def read_media_from_data_base(self, image_index): new_media = Media() image_str=pexif.JpegFile.fromFile("db/"+str(image_index)+".jpeg") meta = image_str.exif.primary.ExtendedEXIF.UserComment new_media.meta = pickle.loads(''.join(meta)) new_media.data = cv2.imread("db/"+str(image_index)+".jpeg") new_media.exif = image_str.exif return new_media
def block_media(self, media): state = self.state (num1, num2, flag) = state.target_block_numbers if flag == 0: #aim for block pixel count avg1 = math.ceil(len(media.data[:,0]) / num1) avg2 = math.ceil(len(media.data[0,:]) / num2) else: #aim for number of blocks avg1 = math.ceil(len(media.data[:,0]) / float(num1)) avg2 = math.ceil(len(media.data[0,:]) / float(num2)) last1 = 0.0 dim1_index = 0 dim2_index = 0 master_block_meta_list = [] while last1 < len(media.data[:,0]): last2 = 0.0 while last2 < len(media.data[0,:]): if (dim1_index == 0 and dim2_index ==0): #first block in image priority = state.first_block_priority block_meta = {'image_index':media.meta['image_index'],'priority':priority, 'x_pixel_index':int(last2),'x_loc_index':int(dim1_index),'y_pixel_index':int(last1),'y_loc_index':int(dim2_index)} first_block = Media(data = media.data[int(last1):int(last1 + avg1), int(last2):int(last2 + avg2)], meta = dict(media.meta, **block_meta), exif = media.exif) else: priority = state.normal_block_priority block_meta = {'image_index':media.meta['image_index'], 'priority':priority, 'x_pixel_index':int(last1),'x_loc_index':int(dim1_index),'y_pixel_index':int(last2),'y_loc_index':int(dim2_index)} state.raw_block_list.append(Media(data = media.data[int(last1):int(last1 + avg1), int(last2):int(last2 + avg2)], meta = block_meta, exif = media.exif)) master_block_meta_list.append(block_meta) last2 += avg2 dim2_index +=1 last1 += avg1 dim1_index +=1 extended_meta = {'extended_meta':master_block_meta_list} first_block.meta = dict(first_block.meta, **extended_meta) state.raw_block_list.append(first_block)
def process_blocks(self): state = self.state while len(state.raw_block_list)>0: raw_block = state.raw_block_list.pop(0) print raw_block.meta media_data = raw_block.data #print media_data image_index = raw_block.meta['image_index'] x_pixel_index = raw_block.meta['x_pixel_index'] y_pixel_index = raw_block.meta['y_pixel_index'] x_loc_index = raw_block.meta['x_loc_index'] y_loc_index = raw_block.meta['y_loc_index'] (flag, img_buffer) = cv2.imencode('.jpg', media_data, [cv2.IMWRITE_JPEG_QUALITY, 95]) #block_name = (image_index << 16) + (x_pixel_index << 8) + y_pixel_index #block_name = (image_index << 16) + (x_loc_index << 8) + y_loc_index block_name = (image_index << 8) + y_loc_index image_binary = img_buffer.tobytes()#np.getbuffer(img_buffer)[:] #print image_binary meta_binary = self.dict_to_binary(raw_block.meta) image_str=pexif.JpegFile.fromString(image_binary) if raw_block.exif is not None: image_str.import_exif(raw_block.exif) image_str.exif.primary.ExtendedEXIF.UserComment = meta_binary # print image_binary # print meta_binary #combined = image_binary+'META'+meta_binary combined = image_str.writeString() state.processed_block_list.append(Media(data = combined, meta = dict(raw_block.meta, **{'block_name':block_name})))
def capture(self): try: imgPath = 'fake/fake.jpg' imgcv = cv2.imread(imgPath) #open image from file image_str=pexif.JpegFile.fromFile(imgPath) return Media(data=imgcv, exif = image_str.exif) except: print 'capture error' return False
def capture(self): print self.ret if self.ret: image_str = pexif.JpegFile.fromFile( self.imgPath) #use fake exif data # Our operations on the frame come here imgcv = cv2.cvtColor(self.frame, cv2.COLOR_BGR2BGRA) return Media(data=imgcv, exif=image_str.exif) else: return False
def main_loop(): '''main processing loop''' #make a media object med = Media() while med.is_alive(): med.process_control_connection() med.process_media() time.sleep(0.1)
def capture(self): if self.camera.take_picture(): #if taking the pic worked.... bytes = self.camera.boGetLatestImage() if bytes: #if we got .jpg image data stream = io.BytesIO(bytes) img = Image.open(stream) #open the stream with PIL imgcv = cv2.cvtColor(np.asarray(img), cv2.COLOR_RGB2BGR) #make a numpy array from the PIL image and then convert to openCV format with RBG to BGR colour conversion image_str=pexif.JpegFile.fromString(bytes) return Media(data=imgcv, exif = image_str.exif) else: return False
def capture(): bashCommand = "gphoto2 --capture-image-and-download --force-overwrite --stdout" child = subprocess.Popen(bashCommand.split(), shell=False, stdout=subprocess.PIPE, stderr=subprocess.PIPE) stdout, stderr = child.communicate() #we only want the .jpeg binary buffer stream = io.BytesIO(stdout[0]) #make an IO stream for the binary data img = Image.open(stream) #open the stream with PIL imgcv = cv2.cvtColor( np.asarray(img), cv2.COLOR_RGB2BGR ) #make a numpy array from the PIL image and then convert to openCV format with RBG to BGR colour conversion image_str = pexif.JpegFile.fromString(stdout[0]) return Media(data=imgcv, exif=image_str.exif)
def __init__(self, queue): self.capture_mode = 1 # 0 = wait for cmd and action, 1 = auto loop interval self.control_connection_in = mavutil.mavudp("127.0.0.1:14666") self.control_link_in = mavutil.mavlink.MAVLink( self.control_connection_in) self.control_connection_out = mavutil.mavudp("127.0.0.1:14676", input=False) self.control_link_out = mavutil.mavlink.MAVLink( self.control_connection_out) self.control_link_out.srcSystem = 122 self.control_link_out.srcComponent = 100 self.table_ports = [self.control_connection_in.port] self.capture_interval = 2 #seconds. used for auto capture self.alive = True self.current_meta_image_index = None self.target_system = 1 self.target_component = 1 self.camera_type = "vfl" self.media_queue = queue self.image_index = 0 self.capture_time = time.time() self.media_buffer = [] self.media_buffer_max_count = 5 #media objects self.media_buffer_max_age = 5 #seconds self.request_ap_meta = True self.request_mount_meta = False #currently there is no mount... self.capture_retry_max = -1 #-1 = inf, 0 = no retry, 1, 2, 3, etc... self.capture_retry_count = 0 self.prev_img = Media() if self.camera_type == 'canon': self.camera = gphoto_image_capture.Camera() if self.camera_type == 'fake': self.camera = fake_image_capture.Camera() if self.camera_type == 'sony': self.camera = sony_image_capture.Camera() if self.camera_type == 'vfl': self.camera = vfl_image_capture.Camera()