class Sub: def __init__(self,name,parent): self.name = name self.pub = rospy.Publisher('/%s/compressed'%name, CompressedImage) self.blank_pub = rospy.Publisher('/%s_blank/compressed'%name, CompressedImage) self.info = Info() self.sub = None self.detect = getattr(VUtil, name) self.parent = parent self.kern = (3,3) self.thresh = 100 self.canPublish = False self.box = getCheckBox(name) self.box.stateChanged.connect(self.box_cb) def cam_cb(self,rosimg): cvimg = VUtil.rosimg2cv(rosimg) y,x = cvimg.shape[:2] cvimg = cv2.resize(cvimg, (x/2,y/2)) if self.canPublish: blank = np.zeros_like(cvimg) out = self.detect(cvimg,self.info.data,blank) self.info.draw(blank) self.pub.publish(VUtil.writeCompressed(out)) self.blank_pub.publish(VUtil.writeCompressed(blank)) def box_cb(self, state): if state == QtCore.Qt.Checked: topic = str(self.parent.currTopic) self.sub = rospy.Subscriber(topic,Image,self.cam_cb) self.canPublish = True self.parent.analyseTopic = '/%s/compressed'%self.name self.ps = subprocess.Popen(['rosrun','image_view','image_view','image:='+'/%s_blank'%self.name,'compressed']) else: self.canPublish = False self.sub.unregister() self.ps.terminate()