# import the necessary packages
from webcamvideostream import WebcamVideoStream


class VideoStream:
	def __init__(self, src=0, usePiCamera=False, resolution=(320, 240),framerate=32):
		# check to see if the picamera module should be used
		if usePiCamera:
			# only import the picamera packages unless we are
			# explicity told to do so -- this helps remove the
			# requirement of `picamera[array]` from desktops or
			# laptops that still want to use the `imutils` package
			from pivideostream import PiVideoStream
			# initialize the picamera stream and allow the camera
			# sensor to warmup
			self.stream = PiVideoStream(resolution=resolution,framerate=framerate)
		# otherwise, we are using OpenCV so initialize the webcam stream
		else:
			self.stream = WebcamVideoStream(src=src)
	
    def start(self):
    	# start the threaded video stream
    	return self.stream.start()
    
    def update(self):
		# grab the next frame from the stream
		self.stream.update()
    
    def read(self):
		# return the current frame
		return self.stream.read()
    
    def stop(self):
		# stop the thread and release any resources
		self.stream.stop()
# import the necessary packages
from imutils.video import VideoStream
import datetime
import argparse
import imutils
import time
import cv2
# construct the argument parse and parse the arguments
ap = argparse.ArgumentParser()
ap.add_argument("-p", "--picamera", type=int, default=-1,
	help="whether or not the Raspberry Pi camera should be used")
args = vars(ap.parse_args())
# initialize the video stream and allow the cammera sensor to warmup
vs = VideoStream(usePiCamera=args["picamera"] > 0).start()
time.sleep(2.0)
