0

I am testing a simple open-cv example on a project hosted on FloydHub. I have installed opencv using 'pip install opencv-python'. I am trying to capture the video from web cam this way:

import cv2
cap = cv2.VideoCapture(1)

while(True):
 _, frame = cap.read()
 cv2.imshow('frame',frame)
 if (cv2.waitKey(1) & 0xFF == ord('q')):
    break

cap.release()
cv2.destroyAllWindows()

but it gives me this error: error: /io/opencv/modules/highgui/src/window.cpp:331: error: (-215) size.width>0 && size.height>0 in function imshow.

I get the same error with cv2.VideoCapture(0).

I'm trying the same example from a jupyter notebook outside of Floydhub and it works perfectly.

  • `cap.read()` failed for some reason, but your program doesn't consider that a possibility and tries to display the empty image anyway. – Dan Mašek Aug 27 '18 at 14:53
  • @DanMašek yes, I figured that. I am trying to find why cap.read() failed –  Aug 27 '18 at 14:55
  • I got this error. `error: OpenCV(3.4.2) /Users/travis/build/skvark/opencv-python/opencv/modules/highgui/src/window.cpp:356: error: (-215:Assertion failed) size.width>0 && size.height>0 in function 'imshow'` Have you tried restarting the kernel? or just rebooting the computer? worked for me after i set .VideoCaptrue(0) – Stanley Aug 27 '18 at 14:55
  • Isn't FloydHub a cloud based service, meaning your code runs on some server in a hosting center? As such, it can't use your local hardware... – Dan Mašek Aug 27 '18 at 14:55
  • It is not able to access your webcam. – Garvita Tiwari Aug 27 '18 at 14:58
  • @GarvitaTiwari is there any way I could give access to my webcam? –  Aug 27 '18 at 15:03
  • @DanMašek that makes sense. Is there any way I can give access to it from Floydhub? –  Aug 27 '18 at 15:09
  • In short, you'd need to read the data on the client, stream it to the server, and since you want to display it, stream the image data back to the client. TBH, as is, this script doesn't make sense running on a server. Beside the problem with VideoCapture, there's also `imshow`/`waitKey` and related. If you run `imshow` on a remote machine (server), it will try to open a window on that machine, which is probably not what you want. – Dan Mašek Aug 27 '18 at 15:55
  • Check your webcam connection – Sreekiran A R Sep 05 '18 at 05:45

0 Answers0