The windows platform uses the CMake tool to compile and install darknet + yolov3 + image detection + camera detection + video detection + mobile phone as a camera for detection (detailed explanation)

Table of contents

1. Compile and install tutorial

(1) Install visual studio 2022

(2) Download and install CMake

(3) Download the darknet.zip file

(4) Install OpenCV 

(5) Modify the Makefile file

(6) Modify the CMakeLists.txt file

(7) Use the CMake tool

2.yolov3 for testing

(1) Single image for detection 

(2) Turn on the camera for detection

(3) Video detection

(4) Use the camera of the mobile phone as the camera of the computer for detection


The process of compiling and installing DarkNet (detailed explanation without GPU)

Two IP Camera+YOLOV3 for target detection (the phone camera is used as a computer camera)

Tip: Regarding the process of using make to compile DarkNet, there is no problem when performing target detection on a single image. But in fact, there is an unsolved problem, that is, if it is to detect the video or turn on the camera for detection, it will cause a big problem. The following uses CMake to compile darknet, which can detect the target on a single image or turn on the camera. detection.

https://github.com/AlexeyAB/darknet#for-using-network-video-camera-mjpeg-stream-with-any-android-smartphone

Note: Relevant tutorials have been given in this official GitHub code, but details and problems that will arise in the later use process are not given. This article mainly solves some details and possible problems.

 

1. Compile and install tutorial

(1) Install visual studio 2022

https://visualstudio.microsoft.com/thank-you-downloading-visual-studio/?sku=Community

(2) Download and install CMake

https://cmake.org/download/

https://mydreamambitious.blog.csdn.net/article/details/130367003

Tip: Readers can unzip it after downloading, and you can see a cmake-gui.exe executable file in the /bin directory, which will be used later. 

(3) Download the darknet.zip file

https://github.com/AlexeyAB/darknet/archive/master.zip

Tip: This is the official code and many other documents.

(4) Install OpenCV 

https://opencv.org/releases/

Tip 1: After installing OpenCV, add the following path to the Path environment variable :

E:\opencv\build\x64\cv15\lib

Tip 2: In order to prevent the prompt that OpenCV cannot be found when configuring CMake later, perform the following operations:

Add the build path under the OpenCV directory :

(5) Modify the Makefile file

 

(6) Modify the CMakeLists.txt file

Tip: This is an error reported during the configuration and generation process using CMake. Due to the CPU we use, the following modifications need to be made here. 

Tip: Why do you need to modify it here? It is because we are prompted that we do not use GPU when using the CMake tool for configuration and generation. Then the GPU and CUDNN here also need to be modified to OFF and turned off. 

Or if you do not directly modify the content of the CMakeLists.txt file, you can also remove the "√" in the red part below it about CUDA.

 

(7) Use the CMake tool

hint:

  • The first path is the darknet-master path after decompressing the downloaded darknet.zip;
  • The second path is where the files after build are stored, choose a path by yourself (note that it is best not to have Chinese in this path).

Tip: Select the version of visual studio 2022 you just installed (the version must correspond), and select the x64 version. After the selection is complete, click "finish".

  

Tip: Start configuration. If you make an error during the configuration process, you need to reconfigure. Click on CMake:

 

 

Tip: After the configuration is complete, you can click "Generate". 

 

Tip: After the generation is complete, click "Open Project".

 

Tip: Find the Release directory according to the build path you selected before, and you can see darknet.exe under it. You can copy it to the darknet-master directory (you decide, but it is more convenient to use later). 

 

2.yolov3 for testing

YOLOV3 homepage: https://pjreddie.com/darknet/yolo/

(1) Single image for detection 

Tip: First use the following command to detect a single image (the darknet.exe has been copied to the darknet-master directory, and is currently in the darknet-master directory), open the cmd command window (windows) :

darknet detect cfg/yolov3.cfg weights/yolov3.weights data/dog.jpg

  • The path of darknet must be specified (since darknet is in the current directory, just write darknet);
  • The detect keyword must be specified;
  • Specify the location of the yolov3.cfg configuration file;
  • Specify the location of the yolov3.weights weight file;
  • Specify the path of the test picture dog.jpg;

Tip: When using the above command, an error may be reported, such as:

  •  Code execution cannot continue because opencv world455.dll cannot be found. Reinstalling the program may resolve this issue.
  • Code execution cannot continue because pthreadVC2.dlI cannot be found. Reinstalling the program may resolve this issue.

Tip: The solution is as follows, that is to find the corresponding error file under the opencv\build\x64\vc15\bin directory where the opencv is installed and copy it to the current darknet-master directory: 

 You can go to darknet-master\build\darknet\x64 to find pthreadVC2.dll and copy it to the current darknet-master directory.

 

 

 

(2) Turn on the camera for detection

darknet detector demo cfg/coco.data cfg/yolov3-tiny.cfg weights/yolov3-tiny.weights

Related explanations are as above:

  

Tip: Press the ESC key to exit the test. 

(3) Video detection

darknet detector demo cfg/coco.data cfg/yolov3-tiny.cfg weights/yolov3-tiny.weights video/demo.mp4

Note: Maybe an error will be reported when executing the above command:

Solution:  The solution is as follows, which is to find the corresponding error file under the opencv\build\x64\vc15\bin directory of the installation location of opencv and copy it to the current darknet-master directory:

Copy the file opencv_videoio_ffmpeg455_64.dll to the current darknet-master directory: 

 

 

(4) Use the camera of the mobile phone as the camera of the computer for detection

Two IP Camera+YOLOV3 for target detection (the phone camera is used as a computer camera)

 

darknet detector demo cfg/coco.data cfg/yolov3-tiny.cfg weights/yolov3-tiny.weights http://admin:[email protected]:8080/video (Note: the mobile phone and computer are in the same network segment (same as A hotspot or WIFI))

 

Guess you like

Origin blog.csdn.net/Keep_Trying_Go/article/details/130804424