I have a file in which I have a function to open camera.
Code: Select all
import cv2
cap = cv2.VideoCapture(0)
cap.set(3, 320)
cap.set(4 , 240)
def open_camera(capture):
if(capture):
ret , frame = cap.read()
cv2.imshow("I see you !!!" , frame)
if(cv2.waitKey(1) == ord('c')):
cap.release()
cv2.destroyAllWindows()
capture = False
return capture
In another file I have a while True inside a function (call_getch() ) that makes another work .
In this while True I use an input and when I press "w" ,then I do something ,when I press "s" , I do something else(not important)
When I press "c" ,then I call open_camera(True) to open camera.Done.It's ok.
When I click above the window of video and then press "c" ,the camera and the window close.This is what I want.OK
But ,when I press again "c" button from keyboard ,I get an error and program terminates:
Code: Select all
cv2.error: OpenCV(4.2.0) /io/opencv/modules/highgui/src/window.cpp:376: error: (-215:Assertion failed) size.width>0 && size.height>0 in function 'imshow'
Code: Select all
def call_getch():
enable_camera = False
give_move = curses.initscr()
curses.noecho()
give_move.nodelay(1) # set getch() non-blocking
try:
while True:
move_bar_with_w_s = give_move.getch()
if(move_bar_with_w_s == ord("w")):
do something...
if(move_bar_with_w_s == ord("s")):
do something else...
if(move_bar_with_w_s == ord("c")) :
enable_camera = True
if(enable_camera):
ac = open_camera(True) #return value from open_camera() method.
if ac == False:
enable_camera = False
finally:
curses.endwin()
system("clear")
call_getch()
Thanks guys...