def find_interesting_object(classifier, wc_paths): for i, path in enumerate(wc_paths): print i cam = Webcam(online=False, path=path) for i in range(10): cam.update() for patch in cam.patches(squareSize=227): if patch is not None: rankings = classifier.rankings(patch) for label, idx, prob in rankings: if label == 'human' and prob > 0.015: print rankings cv2.imshow('patch', patch) cv2.waitKey(0)
from detector.Webcam import Webcam from classify.classifier import ReferenceClassifier from classify.classifier import CamClassifier parser = argparse.ArgumentParser() parser.add_argument("frames_dir", help = "Directory containing webcam image folders") parser.add_argument("num_webcams", help = "Number of webcams to sample", type = int) args = parser.parse_args() frames_dir = args.frames_dir num_webcams = args.num_webcams wc_paths = [os.path.join(frames_dir, fn) for fn in os.listdir(frames_dir)] wc_paths = random.sample(wc_paths, num_webcams) classifier = CamClassifier() classifier.set_batch_size(1) while True: for path in wc_paths: cam = Webcam(online=False, path=path) for i in range(5): cam.update() overlay = cam.filtered_overlay(classifier, squareSize=227) if overlay is not None: cv2.imshow('overlay', overlay) cv2.waitKey(0)
def classify_one(classifier, patches): random.shuffle(patches) for patch in patches: if patch is not None: print patch.shape #classification = classifier.classify(patch) cv2.imshow('patch', patch) #print classifier.label(classification) classifier.rankings(patch) cv2.waitKey(0) return classifier = CamClassifier() classifier.set_batch_size(1) webcam = Webcam(online = True, path = "http://vso.aa0.netvolante.jp/record/current.jpg") K_HUMAN_THRESH = 0.0002 def find_human_in_cam(classifier, cam): patches = webcam.patches(squareSize=227) random.shuffle(patches) for patch in patches: if patch is not None: rankings = classifier.rankings(patch) for ranking in rankings: label, idx, prob = ranking if label != 'noise' and prob > 0.5: if prob > K_HUMAN_THRESH: print rankings cv2.imshow('patch', patch)
for patch in patches: if patch is not None: cv2.imshow("patch", patch) k = cv2.waitKey(0) & 0xFF if k in KEYS: command = KEYS[k] if command == "QUIT": sys.exit(0) elif command == "NEXT": print "PROCESSING NEXT WEBCAM" return elif command in LABELS: print command save_patch(patch, command) else: print "Unrecognized command" return else: print "Frame unlabeled." webcam_no = 241 wc_paths = sorted(wc_paths) wc_paths = wc_paths[webcam_no:] for wc_path in sorted(wc_paths): cam = Webcam(online=False, resize=(width, width), path=wc_path) cam.update() process_cam(cam) print "WEBCAM_NO", webcam_no webcam_no += 1