def main(camera): # camera = cv2.VideoCapture(0) hd = HandDetection() df = DrawFrame() while True: (grabbed, frame_in) = camera.read() frame_orig = frame_in.copy() # make a window smaller frame_final = df.resize(frame_in) # flipped frame to draw on # frame_final = df.flip(frame) if cv2.waitKey(1) == ord("h") & 0xFF: if not hd.trained_hand: hd.train_hand(frame_final) if not hd.trained_hand: frame_final = hd.draw_hand_rect(frame_final) elif hd.trained_hand: frame_final = frame_final[30:500, 30:350] frame_final = df.draw_final(frame_final, hd) cv2.imshow("Image", frame_final) if cv2.waitKey(1) == ord("q") & 0xFF: break
def loop(output_video): camera = cv2.VideoCapture(0) if output_video != None: fourcc = cv2.cv.CV_FOURCC('m', 'p', '4', 'v') video = cv2.VideoWriter(output_video, fourcc, 20, (711,800)) record_video = True else: record_video = False df = DrawFrame() pd = PaperDetection() hd = HandDetection() while True: # get frame (grabbed, frame_in) = camera.read() # original frame frame_orig = frame_in.copy() # shrink frame frame = df.resize(frame_in) # flipped frame to draw on frame_final = df.flip(frame) # click p to train paper if cv2.waitKey(1) == ord('p') & 0xFF: if not pd.trained_paper: pd.train_paper(frame) pd.set_paper(frame) pd.set_ocr_text(frame_orig) # click h to train hand if cv2.waitKey(1) == ord('h') & 0xFF: if pd.trained_paper and not hd.trained_hand: hd.train_hand(frame) # click q to quit if cv2.waitKey(1) == ord('q') & 0xFF: break # create frame depending on trained status if not pd.trained_paper: frame_final = pd.draw_paper_rect(frame_final) elif pd.trained_paper and not hd.trained_hand: frame_final = hd.draw_hand_rect(frame_final) elif pd.trained_paper and hd.trained_hand: frame_final = df.draw_final(frame_final, pd, hd) # record frame if record_video: video.write(frame_final) # display frame cv2.imshow('image', frame_final) # cleanup if record_video: video.release() camera.release() cv2.destroyAllWindows()
def loop(output_video): camera = cv2.VideoCapture(0) if output_video != None: fourcc = cv2.cv.CV_FOURCC('m', 'p', '4', 'v') video = cv2.VideoWriter(output_video, fourcc, 20, (711, 800)) record_video = True else: record_video = False df = DrawFrame() pd = PaperDetection() hd = HandDetection() while True: # get frame (grabbed, frame_in) = camera.read() # original frame frame_orig = frame_in.copy() # shrink frame frame = df.resize(frame_in) # flipped frame to draw on frame_final = df.flip(frame) # click p to train paper if cv2.waitKey(1) == ord('p') & 0xFF: if not pd.trained_paper: pd.train_paper(frame) pd.set_paper(frame) pd.set_ocr_text(frame_orig) # click h to train hand if cv2.waitKey(1) == ord('h') & 0xFF: if pd.trained_paper and not hd.trained_hand: hd.train_hand(frame) # click q to quit if cv2.waitKey(1) == ord('q') & 0xFF: break # create frame depending on trained status if not pd.trained_paper: frame_final = pd.draw_paper_rect(frame_final) elif pd.trained_paper and not hd.trained_hand: frame_final = hd.draw_hand_rect(frame_final) elif pd.trained_paper and hd.trained_hand: frame_final = df.draw_final(frame_final, pd, hd) # record frame if record_video: video.write(frame_final) # display frame cv2.imshow('image', frame_final) # cleanup if record_video: video.release() camera.release() cv2.destroyAllWindows()
def register(output_video, name): camera = cv2.VideoCapture(0) df = DrawFrame() hd = HandDetection() timeout = time.time() + 5 while True: # get frame (grabbed, frame_in) = camera.read() # shrink frame frame = df.resize(frame_in) # flipped frame to draw on frame_final = df.flip(frame) #train hand if time.time() > timeout: if not hd.trained_hand: hd.train_hand(frame) # click q to quit if cv2.waitKey(1) == ord('q') & 0xFF: print df.pw break #if hand not trained, draw red squares if not hd.trained_hand: frame_final = hd.draw_hand_rect(frame_final) #if hand trained, draw 9 digits elif hd.trained_hand: frame_final = df.draw_pass_rect(frame_final) frame_final = df.draw_final(frame_final, 12, hd) if len(df.pw) > 3: print df.pw fd = open('login.csv', 'a') fd.write(name + "," + df.pw + "\n") fd.close() break # display frame cv2.imshow('image', frame_final) camera.release() cv2.destroyAllWindows() return True
def authenticate(output_video, name): camera = cv2.VideoCapture(0) fgbg = cv2.BackgroundSubtractorMOG() login = {} with open('login.csv') as f: reader = csv.reader(f) for row in reader: login[row[0]] = row[1] print login #if duplicate names, it will use the pw that is newest in csv file if (name not in login): return False password = login[name] print password df = DrawFrame() hd = HandDetection() timeout = time.time() + 5 while True: # get frame (grabbed, frame_in) = camera.read() fgmask = fgbg.apply(frame_in) cv2.imshow('fgmask', fgmask) # fgmask = fgbg.apply(frame_in) # # Display the fgmask frame # cv2.imshow('fgmask', fgmask) # shrink frame frame = df.resize(frame_in) # flipped frame to draw on frame_final = df.flip(frame) #train hand if time.time() > timeout: if not hd.trained_hand: hd.train_hand(frame) # click q to quit if cv2.waitKey(1) == ord('q') & 0xFF: print df.pw break #if hand not trained, draw red squares if not hd.trained_hand: frame_final = hd.draw_hand_rect(frame_final) #if hand trained, draw 9 digits elif hd.trained_hand: frame_final = df.draw_pass_rect(frame_final) frame_final = df.draw_final(frame_final, 12, hd) if len(df.pw) > 3: print df.pw break # display frame cv2.imshow('image', frame_final) camera.release() cv2.destroyAllWindows() if (password == df.pw): return True else: return False