AlexeyAB / darknet

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

cvQueryFrame continually returns null #343

Open UsaidPro opened 6 years ago

UsaidPro commented 6 years ago

I've been trying to use Darknet to process images taken through my laptop's webcam using the demo code. The problem I'm having is that the camera opens (through cvCaptureFromCAM) but it doesn't return frames (through cvQueryFrame). I know that the camera works (can access it using other applications).

System: Windows 10, GTX 1050, Opencv 3, MS Visual Studio 2015

I've also noticed that Opencv seems to have dropped support for their C API. Any plans to move to the C++ API?

EDIT: I've confirmed that the camera works fine using the C++ API (same environment).

AlexeyAB commented 6 years ago

@UsaidPro Hi,


You can try to use Darknet Yolo as DDL/SO-library and C++ application that uses this library:

  1. At first change this line: https://github.com/AlexeyAB/darknet/blob/22bf10984cb7940e84db4f086ecbc25d9d5d64b5/src/yolo_console_dll.cpp#L147 to this: cv::VideoCapture cap(0); cap >> cur_frame; // where 0 - is number of web-cam

  1. Compile and run DDL/SO-library and C++ aplication that uses this library:
AlexeyAB commented 6 years ago

Also if you want to decrease delay of your web-cam -

you can try to change these lines: https://github.com/AlexeyAB/darknet/blob/22bf10984cb7940e84db4f086ecbc25d9d5d64b5/src/yolo_console_dll.cpp#L241-L244

to these:

    std::unique_lock<std::mutex> lock(mtx);
    while (!consumed) cv_detected.wait(lock);
AlexeyAB commented 6 years ago

I fixed it. Just update your code from this repo. It was C API bug in OpenCV 3.x.