# cv2.putText(vis_roi, # "%s (%s)" % (who, confidence), # (sx1 + 2, sy1 + 20 + 20 * i), # cv2.FONT_HERSHEY_PLAIN, 1.1, color) winning_label = recog.get_overall_prediction(predictions) #rect_color = recog.LABEL_COLORS[winning_label] karlness_update = 1 if who == "Karl" else 0 else: #rect_color = (0, 255, 255) karlness_update = 1 karlness = KARLNESS_DECAY * karlness + (1 - KARLNESS_DECAY) * karlness_update rect_color = (0, 255 * (1 - karlness), 255 * karlness) draw_rects(vis_roi, subtargets, rect_color) if not contains(next_targets, subtargets[0]): fixed_rect = [max(0, x1-BUFFER)+sx1,max(0, y1-BUFFER)+sy1,max(0, x1-BUFFER)+sx2,max(0, y1-BUFFER)+sy2] s_last, c_last = size_and_center(fixed_rect) next_targets.append(( fixed_rect, 0, VELOCITY_DECAY*velocity+(1-VELOCITY_DECAY)*np.array(diff(c_last, c)), karlness )) else: # draw_rects(vis, [rect], (0,0,255)) if misses < MAX_MISSES:
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)) targets = next_targets if is_auto: targeter.update_targets(targets) # print "targets: ", len(targets)
# (sx1 + 2, sy1 + 20 + 20 * i), # cv2.FONT_HERSHEY_PLAIN, 1.1, color) winning_label = recog.get_overall_prediction( predictions) #rect_color = recog.LABEL_COLORS[winning_label] karlness_update = 1 if who == "Karl" else 0 else: #rect_color = (0, 255, 255) karlness_update = 1 karlness = KARLNESS_DECAY * karlness + ( 1 - KARLNESS_DECAY) * karlness_update rect_color = (0, 255 * (1 - karlness), 255 * karlness) draw_rects(vis_roi, subtargets, rect_color) if not contains(next_targets, subtargets[0]): fixed_rect = [ max(0, x1 - BUFFER) + sx1, max(0, y1 - BUFFER) + sy1, max(0, x1 - BUFFER) + sx2, max(0, y1 - BUFFER) + sy2 ] s_last, c_last = size_and_center(fixed_rect) next_targets.append( (fixed_rect, 0, VELOCITY_DECAY * velocity + (1 - VELOCITY_DECAY) * np.array(diff(c_last, c)), karlness))
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)) targets = next_targets if is_auto: targeter.update_targets(targets) # print "targets: ", len(targets) dt = clock() - t # with the_lock: # print "time: ", dt*1000