python - OpenCV webcam capture -


i'm afraid have run bit beyond scope of novice abilities. quick summary of problem: attempting capture live video stream during experiment (using opensesame) webcam using opencv python module. can work, issue code pops open new window show live stream recording. how alter code not show live window still able press 'q' shut off live stream?

import numpy np import cv2  subject = str(self.get('subject_nr')) cap = cv2.videocapture(0) w=int(cap.get(cv2.cap_prop_frame_width )) h=int(cap.get(cv2.cap_prop_frame_height ))  #define codec , create videowriter object #fourcc = cv2.videowriter_fourcc(*'divx') fourcc = cv2.videowriter_fourcc(*'xvid') out = cv2.videowriter('path\to\output'+ subject + '.avi', -1, 20.0, (w,h))  while(cap.isopened()):     ret, frame = cap.read()     if ret==true:          out.write(frame)          cv2.imshow('frame',frame)         if cv2.waitkey(1) & 0xff == ord('q'):             break     else:         break  #release if job finished cap.release() out.release() cv2.destroyallwindows() 

cv2.waitkey() captures keystrokes highgui window. cannot use waitkey capture keystrokes if never display window. need can capture keystrokes terminal.

for linux, can achieve using termios , fcntl modules. here example python's documentation. https://docs.python.org/2/faq/library.html#how-do-i-get-a-single-keypress-at-a-time


Comments

Popular posts from this blog

javascript - Bootstrap Popover: iOS Safari strange behaviour -

Magento/PHP - Get phones on all members in a customer group -

session - Logging Out Using PHP -