#https://www.arunponnusamy.com/yolo-object-detection-opencv-python.html

from picamera.array import PiRGBArray
from picamera import PiCamera
import time
import cv2

# initialize the camera and grab a reference to the raw camera capture
camera = PiCamera()
camera.resolution = (640, 480)
camera.framerate = 20
rawCapture = PiRGBArray(camera, size=(640, 480))

# allow the camera to warm up
time.sleep(0.2)

x = input()
# grab an image from the camera
camera.capture(rawCapture, format="bgr")
image = rawCapture.array
	
# display the image on screen and wait for a keypress
cv2.imshow("Image", image)
cv2.waitKey(0)

rawCapture.truncate(0)

for frame in camera.capture_continuous(rawCapture, format="bgr", use_video_port=True):
	# grab the numpy array representing the image,
	# then initialize the timestamp and
	# occupied/unoccupied text
	image = rawCapture.array
	
	# show the frame
	cv2.imshow("Frame", image)
	
	# if the 'q' key was pressed, break from the loop
	key = cv2.waitKey(1) & 0xFF
	if key == ord("q"):
		break

	# clear the stream in preparation for the next frame
	rawCapture.truncate(0)
