vandalsp
vandalsp

Reputation: 1

Code works in Windows but not Raspberry pi (opencv)

I'm new to coding and using a raspberry pi. I've searched through many tutorials online and found a how to get OpenCV library into the pi itself and downloaded VSC on my laptop and the pi. The issue that I'm having is the code that I used on my laptop doesn't work the same on the pi. I've been getting errors on my code that dosen't show in in my laptop VSC.

the purpose is to display a live feed from the camera in the raspberry pi

import numpy as np
import cv2

cap = cv2.VideoCapture(0)

while(True):
    ret, frame = cap.read()

    frame = cv2.resize(frame, (0,0), fx=0.5,fy=0.5)
    cv2.imshow("Frame",frame)

    ch = cv2.waitKey(1)
    if ch & 0xFF == ord('q'):
        break

cap.release()
cv2.destroyAllWindows()

Upvotes: 0

Views: 153

Answers (1)

danangjoyoo
danangjoyoo

Reputation: 360

I think you have to use different device id in cv.VideoCapture(id)

because raspberry is using linux and at some point the id is not always 0

Upvotes: 0

Related Questions