from comm import comm, mapper import subprocess, os, shutil import jds_utils.dir_tools comm.setDataRoot("/home/joschu/Data/test_comm") dir_tools.ensure_exists(comm.getDataRoot()) def delTopic(topic): path = comm.topicPath(topic) if os.path.exists(path): shutil.rmtree(path) # topicA = "topicA" topicB = "topicB" delTopic(topicA) delTopic(topicB) pubA = comm.FilePublisher(topicA, "txt") pubB = comm.FilePublisher(topicB, "txt") msgsA = [comm.FloatMessage(t) for t in [0, 1, 2, 3]] msgsB = [comm.FloatMessage(t) for t in [-1, 0, 0.1, 0.9]] for msg in msgsA: pubA.send(msg) for msg in msgsB: pubB.send(msg) class TestParMap(mapper.ParallelMapper):
__builtins__.__openravepy_version__ = '0.4' import openravepy as rave import numpy as np from os.path import join import time from comm import comm env = rave.Environment() env.SetViewer('qtcoin') env.Load('robots/pr2-beta-sim.robot.xml') pr2 = env.GetRobots()[0] comm.setDataRoot("/home/joschu/Data/comm3") jointSub = comm.FileSubscriber("joints","txt",comm.ArrayMessage) rosnames = np.load("/home/joschu/Data/knot_kinect2/joint_names.npy") ros2rave = np.array([pr2.GetJointIndex(name) for name in rosnames]) while True: try: msg = jointSub.recv() except StopIteration: break rosvalues = msg.data goodrosinds = np.flatnonzero(ros2rave != -1) raveinds = ros2rave[goodrosinds]
self.window_name = "labeling" cv2.namedWindow(self.window_name,cv2.cv.CV_WINDOW_NORMAL) with open(self.args.classifier,"r") as fh: self.classifier = cPickle.load(fh) self.mask = cv2.imread(self.args.mask,0) def add_extra_arguments(self, parser): parser.add_argument('classifier',type=str) parser.add_argument('--mask',default=join(comm.DATA_ROOT,"once/roi_mask.png")) return parser def func(self, (xyz,bgr)): bgr = bgr.copy() label = self.classifier.predict(bgr,self.mask) x,y,z = xyz[:,:,0], xyz[:,:,1], xyz[:,:,2] depth = np.sqrt(x**2+y**2+z**2) depth[np.isnan(depth)] = np.inf good = np.zeros(depth.shape,bool) good[1:] |= np.abs(depth[1:] - depth[:-1]) < .02 good[:,1:] |= np.abs(depth[:,1:] - depth[:,:-1]) < .02 good = ndi.binary_erosion(good, np.ones((3,3))) label *= good cv2.imshow(self.window_name,annotation.colorizeLabels(bgr,label)) cv2.waitKey(10) return label comm.setDataRoot() M = LabelImages() M.run()
cv2.namedWindow(self.window_name, cv2.cv.CV_WINDOW_NORMAL) with open(self.args.classifier, "r") as fh: self.classifier = cPickle.load(fh) self.mask = cv2.imread(self.args.mask, 0) def add_extra_arguments(self, parser): parser.add_argument('classifier', type=str) parser.add_argument('--mask', default=join(comm.DATA_ROOT, "once/roi_mask.png")) return parser def func(self, (xyz, bgr)): bgr = bgr.copy() label = self.classifier.predict(bgr, self.mask) x, y, z = xyz[:, :, 0], xyz[:, :, 1], xyz[:, :, 2] depth = np.sqrt(x**2 + y**2 + z**2) depth[np.isnan(depth)] = np.inf good = np.zeros(depth.shape, bool) good[1:] |= np.abs(depth[1:] - depth[:-1]) < .02 good[:, 1:] |= np.abs(depth[:, 1:] - depth[:, :-1]) < .02 good = ndi.binary_erosion(good, np.ones((3, 3))) label *= good cv2.imshow(self.window_name, annotation.colorizeLabels(bgr, label)) cv2.waitKey(10) return label comm.setDataRoot() M = LabelImages() M.run()
from comm import comm, mapper import subprocess, os, shutil import jds_utils.dir_tools comm.setDataRoot("/home/joschu/Data/test_comm") dir_tools.ensure_exists(comm.getDataRoot()) def delTopic(topic): path = comm.topicPath(topic) if os.path.exists(path): shutil.rmtree(path) # topicA = "topicA" topicB = "topicB" delTopic(topicA) delTopic(topicB) pubA = comm.FilePublisher(topicA, "txt") pubB = comm.FilePublisher(topicB, "txt") msgsA = [comm.FloatMessage(t) for t in [0, 1, 2, 3]] msgsB = [comm.FloatMessage(t) for t in [-1, 0, .1, .9]] for msg in msgsA: pubA.send(msg) for msg in msgsB: pubB.send(msg) class TestParMap(mapper.ParallelMapper):