AlexeyAB / darknet

YOLOv4 / Scaled-YOLOv4 / YOLO - Neural Networks for Object Detection (Windows and Linux version of Darknet )
http://pjreddie.com/darknet/
Other
21.75k stars 7.96k forks source link

Make webcam resolution configurable via command line #2228

Open tdurand opened 5 years ago

tdurand commented 5 years ago

Hi @AlexeyAB , thanks a lot for you work, it improve greatly perfs from default darknet implem and add some nice features !

I'm working on some project that needs to be able to change the default webcam resolution, I saw that I can do so easily by changing:

((cv::VideoCapture*)cap)->set(CV_CAP_PROP_FRAME_WIDTH, 720);
((cv::VideoCapture*)cap)->set(CV_CAP_PROP_FRAME_HEIGHT, 405);

In http_stream.cpp#481

I would like to make it configurable directly via command line with a new option, for example: -c_resolution, would lead to something like:

./darknet detector demo cfg/voc.data cfg/yolo-voc.cfg yolo-voc.weights -c 0 -c_resolution 720x405

What do you think, would you be interested in a PR for this ?

Thanks.

AlexeyAB commented 5 years ago

@tdurand Hi,

I'm working on some project that needs to be able to change the default webcam resolution, I saw that I can do so easily by changing:

((cv::VideoCapture)cap)->set(CV_CAP_PROP_FRAME_WIDTH, 720); ((cv::VideoCapture)cap)->set(CV_CAP_PROP_FRAME_HEIGHT, 405); In http_stream.cpp#481

Yes, you can change these lines, but in most cases the resolution on the camera is set different from the specified one.

Also it would not be better to configure the webcam using the V4L2-ctl utility? https://elinux.org/Thread:Talk:Jetson/Cameras/How_to_do_I_change_the_USB_camera_resolution%3F

   v4l2-ctl --set-fmt-video=width=1920,height=1080,pixelformat=YUYV
   v4l2-ctl --set-fmt-video=width=1920,height=1088,pixelformat=4   # For Raspberry Pi Cam
   v4l2-ctl -v width=1280,height=720,pixelformat=BGR3

More: https://www.kurokesu.com/main/2016/01/16/manual-usb-camera-settings-in-linux/

Or install OpenCV with Gstreamer for real-time capture and run Darknet as: /darknet detector demo cfg/coco.data cfg/yolov3-tiny.cfg yolov3-tiny.weights "v4l2src ! video/x-raw, framerate=30/1, width=640, height=480, format=RGB ! videoconvert ! appsink"

tdurand commented 5 years ago

Thanks for you answer, from what I found out:

  1. Changing resolution with v4l2-ctl doesn't seem to have any effect on OpenCV VideoCapture, it always picks up the default resolution 640x480
  2. Changing directly ((cv::VideoCapture*)cap)->set(CV_CAP_PROP_FRAME_WIDTH, **); works for me only if I set a supported resolution of the webcam, which you can find out with this command v4l2-ctl -d 0 --list-formats-ext
  3. I didn't try to run darknet directly from a Gstreamer stream, I'm working on a Jetson TX2 with Jetpack 3.3 which come with OpenCV 3.3.1 which doesn't include GStreamer, I know I can reinstall opencv with gstreamer included, but for now I would like to keep the setup of the tool easy and avoid too much config.

I think I will include this flag option like -c_resolution 1280x720 in a fork of your darknet version.. I'll send a PR but feel free to include it or not... I understand it may not be in the interest of this tool to have too much config flags.

AlexeyAB commented 5 years ago

@tdurand

Jetson TX2 with Jetpack 3.3

What ~latency do you have for CSI-2 camera on TX2 without Gstreamer?

I think I will include this flag option like -c_resolution 1280x720 in a fork of your darknet version.. I'll send a PR but feel free to include it or not... I understand it may not be in the interest of this tool to have too much config flags.

Ok, try to do more changes in http_stream.cpp and less in detector.c.

tdurand commented 5 years ago

What ~latency do you have for CSI-2 camera on TX2 without Gstreamer?

I'm using a usb logitech camera, not sure how to measure the latency ?

Ok, try to do more changes in http_stream.cpp and less in detector.c.

👍 , will do likely next week.