def start(self): """ Starts sending the stream to the Viewer. Creates a camera, takes a image frame converts the frame to string and sends the string across the network :return: None """ print("Streaming Started...") camera = Camera() camera.start_capture() self.keep_running = True while self.footage_socket and self.keep_running: try: time.sleep( 0.05 ) # Sleep to decrease processing time per frame, VERY EFFECTIVE frame = camera.current_frame.read() # grab the current frame scale_percent = 100 # percent of original size, SET BY YOUR DESIRE width = int(frame.shape[1] * scale_percent / 100) height = int(frame.shape[0] * scale_percent / 100) dim = (width, height) frameSmall = cv2.resize(frame, dim, interpolation=cv2.INTER_AREA) frameSmall = cv2.cvtColor( frameSmall, cv2.COLOR_BGR2GRAY ) #Convert the image to grey scale, decreasing processing time and network trafic, YOU CAN DELETE THIS LINE TO GET A COLOR IMAGE image_as_string = image_to_string(frameSmall) self.footage_socket.send(image_as_string) except KeyboardInterrupt: cv2.destroyAllWindows() break print("Streaming Stopped!") cv2.destroyAllWindows()
def start(self, framerate): """ Starts sending the stream to the Viewer. Creates a camera, takes a image frame converts the frame to string and sends the string across the network :return: None """ self.framerates = [framerate / 3., framerate] print("Streaming Started...") camera = Camera() camera.start_capture() self.keep_running = True id = 0 separator = "______".encode() time.sleep(2) start = time.time() while self.footage_socket and self.footage_socket_tiny and self.keep_running: try: try: normal_framerate = int( self.footage_socket_tiny.recv(flags=zmq.NOBLOCK)) framerate = self.framerates[normal_framerate] except zmq.error.Again: pass time.sleep(0.6 / framerate) frame = camera.current_frame.read() # grab the current frame small_frame = resize_img(frame)[0] # resize image_as_string = image_to_string(frame) # encode the frame small_image_as_string = image_to_string( small_frame) # encode the small frame self.footage_socket_viewer.send(image_as_string + separator + str(id).encode()) self.footage_socket.send( small_image_as_string + separator + str(id).encode() + separator + str(round(time.time(), 2)).encode()) # send it id += 1 print('Frame: %d, framerate: %2.2f fps' % (id, round(id / (time.time() - start), 2))) except KeyboardInterrupt: cv2.destroyAllWindows() break print("Streaming Stopped!") cv2.destroyAllWindows()
def frame_capture(): global buffer camera = Camera() camera.start_capture() while True: frame = camera.current_frame.read() # grab the current frame frame = rescale_frame(frame) buffer.append(image_to_string(frame)) print(len(buffer))
def start(self): """ Starts sending the stream to the Viewer. Creates a camera, takes a image frame converts the frame to string and sends the string across the network :return: None """ print("Streaming Started...") camera = Camera() camera.start_capture() self.keep_running = True while self.footage_socket and self.keep_running: try: frame = camera.current_frame.read() # grab the current frame image_as_string = image_to_string(frame) self.footage_socket.send(image_as_string) except KeyboardInterrupt: cv2.destroyAllWindows() break print("Streaming Stopped!") cv2.destroyAllWindows()