def fetch_yesterday(): """下载昨日的数据""" jobs = [gevent.spawn(fetch, year, month, day, n) for n in range(24)] gevent.joinall(jobs) if not util.detect(data_dir, year, month, day): util.sendmail('Download Error', '\n'.join(os.listdir(data_dir)) + '\nFound In Target Dir.')
def high_level_tracker(image, should_stop, lock, targets, cascade): # 1 thread, high level tracking last_taunt_time = 0 next_taunt_wait = 3*(1+random.random()) while True: with lock: if ord(should_stop.value): break high_image = image.copy() # t = clock() rects = detect(high_image, cascade) # with lock: # print "high just took: ", clock() - t if len(rects) > 0: with lock: targets[:] = rects if (time.time() - last_taunt_time) > next_taunt_wait: speak() last_taunt_time = time.time() next_taunt_wait = 3*(1+random.random())
def fetch_yesterday(): """下载昨日的数据""" jobs = [gevent.spawn(fetch, year, month, day, n) for n in range(24)] gevent.joinall(jobs) if not util.detect(data_dir, year, month, day): util.sendmail( 'Download Error', '\n'.join(os.listdir(data_dir)) + '\nFound In Target Dir.')
def high_level_tracker(image, should_stop, lock, targets, cascade): # 1 thread, high level tracking while True: with lock: if ord(should_stop.value): break high_image = image.copy() # t = clock() rects = detect(high_image, cascade) # with lock: # print "high just took: ", clock() - t if len(rects) > 0: with lock: targets[:] = rects
def main(): input_dir = args.input_dir output_dir = args.output_dir if not os.path.exists(output_dir): os.makedirs(output_dir) for f_path in os.listdir(input_dir): f = f_path.split('.') suffix = f[-1].lower() prefix = os.path.split(f[-2])[-1] filename = prefix + '.' + suffix img = cv2.imread(os.path.join(input_dir, f_path)) centers, landmarks = detect(img) if landmarks is None: with open(os.path.join(output_dir, 'fails.log'), 'a') as f: f.write(filename) print(filename, 'failed') continue print(filename) if suffix in ['jpg', 'png']: for ft_list in ft_lists: dirname = '-'.join(ft_list) ft_dir = os.path.join(output_dir, dirname) # img = auto_mask_single_img(f_path, ft_list, disturb_ellipse=0) mask = get_mask(img, ft_list, centers, landmarks, disturb_ellipse=2, randrange=(10, 50)) if not os.path.exists(ft_dir): os.makedirs(ft_dir) imsave(os.path.join(ft_dir, filename), mask)
def high_level_tracker(image, should_stop, lock, targets, cascade): # 1 thread, high level tracking last_taunt_time = 0 next_taunt_wait = 3 * (1 + random.random()) while True: with lock: if ord(should_stop.value): break high_image = image.copy() # t = clock() rects = detect(high_image, cascade) # with lock: # print "high just took: ", clock() - t if len(rects) > 0: with lock: targets[:] = rects if (time.time() - last_taunt_time) > next_taunt_wait: speak() last_taunt_time = time.time() next_taunt_wait = 3 * (1 + random.random())
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), # (sx1 + 2, sy1 + 20 + 20 * i),
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]
def test15(): print util.detect('/Users/liushuai/Downloads/data/2013/11/3', 2013, 11, 3)