def handle_shot(self, laser_color, x, y): if (self._pause_shot_detection): return timestamp = 0 # Start the shot timer if it has not been started yet, # otherwise get the time offset if self._shot_timer_start is None: self._shot_timer_start = time.time() else: timestamp = time.time() - self._shot_timer_start tree_item = None if "green" in laser_color: tree_item = self._shot_timer_tree.insert("", "end", values=[timestamp, "green"]) else: tree_item = self._shot_timer_tree.insert("", "end", values=[timestamp, laser_color]) self._shot_timer_tree.see(tree_item) new_shot = Shot((x, y), self._webcam_canvas, self._preferences[configurator.MARKER_RADIUS], laser_color, timestamp) self._shots.append(new_shot) new_shot.draw_marker() # Process the shot to see if we hit a region and perform # a training protocol specific action and any if we did # command tag actions if we did self.process_hit(new_shot, tree_item)
def detect_shots(self): if (self._webcam_frame is None): self._window.after(self._preferences[DETECTION_RATE], self.detect_shots) return # Makes feed black and white frame_bw = cv2.cvtColor(self._webcam_frame, cv2.cv.CV_BGR2GRAY) # Threshold the image (thresh, frame_thresh) = cv2.threshold(frame_bw, self._preferences[LASER_INTENSITY], 255, cv2.THRESH_BINARY) # Determine if we have a light source or glare on the feed if not self._seen_interference: self.detect_interfence(frame_thresh) # Find min and max values on the black and white frame min_max = cv2.minMaxLoc(frame_thresh) # The minimum and maximum are the same if there was # nothing detected if (min_max[0] != min_max[1]): x = min_max[3][0] y = min_max[3][1] laser_color = self.detect_laser_color(x, y) # If we couldn't detect a laser color, it's probably not a # shot if (laser_color is not None and preferences[IGNORE_LASER_COLOR] not in laser_color): new_shot = Shot((x, y), self._preferences[MARKER_RADIUS], laser_color) self._shots.append(new_shot) new_shot.draw_marker(self._webcam_canvas) # Process the shot to see if we hit a region and perform # a training protocol specific action and any if we did # command tag actions if we did self.process_hit(new_shot) if self._shutdown == False: self._window.after(self._preferences[DETECTION_RATE], self.detect_shots)
def detect_shots(self): if (self._webcam_frame is None): self._window.after(self._preferences[DETECTION_RATE], self.detect_shots) return # Makes feed black and white frame_bw = cv2.cvtColor(self._webcam_frame, cv2.cv.CV_BGR2GRAY) # Threshold the image (thresh, frame_thresh) = cv2.threshold(frame_bw, self._preferences[LASER_INTENSITY], 255, cv2.THRESH_BINARY) # Determine if we have a light source or glare on the feed if not self._seen_interference: self.detect_interfence(frame_thresh) # Find min and max values on the black and white frame min_max = cv2.minMaxLoc(frame_thresh) # The minimum and maximum are the same if there was # nothing detected if (min_max[0] != min_max[1]): x = min_max[3][0] y = min_max[3][1] new_shot = Shot((x, y), self._preferences[MARKER_RADIUS]) self._shots.append(new_shot) new_shot.draw_marker(self._webcam_canvas) # Process the shot to see if we hit a region and perform # a training protocol specific action and any if we did # command tag actions if we did self.process_hit(new_shot) if self._shutdown == False: self._window.after(self._preferences[DETECTION_RATE], self.detect_shots)
def handle_shot(self, laser_color, x, y): if (self._pause_shot_detection): return if self.update_virtual_magazine(): return if self.malfunction(): return timestamp = 0 hit_projector_region = None projector_region_tags = None # If the projector is calibrated and the shot is in the # projector's bounding box, tell the projector arena if self._projector_calibrated: bbox = self._projector_calibrator.get_projected_bbox() x_scale = float(self._projector_arena.arena_width()) / float(bbox[2] - bbox[0]) y_scale = float(self._projector_arena.arena_height()) / float(bbox[3] - bbox[1]) if (x > bbox[0] and x < bbox[2] and y > bbox[1] and y < bbox[3]): # Translate the coordinates into the arena's coordinate system hit_projector_region, projector_region_tags = self._projector_arena.handle_shot(laser_color, (x - bbox[0])*x_scale, (y - bbox[1])*y_scale) # This makes sure click to shoot can be used for the projector too if self._preferences[configurator.DEBUG]: frame_height = len(self._webcam_frame) frame_width = len(self._webcam_frame[0]) x_scale = float(self._projector_arena.arena_width()) / float(frame_width) y_scale = float(self._projector_arena.arena_height()) / float(frame_height) hit_projector_region, projector_region_tags = self._projector_arena.handle_shot(laser_color, (x)*x_scale, (y)*y_scale) # Start the shot timer if it has not been started yet, # otherwise get the time offset if self._shot_timer_start is None: self._shot_timer_start = time.time() else: timestamp = time.time() - self._shot_timer_start tree_item = None if "green" in laser_color: tree_item = self._shot_timer_tree.insert("", "end", values=[timestamp, "green"]) else: tree_item = self._shot_timer_tree.insert("", "end", values=[timestamp, laser_color]) self._shot_timer_tree.see(tree_item) new_shot = Shot((x, y), self._webcam_canvas, self._preferences[configurator.MARKER_RADIUS], laser_color, timestamp) self._shots.append(new_shot) new_shot.draw_marker() if hit_projector_region != None and self._loaded_training != None: self._loaded_training.hit_listener(hit_projector_region, projector_region_tags, new_shot, tree_item) return # Process the shot to see if we hit a region and perform # a training protocol specific action and any if we did # command tag actions if we did self.process_hit(new_shot, tree_item)