Ejemplo n.º 1
0
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()
Ejemplo n.º 2
0
        # show the frame and record if a key is pressed
        # cv2.imshow("Frame", frame)

        fps.update()
        key = cv2.waitKey(1) & 0xFF

        if not status == "No Targets":
            print("{} x:{} y:{} ft:{:.2f} {} ".format(status, (cX - f_w),
                                                      (cY - f_h),
                                                      (inches * 3) / 12,
                                                      cpuTemp))
        else:
            print("{} x:  y: ft:{:.2f} {} ".format(status, -00, cpuTemp))

        # if the 'q' key is pressed, stop the loop
        if (key == ord("q") or key == ord("Q") or key == chr(27)):
            break

# cleanup the camera and close any open windows
fps.stop()
camera.stop()
cv2.destroyAllWindows()

print("============================================")
print("\tElasped time: {:.2f}".format(fps.elapsed()))
print("\tApprox. FPS: {:.2f}".format(fps.fps()))
print("Camera Active: ", camera.grabbed)
camera.update()
sleep(4)