labelGetter = comm.FileGetter(args.label,"bmp",comm.SingleChannelImageMessage) ropeInitPub = comm.FilePublisher(args.out,"txt") prev_id = -1 while True: latest_id = getLastInd(args.label) print "latest id", latest_id if latest_id == prev_id: sleep(.1) continue else: prev_id = latest_id timePrevStart = time() xyz,bgr = pcdGetter.recv_id(latest_id).data label = labelGetter.recv_id(latest_id).data if label is None: raise Exception("could not read label file") try: xyzs,labels = initialize_rope(label,xyz, bgr,plotting=args.plotting) ropeInitPub.send(RopeInitMessage(data=(xyzs, labels))) sleep(max(args.pause - (time() - timePrevStart),0)) except Exception: print colorize("exception occurred in rope init:","red") traceback.print_exc()
#!/usr/bin/env python import argparse, cv2, os parser = argparse.ArgumentParser() parser.add_argument("pcd_file") parser.add_argument("label_file") parser.add_argument("outfile") parser.add_argument("--plotting",action="store_true") args = parser.parse_args() from jds_image_proc import pcd_io from jds_image_proc.rope_initialization import initialize_rope,RopeInitMessage xyz,bgr = pcd_io.load_xyzrgb(args.pcd_file) # get rope mask label_img = cv2.imread(args.label_file,0) if label_img is None: raise Exception("could not read image %s"%args.label_file) xyzs_unif,labels = initialize_rope(label_img,xyz, bgr,plotting=args.plotting) if not os.path.exists(os.path.dirname(args.outfile)): os.mkdir(dirname(args.outfile)) print "writing",args.outfile RopeInitMessage((xyzs_unif,labels)).toFiles(args.outfile,"/tmp/junk.json")
#!/usr/bin/env python import argparse, cv2, os parser = argparse.ArgumentParser() parser.add_argument("pcd_file") parser.add_argument("label_file") parser.add_argument("outfile") parser.add_argument("--plotting", action="store_true") args = parser.parse_args() from jds_image_proc import pcd_io from jds_image_proc.rope_initialization import initialize_rope, RopeInitMessage xyz, bgr = pcd_io.load_xyzrgb(args.pcd_file) # get rope mask label_img = cv2.imread(args.label_file, 0) if label_img is None: raise Exception("could not read image %s" % args.label_file) xyzs_unif, labels = initialize_rope(label_img, xyz, bgr, plotting=args.plotting) if not os.path.exists(os.path.dirname(args.outfile)): os.mkdir(dirname(args.outfile)) print "writing", args.outfile RopeInitMessage((xyzs_unif, labels)).toFiles(args.outfile, "/tmp/junk.json")
pcdGetter = comm.FileGetter(args.pcd, "pcd", comm.PointCloudMessage) labelGetter = comm.FileGetter(args.label, "bmp", comm.SingleChannelImageMessage) ropeInitPub = comm.FilePublisher(args.out, "txt") prev_id = -1 while True: latest_id = getLastInd(args.label) print "latest id", latest_id if latest_id == prev_id: sleep(.1) continue else: prev_id = latest_id timePrevStart = time() xyz, bgr = pcdGetter.recv_id(latest_id).data label = labelGetter.recv_id(latest_id).data if label is None: raise Exception("could not read label file") try: xyzs, labels = initialize_rope(label, xyz, bgr, plotting=args.plotting) ropeInitPub.send(RopeInitMessage(data=(xyzs, labels))) sleep(max(args.pause - (time() - timePrevStart), 0)) except Exception: print colorize("exception occurred in rope init:", "red") traceback.print_exc()