How can i make the cv2.VideoCapture(0) recognize the USB camera of raspberry-pi.

```
def OnRecord(self, evt):
    capture = cv2.VideoCapture(0)
    if (not capture.isOpened()):
        print "Error"
# video recorder
    fourcc = cv2.cv.CV_FOURCC(*'XVID')  # cv2.VideoWriter_fourcc() does not exist
    video_writer = cv2.VideoWriter.open("output.mp4", fourcc, 20, (640, 480), True)

    # record video
    while (capture.isOpened()):
        ret, frame = capture.read()
        if ret==True:
            video_writer.write(frame)
            cv2.imshow('Video', frame)
        else:
            break

def OnCancel(self, evt):
    capture.release()
    video_writer.release()
    cv2.destroyAllWindows()

```

but it only prints Error.

So i guess capture is not opening. What might be the reason?

I tried this code from opencv documentation but doesn't worked out for me.

```
import numpy as np
import cv2

cap = cv2.VideoCapture(0)

# Define the codec and create VideoWriter object
fourcc = cv2.VideoWriter_fourcc(*'XVID')
out = cv2.VideoWriter('output.avi',fourcc, 20.0, (640,480))

while(cap.isOpened()):
    ret, frame = cap.read()
    if ret==True:
        frame = cv2.flip(frame,0)

        # write the flipped frame
        out.write(frame)

        cv2.imshow('frame',frame)
        if cv2.waitKey(1) & 0xFF == ord('q'):
            break
    else:
        break

# Release everything if job is finished
cap.release()
out.release()
cv2.destroyAllWindows()

```

Any help would be greatly appreciated.