def __init__(self, width=640, height=480, frame_rate=30, jpeg_quality=70, jpeg_lib='cv2'): """Constructor. Args: jpeg_quality (:obj:`int`): Quality of JPEG encoding, in 0, 100. """ # global CAMERA_CV2, CAMERA_PICAMERA Thread.__init__(self) self.width = width self.height = height self.fps = frame_rate self.camera = picamera.PiCamera(framerate=self.fps, sensor_mode=4) self.camera.resolution = (self.width, self.height) self.camera.framerate = self.fps time.sleep(2) #self.camera.start_preview() self.numpy_array = np.empty((self.width * self.height * 3, ), dtype=np.uint8) self.frame_index = 0 self.running = True self.jpeg_image = None self.lock = Lock() self.jpeg_quality = jpeg_quality self.jpeg_encode_func = lambda img, jpeg_quality=self.jpeg_quality: utils.cv2_encode_image( img, jpeg_quality)
def __init__(self, jpeg_quality, jpeg_lib, video_name): """Constructor. Args: jpeg_quality (:obj:`int`): Quality of JPEG encoding, in 0, 100. """ Thread.__init__(self) self.cap = cv2.VideoCapture(video_name) self.running = True self.buffer = None self.lock = Lock() self.jpeg_encode_func = lambda img, jpeg_quality=jpeg_quality: utils.cv2_encode_image( img, jpeg_quality)
def __init__(self, jpeg_quality, jpeg_lib): """Constructor. Args: jpeg_quality (:obj:`int`): Quality of JPEG encoding, in 0, 100. """ Thread.__init__(self) self.cap = cv2.VideoCapture(3) self.turbojpeg = TurboJPEG() self.running = True self.buffer = None self.lock = Lock() if jpeg_lib == 'turbo': self.jpeg = TurboJPEG() self.jpeg_encode_func = lambda img, jpeg_quality=jpeg_quality, jpeg=self.jpeg: utils.turbo_encode_image(img, jpeg, jpeg_quality) else: self.jpeg_encode_func = lambda img, jpeg_quality=jpeg_quality: utils.cv2_encode_image(img, jpeg_quality)
dataview[(num_packets - 1) * data_chunk_size:])) return packets if __name__ == '__main__': import random import utils import cv2 img = cv2.imread('monarch.png') # Build up a collection of messages packets = [] img0_jpeg = utils.cv2_encode_image(img, 10) img1_jpeg = utils.cv2_encode_image(img, 100) packets += UdpPacketsHandler.split_data(msg_idx=0, data=img0_jpeg, max_packet_size=2048) packets += UdpPacketsHandler.split_data(msg_idx=1, data=img1_jpeg, max_packet_size=60000) # Shuffle the packets to see if we can handle disordered packets random.shuffle(packets) print("A total of {} packets are considered sequentially".format( len(packets))) #
default=3390, help='The port on which to listen for incoming connections') parser.add_argument('--jpeg_quality', type=int, default=70, help='The JPEG quality for compressing the reply') args = parser.parse_args() ########################################################### # System Initial configurations ########################################################### host = '' # any interface port = args.port jpeg_quality = args.jpeg_quality jpeg_encode_func = lambda img, jpeg_quality=jpeg_quality: utils.cv2_encode_image( img, jpeg_quality) jpeg_decode_func = lambda buf: utils.cv2_decode_image_buffer(buf) #--------------------------------------------------------- # Start a thread to grab theia images #--------------------------------------------------------- grabber = piGrabber(jpeg_quality=jpeg_quality) grabber.set_manual_ae(100, 8333) grabber.start() # A lambda function to get a cv2 image # get_buffer = lambda: grabber.get_buffer() get_jpeg_image = lambda: grabber.get_jpeg_image() drop_cmd_data = lambda: parse_cmddata() #----------------------------------------------------------