def set_erode_iteration(self, erode_iterations): InfraredModel.set_erode_iterations(erode_iterations=erode_iterations)
def set_dilate_iteration(self, dilate_iterations): InfraredModel.set_dilate_iterations( dilate_iterations=dilate_iterations)
def set_blur_kernalsize(self, blur_kernalsize): InfraredModel.set_blur_kernalsize(blur_kernalsize=blur_kernalsize)
def set_infrared_lower_boundary_value(self, value): InfraredModel.set_infrared_lower_boundary_value(value=value)
def set_infrared_lower_boundary_saturation(self, saturation): InfraredModel.set_infrared_lower_boundary_saturation( saturation=saturation)
def set_infrared_lower_boundary_hue(self, hue): InfraredModel.set_infrared_lower_boundary_hue(hue=hue)
def tracking_loop(self): while self.is_tracking: if self.infrared_camera is not None: # Get a frame from camera ret, frame = self.infrared_camera_get_frame() if ret: # Resize(downsize) the frame for better processing performance # Current natively using 320x240 frame, no downsizing it needed frame = imutils.resize(frame, width=320) # Process the frame ir_result = InfraredModel.find_candidate_targets( frame=frame) result = ir_result["result"] pro_processing_frame = ir_result["pro_processing_frame"] if result: targets = ir_result["targets"] if len(targets) == 1: x, y = targets[0].x, targets[0].y cv2.circle(pro_processing_frame, (x, y), 6, (0, 0, 255), -1) else: # sort the candidates by radius targets.sort(key=Target.get_radius, reverse=True) # if the largest candidates is larger than the second largest candidates by a lot (* 0.??, hence ??% ) # We can assume that the anything other than the largest candidates should be considered. if targets[1].radius < (targets[0].radius * 0.15): x, y = targets[0].x, targets[0].y cv2.circle(pro_processing_frame, (x, y), 6, (0, 0, 255), -1) else: # Both first and second largest candidates are large enough, compare to each other, hence consider both. x, y = Target.find_2_targets_middle( target0=targets[0], target1=targets[1]) cv2.circle(pro_processing_frame, (targets[0].x, targets[0].y), 6, (0, 0, 255), -1) cv2.circle(pro_processing_frame, (targets[1].x, targets[1].y), 6, (0, 0, 255), -1) cv2.circle(pro_processing_frame, (x, y), 4, (0, 255, 0), -1) pix = GuiModel.frame_to_pixmap(pro_processing_frame) self.controller.main_gui_set_label_infrared_camera_preview_frame( pixmap=pix) # Calculate the distance from center to target, in X-axis and Y-axis dx = x - 160 dy = y - 160 # print("Before: dx: " + str(dx) + "\tdy: " + str(dy)) abs_dx = abs(dx) abs_dy = abs(dy) if abs_dx < self.effective_x: dx = 0 if abs_dy < self.effective_y: dy = 0 # print("After : dx: " + str(dx) + "\tdy: " + str(dy)) if not (dx == 0 and dy == 0): # 0 = Negative, 2 = Positive, this value will be minus 1 in Arduino board, 0-> -1; 2-> 1 # target on left to center if dx < 0: direction_x = 0 # target on right to center else: direction_x = 2 # target above center if dy < 0: direction_y = 0 # target below center else: direction_y = 2 # TODO: Set package type # Build the message string # First integer is package type message = "0" + str(direction_x) + str( abs(dx) ).zfill(3) + str(direction_y) + str(abs(dy)).zfill( 3) + ";" # print("Sent Message: " + message) # Send message self.send_serial_message(message=message) print(message) else: pix = GuiModel.frame_to_pixmap(pro_processing_frame) self.controller.main_gui_set_label_infrared_camera_preview_frame( pixmap=pix) else: print("Tracking Ended With ret=False") self.stop_tracking() # self.infrared_camera = None else: print("Tracking Ended With infrared_camera is None") self.stop_tracking() print("Tracking Ended") self.controller.main_gui_clear_label_infrared_camera_preview_frame()