theAIGuysCode / yolov4-custom-functions

A Wide Range of Custom Functions for YOLOv4, YOLOv4-tiny, YOLOv3, and YOLOv3-tiny Implemented in TensorFlow, TFLite, and TensorRT.
MIT License
601 stars 372 forks source link

can't open camera by index in Colab #97

Open isinsuarici opened 2 years ago

isinsuarici commented 2 years ago

I'm using colab and when I run the following code:

!python detect_video.py --weights ./checkpoints/yolov4-416 --size 416 --model yolov4 --video 0 --output ./detections/results2.avi --crop

then it says:

[ WARN:0@5.489] global /io/opencv/modules/videoio/src/cap_v4l.cpp (902) open VIDEOIO(V4L2:/dev/video0): can't open camera by index
Video has ended or failed, try a different video format!

I know the problem is with opening the camera in Colab. But I couldn't find how to solve it.

isinsuarici commented 2 years ago

I know it's about the part:

try:
    vid = cv2.VideoCapture(int(video_path))
except:
    vid = cv2.VideoCapture(video_path)

When I wrote --video 0, it looks for a camera but Colab doesn't have a camera. I have to connect to my local camera. But how can I do that? ( I saw the snippets about Javascript but I can't use it in this way.)