def update_target_rect(self, rect_misses): if rect_misses[1] == 0: size, center = size_and_center(rect_misses[0]) self.target = center + rect_misses[2] self.correction = distance_correction(size[0]) else: self.target = None
continue targets.append((rect, 0, np.zeros(2), 0)) possible_targets[:] = [] vis = img.copy() next_targets = [] for rect, misses, velocity, karlness in targets: x1, y1, x2, y2 = rect with the_lock: roi = low_image[max(0, y1-BUFFER):min(width, y2+BUFFER), max(0, x1-BUFFER):min(height, x2+BUFFER)] # draw_rects(vis, [[max(0, x1-BUFFER), max(0, y1-BUFFER), min(height, x2+BUFFER), min(width, y2+BUFFER)]], (255,0,0)) subt = clock() s, c = size_and_center(rect) subtargets = detect(roi.copy(), cascade_nested, size=(max(30, s[0]-REFIND_BUFFER), max(30, s[1]-REFIND_BUFFER))) # with the_lock: # print "subtarget detect: ", clock() - subt if len(subtargets) == 1: sx1, sy1, sx2, sy2 = subtargets[0] vis_roi = vis[max(0, y1-BUFFER):min(width, y2+BUFFER), max(0, x1-BUFFER):min(height, x2+BUFFER)] if recognizing: detection_image = roi[sy1:sy2, sx1:sx2] predictions = recognizer.predict(cv.fromarray(detection_image)) for i, (label, confidence) in enumerate(predictions): color = recog.LABEL_COLORS[label] who = recog.LABELS[label] # cv2.putText(vis_roi, # "%s (%s)" % (who, confidence),
vis = img.copy() next_targets = [] for rect, misses, velocity, karlness in targets: x1, y1, x2, y2 = rect with the_lock: roi = low_image[max(0, y1 - BUFFER):min(width, y2 + BUFFER), max(0, x1 - BUFFER):min(height, x2 + BUFFER)] # draw_rects(vis, [[max(0, x1-BUFFER), max(0, y1-BUFFER), min(height, x2+BUFFER), min(width, y2+BUFFER)]], (255,0,0)) subt = clock() s, c = size_and_center(rect) subtargets = detect(roi.copy(), cascade_nested, size=(max(30, s[0] - REFIND_BUFFER), max(30, s[1] - REFIND_BUFFER))) # with the_lock: # print "subtarget detect: ", clock() - subt if len(subtargets) == 1: sx1, sy1, sx2, sy2 = subtargets[0] vis_roi = vis[max(0, y1 - BUFFER):min(width, y2 + BUFFER), max(0, x1 - BUFFER):min(height, x2 + BUFFER)] if recognizing: detection_image = roi[sy1:sy2, sx1:sx2] predictions = recognizer.predict( cv.fromarray(detection_image))
possible_targets[:] = [] vis = img.copy() next_targets = [] last_time = time.time() for rect, misses, _ in targets: x1, y1, x2, y2 = rect with the_lock: roi = low_image[max(0, y1 - BUFFER):min(width, y2 + BUFFER), max(0, x1 - BUFFER):min(height, x2 + BUFFER)] # draw_rects(vis, [[max(0, x1-BUFFER), max(0, y1-BUFFER), min(height, x2+BUFFER), min(width, y2+BUFFER)]], (255,0,0)) subt = clock() s, c = size_and_center(rect) roi_copy = roi.copy() subtargets = detect(roi_copy, cascade_nested, size=(max(30, s[0] - REFIND_BUFFER), max(30, s[1] - REFIND_BUFFER))) if len(subtargets) == 1: sx1, sy1, sx2, sy2 = subtargets[0] if not contains(next_targets, subtargets[0]): next_targets.append(([ max(0, x1 - BUFFER) + sx1, max(0, y1 - BUFFER) + sy1, max(0, x1 - BUFFER) + sx2, max(0, y1 - BUFFER) + sy2 ], 0, None)) vis_roi = vis[max(0, y1 - BUFFER):min(width, y2 + BUFFER),
targets.append((rect, 0, None)) possible_targets[:] = [] vis = img.copy() next_targets = [] last_time = time.time() for rect, misses, _ in targets: x1, y1, x2, y2 = rect with the_lock: roi = low_image[max(0, y1-BUFFER):min(width, y2+BUFFER), max(0, x1-BUFFER):min(height, x2+BUFFER)] # draw_rects(vis, [[max(0, x1-BUFFER), max(0, y1-BUFFER), min(height, x2+BUFFER), min(width, y2+BUFFER)]], (255,0,0)) subt = clock() s, c = size_and_center(rect) roi_copy = roi.copy() subtargets = detect(roi_copy, cascade_nested, size=(max(30, s[0]-REFIND_BUFFER), max(30, s[1]-REFIND_BUFFER))) if len(subtargets) == 1: sx1, sy1, sx2, sy2 = subtargets[0] if not contains(next_targets, subtargets[0]): next_targets.append(([max(0, x1-BUFFER)+sx1,max(0, y1-BUFFER)+sy1,max(0, x1-BUFFER)+sx2,max(0, y1-BUFFER)+sy2], 0, None)) vis_roi = vis[max(0, y1-BUFFER):min(width, y2+BUFFER), max(0, x1-BUFFER):min(height, x2+BUFFER)] draw_rects(vis_roi, subtargets, (0, 255, 0)) cv.SaveImage("%s/roi/%s.pgm" % (output_dir, time.time()), cv.fromarray(roi_copy, allowND=True)) cv.SaveImage("%s/face/%s.pgm" % (output_dir, time.time()), cv.fromarray(roi[sx1:sx2, sy1:sy2].copy(), allowND=True)) else: # draw_rects(vis, [rect], (0,0,255)) if misses < MAX_MISSES: next_targets.append((rect, misses+1, None))