Reputation: 51
my function did not return continuous frame ,it return only signal frame and then break here is my code:
import cv2
import numpy as np
def video():
cam=cv2.VideoCapture(0)
while cam.isOpened:
_,frame=cam.read()
return frame
im=video()
cv2.imshow("image",im)
cv2.waitKey(0)
I want such function ,when i call this function ,anywhere in my code it return a continues frame and i do stuff on it whatever display ,face detection or other stuff
Upvotes: 0
Views: 228
Reputation: 6080
Try to gather the frames in a while loop without breaking it by returning:
import cv2
import numpy as np
def video(cam):
_,frame=cam.read()
return frame
cam=cv2.VideoCapture(0)
while cam.isOpened:
im=video(cam)
cv2.imshow("image",im)
cv2.waitKey(0)
Upvotes: 1
Reputation: 2917
When you return
, you just exit the while loop, so it just shows 1 image.
import cv2
import numpy as np
cam=cv2.VideoCapture(0)
while cam.isOpened:
_,frame=cam.read()
cv2.imshow("image",frame)
key = cv2.waitKey(1) & 0xFF
if key == ord("q"):
break
cap.release()
cv2.destroyAllWindows()
Upvotes: 0