default='./images') #ecto options scheduler_options(parser.add_argument_group('Scheduler Options')) args = parser.parse_args() if not os.path.exists(args.output): os.makedirs(args.output) source = create_source( package_name='image_pipeline', source_type='OpenNISource') #optionally pass keyword args here... depth_saver = ecto.If( 'depth saver', cell=ImageSaver( filename_format=os.path.join(args.output, 'depth%04d.png'))) image_saver = ecto.If( 'rgb saver', cell=ImageSaver( filename_format=os.path.join(args.output, 'image%04d.png'))) display = imshow(name='RGB', triggers=dict(save=ord('s'))) plasm = ecto.Plasm() plasm.connect( source['image'] >> (display['image'], image_saver['image']), source['depth'] >> (imshow(name='Depth')['image'], depth_saver['image']), display['save'] >> (image_saver['__test__'], depth_saver['__test__'])) run_plasm(args, plasm, locals=vars())
parser.add_argument('--width', dest='width', default=640) parser.add_argument('--height', dest='height', default=480) parser.add_argument('--preview', action='store_true') #ecto options scheduler_options(parser.add_argument_group('Scheduler Options')) args = parser.parse_args() if not os.path.exists(args.output): os.makedirs(args.output) #camera = VideoCapture(video_device=1,width=int(args.width),height=int(args.height)) source = create_source( package_name='image_pipeline', source_type='OpenNISource') #optionally pass keyword args here... depth_saver = ImageSaver( filename_format=os.path.join(args.output, 'frame_%010d_depth.png')) image_saver = ImageSaver( filename_format=os.path.join(args.output, 'frame_%010d_image.png')) #mono_saver = ImageSaver(filename_format=os.path.join(args.output, 'frame_%010d_mono.png')) plasm = ecto.Plasm() plasm.connect( # camera['image'] >> imshow(name='Mono')['image'], source['depth'] >> imshow(name='Depth')['image'], source['image'] >> imshow(name='RGB')['image']) if not args.preview: plasm.connect( source['image'] >> image_saver['image'], source['depth'] >> depth_saver['image'], # camera['image'] >> mono_saver['image'],
continue plasm = ecto.Plasm() #the db_reader transforms observation id into a set of image,depth,mask,K,R,T db_reader = capture.ObservationReader("db_reader", db_params=dbtools.args_to_db_params(args)) #this iterates over all of the observation ids. observation_dealer = ecto.Dealer(tendril=db_reader.inputs.at('observation'), iterable=obs_ids) plasm.connect(observation_dealer[:] >> db_reader['observation']) path_names = [ 'image', 'depth', 'mask'] for path_name in path_names: path = os.path.join(object_id, path_name) if not os.path.exists(path): os.makedirs(path) writer_image = ImageSaver(filename_format=os.path.join(path, '%05d.png'))[:] plasm.connect(db_reader[path_name] >> (writer_image, imshow(name=path_name)['image'])) sched = ecto.schedulers.Singlethreaded(plasm) sched.execute() # write files listing the produced files for path_name in path_names: file_object = open(os.path.join(os.getcwd(), object_id, path_name + '.txt'), 'w') for file_name in [ os.path.join(os.getcwd(), object_id, path_name, file_name) for file_name in os.listdir(os.path.join(object_id, path_name)) if file_name.endswith('png') ]: file_object.write(file_name + '\n') file_object.close #After done execution upload the resulting model to the db....
def match(options, scale=1.0, train_scale=1 / 3.0, scale_factor=1.05, n_levels=5, n_features_train=10000, n_features_test=1000, match_distance=120, ): if not os.path.exists(options.output): os.makedirs(options.output) train = imread('Train image', image_file=options.train, mode=ImageMode.GRAYSCALE) test = imread('Test image', image_file=options.test, mode=ImageMode.GRAYSCALE) train_name, _extension = os.path.splitext(os.path.basename(options.train)) test_name, _extension = os.path.splitext(os.path.basename(options.test)) print 'Scale %d is %f' % (0, scale) for i in range(n_levels - 1): scale *= 1.0 / scale_factor print 'Scale %d is %f' % (i + 1, scale) orb_train = ORB(n_features=n_features_train, n_levels=n_levels, scale_factor=scale_factor) orb_test = ORB(n_features=n_features_test, n_levels=1) plasm = ecto.Plasm() scale = Scale(factor=train_scale, interpolation=AREA) plasm.connect(train['image'] >> scale['image']) train_pts = hookup_orb(plasm, scale, orb_train) test_pts = hookup_orb(plasm, test, orb_test) matcher = Matcher() plasm.connect(orb_train['descriptors'] >> matcher['train'], orb_test['descriptors'] >> matcher['test'], ) matchesMat = MatchesToMat() h_est = MatchRefinement(match_distance=match_distance) plasm.connect(train_pts['points'] >> h_est['train'], test_pts['points'] >> h_est['test'], matcher['matches'] >> h_est['matches'], h_est['matches'] >> matchesMat['matches'] ) match_draw = DrawMatches() output_base = os.path.join(options.output, '%(train)s_%(test)s' % dict(train=train_name, test=test_name)) match_image = output_base + '.png' image_saver = ImageSaver(filename=match_image) plasm.connect(train_pts['points'] >> match_draw['train'], test_pts['points'] >> match_draw['test'], h_est['matches'] >> match_draw['matches'], h_est['matches_mask'] >> match_draw['matches_mask'], scale['image'] >> match_draw['train_image'], test['image'] >> match_draw['test_image'], match_draw[:] >> image_saver[:] ) match_eval = MatchEval(output=options.output) plasm.connect(matchesMat['matches'] >> match_eval['matches'], train_pts['points'] >> match_eval['train'], test_pts['points'] >> match_eval['test'], h_est['matches_mask'] >> match_eval['inliers'], ) run_plasm(options, plasm, locals=vars())
#!/usr/bin/env python import ecto from ecto_opencv.highgui import VideoCapture, imshow, FPSDrawer, ImageSaver video_cap = VideoCapture(video_device=0) fps = FPSDrawer() video_display = imshow(name='video_cap', triggers=dict(save=ord('s'))) saver = ecto.If( cell=ImageSaver('saver', filename_format='ecto_image_%05d.jpg', start=1)) plasm = ecto.Plasm() plasm.connect( video_cap['image'] >> fps['image'], fps['image'] >> video_display['image'], video_display['save'] >> saver['__test__'], fps['image'] >> saver['image'], ) if __name__ == '__main__': from ecto.opts import doit doit(plasm, description='Save images from video stream.')
import ecto from ecto_opencv.highgui import VideoCapture, FPSDrawer, imshow, ImageSaver from ecto_opencv.imgproc import BilateralFilter video_cap = VideoCapture(video_device=0) fps = FPSDrawer() video_display = imshow( 'imshow', name='video_cap', triggers=dict(save=ord('s')), ) saver = ecto.If( cell=ImageSaver('saver', filename_format='bilateral_%05d.jpg', start=1)) bl_begin = None bl_end = None plasm = ecto.Plasm() #Build up a chain of bilateral filters. for i in range(1, 10): next = BilateralFilter(d=-1, sigmaColor=10, sigmaSpace=5) if bl_begin == None: # beginning case bl_begin = next bl_end = next continue plasm.connect(bl_end[:] >> next[:]) bl_end = next
for x in files: if '.png' in x: num = x.split('_')[1].split('.')[0] if num.isdigit(): return int(num) + 1 return 0 rgb_start = init_image_dir('rgb') ir_start = init_image_dir('ir') print 'rgb start', rgb_start, 'ir_start', ir_start if (rgb_start != ir_start): print 'please ensure that the images in ir, and rgb are aligned lexographically' sys.exit(1) #saving images rgb_saver = ecto.If( cell=ImageSaver(filename_format='rgb/rgb_%04d.png', start=rgb_start)) ir_saver = ecto.If( cell=ImageSaver(filename_format='ir/ir_%04d.png', start=ir_start)) plasm.connect(rgb2gray[:] >> rgb_saver['image'], conversion[:] >> ir_saver['image'], ander[:] >> (rgb_saver['__test__'], ir_saver['__test__'])) sched = ecto.schedulers.Singlethreaded(plasm) while sched.execute(niter=5) == 0: #swap it modes next_mode, capture.params.stream_mode = capture.params.stream_mode, next_mode print sched.stats()