1

I tried using a webcam in Kaggle to take capture for the face detection project. but it's not working.

code working well in Jupyter Notebook in the system

here is the code that I'm using :

cap = cv2.VideoCapture(0)

for imgnum in range(number_images):
    print('Collectiong image {}'.format(imgnum))
    ret,frame = cap.read()
    imgname = os.path.join(IMAGES_PATH,f'{str(uuid.uuid1())}.jpg')
    cv2.imwrite(imgname,frame)
    cv2.imshow('frame', frame)
    time.sleep(1)
    
    if cv2.waitKey(1) & 0xFF == ord('q'):
        break
cap.release()
cv2.destroyAllWindows()

this is the error that Kaggle shows : Collectiong image 0

[ WARN:0] global /tmp/pip-req-build-jpmv6t9_/opencv/modules/videoio/src/cap_v4l.cpp (890) open VIDEOIO(V4L2:/dev/video0): can't open camera by index --------------------------------------------------------------------------- error Traceback (most recent call last) /tmp/ipykernel_27/1415701618.py in 4 ret,frame = cap.read() 5 imgname = os.path.join(IMAGES_PATH,f'{str(uuid.uuid1())}.jpg') ----> 6 cv2.imwrite(imgname,frame) 7 cv2.imshow('frame', frame) 8 time.sleep(1)

error: OpenCV(4.5.4) /tmp/pip-req-build-jpmv6t9_/opencv/modules/imgcodecs/src/loadsave.cpp:799: error: (-215:Assertion failed) !_img.empty() in function 'imwrite'

note: I tried to use 1,2 values in cap = cv2.VideoCapture(0) . but is not working.

if any body has any way please write. thankyou

Alireza Atashnejad
  • 612
  • 1
  • 6
  • 22
  • This does not look like it is possible, maybe try google colab: https://www.kaggle.com/product-feedback/90890 – Caridorc Apr 09 '23 at 20:29

0 Answers0