def item_seen(frame):
#print(frame)
global sess
imageio.imwrite('picture_out.jpg', frame)
image = run_inference_on_image('picture_out.jpg', sess)
print("This is the Image yaaaaaaaaaaaaaa {}".format(image))
return image
# main loop
python类imwrite()的实例源码
def item_seen(frame):
#print(frame)
global sess
imageio.imwrite('picture_out.jpg', frame)
image = run_inference_on_image('picture_out.jpg', sess)
print("This is the Image yaaaaaaaaaaaaaa {}".format(image))
return image
# main loop
def item_seen(frame):
global sess, max_images, current_images, label
# DIRTY!!
imageio.imwrite('picture_out.jpg', frame)
image = run_inference_on_image('picture_out.jpg', sess)
if image != "without" and image == label:
current_images += 1
else:
current_images = 0
label = image
if current_images > max_images:
print("This is the label yaaaaaaaaaaaaaa {}".format(image))
current_images = max_images
return image
else:
print("No Still Nothing useful although I am seeing {}".format(image))
return "without"
# maybe resize?
#(w, h, c) = frame.shape
#scipy.misc.imresize(np.asarray(frame), min(200.0 / w, 200.0 / h))
#return run_inference_on_image(np.asarray(frame))
# method to write the gif
def write_thumb(inferer, state, data_dir, store_name):
store_path = os.path.join(data_dir, store_name)
thumb = inferer.prepare_thumb(state)
imageio.imwrite(store_path, thumb)
def execute(self, input_data, input_directory, output_directory):
if not input_data['isvideo']:
return {}
img = input_data['img'].copy()
for comp in self.cfg['inputs']:
comp_outputs = input_data.get(comp)
comp_reports = comp_outputs['reports']
if not comp_reports:
print("Warning: pipeline file specifies {} as input for {} but {} is not outputting any location reports".format(
comp, self.name, comp
))
continue
annotate(img, comp_reports)
# The output directory structure should match input directory structure.
relpath_of_input_file = os.path.relpath(input_data['file'], input_directory)
relparent_of_input_file = os.path.dirname(relpath_of_input_file)
inp_filename,inp_extension = os.path.splitext(os.path.basename(relpath_of_input_file))
output_filedir = os.path.join(output_directory, relparent_of_input_file)
if not os.path.exists(output_filedir):
os.makedirs(output_filedir)
output_filepath = os.path.join(output_filedir,
inp_filename + '-frame-' + str(input_data['frame']) + '-annotated.' + self.cfg['params']['format'])
final_img = cv2.resize(img, (self.cfg['params']['size']['width'], self.cfg['params']['size']['height']))
print(output_filepath)
imageio.imwrite(output_filepath, final_img)
return {'file':output_filepath}
def execute(self, input_data, input_directory, output_directory):
if not input_data['isphoto']:
return {}
img = input_data['img'].copy()
for comp in self.cfg['inputs']:
comp_outputs = input_data.get(comp)
comp_reports = comp_outputs['reports']
if not comp_reports:
print("Warning: pipeline file specifies {} as input for {} but {} is not outputting any location reports".format(
comp, self.name, comp
))
continue
annotate(img, comp_reports)
# The output directory structure should match input directory structure.
relpath_of_input_file = os.path.relpath(input_data['file'], input_directory)
relparent_of_input_file = os.path.dirname(relpath_of_input_file)
inp_filename,inp_extension = os.path.splitext(os.path.basename(relpath_of_input_file))
output_filedir = os.path.join(output_directory, relparent_of_input_file)
if not os.path.exists(output_filedir):
os.makedirs(output_filedir)
output_filepath = os.path.join(output_filedir,
inp_filename + '-annotated.' + self.cfg['params']['format'])
if self.cfg['params'].get('size'):
final_img = cv2.resize(img, (self.cfg['params']['size']['width'], self.cfg['params']['size']['height']))
else:
final_img = img
print(output_filepath)
imageio.imwrite(output_filepath, final_img)
return {'file':output_filepath}
def write(self, imagearr, file_name=None):
if file_name != None:
self.file_name = file_name
elif self.file_name != None:
pass
else:
raise Exception(" %s , Undefined file name: " %
sys._getframe().f_code.co_name)
imagearr.un_normalize()
imageio.imwrite(self.file_name, imagearr.get_uint_array(
tdepth=self.out_color_depth), None)