dataplayer12 / homesecurity

Security camera with Raspberry pi and NVIDIA Jetson platforms
MIT License
177 stars 52 forks source link

Opencv4.5.0 #19

Open FilippoRomeo opened 2 years ago

FilippoRomeo commented 2 years ago

Hi, I was thinking to use OpenCV 4.5.0 on both pi and jetson, what do you suggest? have you tried it?

dataplayer12 commented 2 years ago

Hi, the functions used in this repository are available in every version of opencv (>= 3.0). You should have no problems in using it. I have used opencv 4.5 on jetson but not for this project. Let me know if you encounter any problems.

FilippoRomeo commented 2 years ago

Hi, I had to make some adjustments in the Makefile to specify the version of OpenCV. Now a new error popped when compiling ./compile_darknet.sh

gcc -Iinclude/ -I3rdparty/stb/include -DOPENCV `pkg-config --cflags opencv4` -DGPU -I/usr/local/cuda/include/ -DCUDNN -DCUDNN_HALF -Wall -Wfatal-errors -Wno-unused-result -Wno-unknown-pragmas -fPIC -Ofast -DOPENCV -fopenmp -DGPU -DCUDNN -I/usr/local/cudnn/include -DCUDNN_HALF -fPIC -c ./src/convolutional_layer.c -o obj/convolutional_layer.o
./src/convolutional_layer.c: In function ‘cudnn_convolutional_setup’:
./src/convolutional_layer.c:283:24: error: ‘CUDNN_CONVOLUTION_FWD_PREFER_FASTEST’ undeclared (first use in this function); did you mean ‘CUDNN_CONVOLUTION_BWD_FILTER_ALGO_3’?
     int forward_algo = CUDNN_CONVOLUTION_FWD_PREFER_FASTEST;
                        ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
                        CUDNN_CONVOLUTION_BWD_FILTER_ALGO_3
compilation terminated due to -Wfatal-errors.
Makefile:142: recipe for target 'obj/convolutional_layer.o' failed
make: *** [obj/convolutional_layer.o] Error 1
mv: cannot stat 'libdarknet.so': No such file or directory
Darknet library has been compiled and saved

I followed some of the suggestion here but still doesn't work

dataplayer12 commented 2 years ago

Hi, yes there is an issue with compiling darknet on Jetson. Can you post the full log so I can take a look? Also, which Jetson and JetPack are you using and what scripts have you run up to this point?

FilippoRomeo commented 2 years ago

Hi, I am on AGX with Cuda 10.2, after running this darknet I got many errors of compilation due to different reasons like mismatched version of packages (e.g openCV), so I modified the compile_darknet.sh to:

#sudo apt-get update
#mkdir dpd
cd dpd
#git clone http://www.github.com/dataplayer12/darknet.git
cd darknet
make
mv libdarknet.so ../../human_detection/xavier/
cd ../../
#sudo rm -rf dpd
echo "Darknet library has been compiled and saved"

This allowed me to make some changes to files, followed this

dataplayer12 commented 2 years ago

Can you do a git checkout xavier before make? I tried to make darknet easy to compile on Jetsons but the darknet codebase keeps changing as do Jetpack versions which frequently break things. So compiling darknet is always a moving target that I as a maintainer must constantly keep up with. I haven't had the time to look at new changes in darknet since this project was published. Your best bet might be to google for something like 'compile darknet on JetPack 4.6' or whatever JetPack you are using. I still dont have the full log from your machine to understand what went wrong.

FilippoRomeo commented 2 years ago

So first I tested this repo and then this other and they works.

This is the first error that I had at first

g++ -std=c++11 -Iinclude/ -I3rdparty/stb/include -DOPENCV `pkg-config --cflags opencv` -DGPU -I/usr/local/cuda/include/ -DCUDNN -DCUDNN_HALF -Wall -Wfatal-errors -Wno-unused-result -Wno-unknown-pragmas -fPIC -Ofast -DOPENCV -fopenmp -DGPU -DCUDNN -I/usr/local/cudnn/include -DCUDNN_HALF -fPIC -c ./src/image_opencv.cpp -o obj/image_opencv.o
Package opencv was not found in the pkg-config search path.
Perhaps you should add the directory containing `opencv.pc'
to the PKG_CONFIG_PATH environment variable
No package 'opencv' found
./src/image_opencv.cpp:15:10: fatal error: opencv2/core/version.hpp: No such file or directory
 #include <opencv2/core/version.hpp>
          ^~~~~~~~~~~~~~~~~~~~~~~~~~
compilation terminated.
Makefile:149: recipe for target 'obj/image_opencv.o' failed
make: *** [obj/image_opencv.o] Error 1
mv: cannot stat 'libdarknet.so': No such file or directory
Darknet library has been compiled and saved

Which led me to this and fixed for the most, but then when I run sudo ./compile_darknet.sh this is what I got

chmod +x *.sh
gcc -Iinclude/ -I3rdparty/stb/include -DOPENCV `pkg-config --cflags opencv4` -DGPU -I/usr/local/cuda/include/ -DCUDNN -DCUDNN_HALF -Wall -Wfatal-errors -Wno-unused-result -Wno-unknown-pragmas -fPIC -Ofast -DOPENCV -fopenmp -DGPU -DCUDNN -I/usr/local/cudnn/include -DCUDNN_HALF -fPIC -c ./src/convolutional_layer.c -o obj/convolutional_layer.o
./src/convolutional_layer.c: In function ‘cudnn_convolutional_setup’:
./src/convolutional_layer.c:283:24: error: ‘CUDNN_CONVOLUTION_FWD_PREFER_FASTEST’ undeclared (first use in this function); did you mean ‘CUDNN_CONVOLUTION_BWD_FILTER_ALGO_3’?
     int forward_algo = CUDNN_CONVOLUTION_FWD_PREFER_FASTEST;
                        ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
                        CUDNN_CONVOLUTION_BWD_FILTER_ALGO_3
compilation terminated due to -Wfatal-errors.
Makefile:142: recipe for target 'obj/convolutional_layer.o' failed
make: *** [obj/convolutional_layer.o] Error 1
mv: cannot stat 'libdarknet.so': No such file or directory
Darknet library has been compiled and saved

The ./compile_darknet.sh has a git clone to this path

FilippoRomeo commented 2 years ago

I suggest updating the script for darknet to which the ./compile_darknet.sh is pointing. I tried with the original repo from AlexeyAB and after some adjustment worked with no problem which definitely needs to update some of the files like Makefile and image_opencv.cpp in order to work with the Xavier and the latest JetPack, OpenCV4, Cuda, the Nccv file location etc.