def set_params(self, params): MotionTrackedBodypart.set_params(self, params) self.imgRoiBackground = None self.iCount = 0 self.state.intensity = 0.0 self.state.angles = [] self.state.gradients = [] # Compute the 'handedness' of the head/abdomen and wing/wing axes. self.sense specifies the direction of positive angles. matAxes = np.array( [ [ self.params["gui"]["head"]["hinge"]["x"] - self.params["gui"]["abdomen"]["hinge"]["x"], self.params["gui"]["head"]["hinge"]["y"] - self.params["gui"]["abdomen"]["hinge"]["y"], ], [ self.params["gui"]["right"]["hinge"]["x"] - self.params["gui"]["left"]["hinge"]["x"], self.params["gui"]["right"]["hinge"]["y"] - self.params["gui"]["left"]["hinge"]["y"], ], ] ) if self.name in ["left", "right"]: self.senseAxes = np.sign(np.linalg.det(matAxes)) a = -1 if (self.name == "right") else 1 self.sense = a * self.senseAxes else: self.sense = 1 self.windowEdges.set_enable(self.params["gui"]["windows"] and self.params["gui"][self.name]["track"]) self.bValidDetector = False
def set_params(self, params): MotionTrackedBodypart.set_params(self, params) self.imgRoiBackground = None self.iCount = 0 self.state.intensity = 0.0 self.state.angles = [] self.state.gradients = [] # Compute the 'handedness' of the head/abdomen and wing/wing axes. self.sense specifies the direction of positive angles. matAxes = np.array([[ self.params['gui']['head']['hinge']['x'] - self.params['gui']['abdomen']['hinge']['x'], self.params['gui']['head']['hinge']['y'] - self.params['gui']['abdomen']['hinge']['y'] ], [ self.params['gui']['right']['hinge']['x'] - self.params['gui']['left']['hinge']['x'], self.params['gui']['right']['hinge']['y'] - self.params['gui']['left']['hinge']['y'] ]]) if (self.name in ['left', 'right']): self.senseAxes = np.sign(np.linalg.det(matAxes)) a = -1 if (self.name == 'right') else 1 self.sense = a * self.senseAxes else: self.sense = 1 self.windowEdges.set_enable(self.params['gui']['windows'] and self.params['gui'][self.name]['track']) self.bValidDetector = False
def __init__(self, name=None, params={}, color='white', bEqualizeHist=False): MotionTrackedBodypart.__init__(self, name, params, color, bEqualizeHist) self.name = name self.detector = EdgeDetectorByHoughTransform(self.name, params) self.state = MsgState() self.windowEdges = ImageWindow(False, self.name+'Edges') self.set_params(params) # Services, for live intensities plots via live_wing_histograms.py self.service_trackerdata = rospy.Service('trackerdata_'+self.name, SrvTrackerdata, self.serve_trackerdata_callback)
def __init__(self, name=None, params={}, color='white', bEqualizeHist=False): MotionTrackedBodypart.__init__(self, name, params, color, bEqualizeHist) self.name = name self.detector = EdgeDetectorByHoughTransform(self.name, params) self.state = MsgState() self.windowEdges = ImageWindow(False, self.name + 'Edges') self.set_params(params)
def update(self, dt, image, bInvertColor): MotionTrackedBodypart.update(self, dt, image, bInvertColor) if (self.params['gui'][self.name]['track']): if (not self.bValidDetector): if (self.mask.xMin is not None): self.detector.set_params(self.name, self.params, self.sense, self.angleBodypart_i, self.angleBodypart_b, image.shape, self.mask) self.bValidDetector = True self.update_state()
def draw(self, image): MotionTrackedBodypart.draw(self, image) if self.params["gui"][self.name]["track"]: # Draw the major and minor edges alternately, until the max number has been reached. bgra = self.bgra for i in range(len(self.state.angles)): angle_b = self.transform_angle_b_from_p(self.state.angles[i]) angle_i = self.transform_angle_i_from_b(angle_b) x0 = self.ptHinge_i[0] + self.params["gui"][self.name]["radius_inner"] * np.cos(angle_i) y0 = self.ptHinge_i[1] + self.params["gui"][self.name]["radius_inner"] * np.sin(angle_i) x1 = self.ptHinge_i[0] + self.params["gui"][self.name]["radius_outer"] * np.cos(angle_i) y1 = self.ptHinge_i[1] + self.params["gui"][self.name]["radius_outer"] * np.sin(angle_i) cv2.line(image, (int(x0), int(y0)), (int(x1), int(y1)), bgra, 1) bgra = tuple(0.5 * np.array(bgra)) self.windowEdges.show()
def draw(self, image): MotionTrackedBodypart.draw(self, image) if (self.params['gui'][self.name]['track']): # Draw the major and minor edges alternately, until the max number has been reached. bgra = self.bgra for i in range(len(self.state.angles)): angle_b = self.transform_angle_b_from_p(self.state.angles[i]) angle_i = self.transform_angle_i_from_b(angle_b) x0 = self.ptHinge_i[0] + self.params['gui'][self.name]['radius_inner'] * np.cos(angle_i) y0 = self.ptHinge_i[1] + self.params['gui'][self.name]['radius_inner'] * np.sin(angle_i) x1 = self.ptHinge_i[0] + self.params['gui'][self.name]['radius_outer'] * np.cos(angle_i) y1 = self.ptHinge_i[1] + self.params['gui'][self.name]['radius_outer'] * np.sin(angle_i) cv2.line(image, (int(x0),int(y0)), (int(x1),int(y1)), bgra, 1) bgra = tuple(0.5*np.array(bgra)) self.windowEdges.show()
def update(self, dt, image, bInvertColor): MotionTrackedBodypart.update(self, dt, image, bInvertColor) if self.params["gui"][self.name]["track"]: if not self.bValidDetector: if self.mask.xMin is not None: self.detector.set_params( self.name, self.params, self.sense, self.angleBodypart_i, self.angleBodypart_b, image.shape, self.mask, ) self.bValidDetector = True self.update_state()
def set_params(self, params): MotionTrackedBodypart.set_params(self, params) self.imgRoiBackground = None self.iCount = 0 self.state.intensity = 0.0 self.state.angles = [] self.state.gradients = [] # Compute the 'handedness' of the head/abdomen and wing/wing axes. self.sense specifies the direction of positive angles. matAxes = np.array([[self.params['gui']['head']['hinge']['x']-self.params['gui']['abdomen']['hinge']['x'], self.params['gui']['head']['hinge']['y']-self.params['gui']['abdomen']['hinge']['y']], [self.params['gui']['right']['hinge']['x']-self.params['gui']['left']['hinge']['x'], self.params['gui']['right']['hinge']['y']-self.params['gui']['left']['hinge']['y']]]) if (self.name in ['left','right']): self.senseAxes = np.sign(np.linalg.det(matAxes)) a = -1 if (self.name=='right') else 1 self.sense = a*self.senseAxes else: self.sense = 1 self.windowEdges.set_enable(self.params['gui']['windows'] and self.params['gui'][self.name]['track']) self.bValidDetector = False