I am trying to do Compiling With OpenCV section in this page: Installing Darknet
After I did OPENCV = 1, I tried to do re-make, so I did make in the darknet directory.
The directory is below.
(yolo) bash-3.2$ pwd
/Users/moray/darknet
(yolo) bash-3.2$ ls
LICENSE LICENSE.gpl LICENSE.v1 backup data libdarknet.a python src
LICENSE.fuck LICENSE.meta Makefile cfg examples libdarknet.so results
LICENSE.gen LICENSE.mit README.md darknet include obj scripts
and the result of the re-makaing is here.
(yolo) bash-3.2$ make
g++ -Iinclude/ -Isrc/ -DOPENCV `pkg-config --cflags opencv` -Wall -Wno-unused-result -Wno-unknown-pragmas -Wfatal-errors -fPIC -Ofast -DOPENCV -c ./src/image_opencv.cpp -o obj/image_opencv.o
/bin/sh: pkg-config: command not found
./src/image_opencv.cpp:6:10: fatal error: 'opencv2/opencv.hpp' file not found
#include "opencv2/opencv.hpp"
^~~~~~~~~~~~~~~~~~~~
1 error generated.
make: *** [obj/image_opencv.o] Error 1
So I thought include path could not reference opencv.hpp, I looked for the file and found it.
(yolo) bash-3.2$ ls ~/opt/anaconda3/pkgs/libopencv-3.4.2-h7c891bd_1/include/opencv2/opencv.hpp
/Users/moray/opt/anaconda3/pkgs/libopencv-3.4.2-h7c891bd_1/include/opencv2/opencv.hpp
Therefore I tried to change #include "opencv2/opencv.hpp" to "include "~/opt/anaconda3/pkgs/libopencv-3.4.2-h7c891bd_1/include/opencv2/opencv.hpp" in ./src/image_opencv.cpp
And the result is here.
(yolo) bash-3.2$ make
g++ -Iinclude/ -Isrc/ -DOPENCV `pkg-config --cflags opencv` -Wall -Wno-unused-result -Wno-unknown-pragmas -Wfatal-errors -fPIC -Ofast -DOPENCV -c ./src/image_opencv.cpp -o obj/image_opencv.o
/bin/sh: pkg-config: command not found
./src/image_opencv.cpp:7:10: fatal error:
'~/opt/anaconda3/pkgs/libopencv-3.4.2-h7c891bd_1/include/opencv2/opencv.hpp' file not found
#include "~/opt/anaconda3/pkgs/libopencv-3.4.2-h7c891bd_1/include/opencv2/opencv.hpp"
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1 error generated.
make: *** [obj/image_opencv.o] Error 1
I cannot understand why the error happens.
Please tell me your think.
============================================
os: macOS Catalina 10.15.1
(yolo) is a virtual environment in anaconda(3)
opencv was installed by pip command in (yolo)
all the packages by pip command in (yolo):
(yolo) bash-3.2$ pip list
Package Version
--------------------- -------------------
certifi 2019.11.28
numpy 1.17.4
opencv-contrib-python 4.1.2.30
opencv-python 4.1.1.26
pip 19.3.1
setuptools 42.0.2.post20191203
wheel 0.33.6
gcc:
(yolo) bash-3.2$ gcc --version
Configured with: --prefix=/Library/Developer/CommandLineTools/usr --with-gxx-include-dir=/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/c++/4.2.1
Apple clang version 11.0.0 (clang-1100.0.33.12)
Target: x86_64-apple-darwin19.0.0
Thread model: posix
InstalledDir: /Library/Developer/CommandLineTools/usr/bin
This error explains it pkg-config: command not found. In order to use OpenCV in YOLO, you have to install OpenCV that works for C or C++ program, not Python. You probably installed opencv using pip for Python. Follow these steps in one of these links to install opencv : this or this or other tutorial.
After that, to check whether you have installed OpenCV correctly and can be used in C program, run this command :
pkg-config --modversion opencv
If it doesn't show anything or shows wrong version, try to reinstall OpenCV OR it is possible that your machine doesn't locate opencv version correctly.
So add command to your ~/.bashrc for example :
vim ~/.bashrc
export PKG_CONFIG_PATH=/home/user/installation/OpenCV-3.4.0/lib/pkgconfig
source ~/.bashrc
Notes : Change the path according to your opencv installation directory that contains opencv.pc
Related
I am trying to use Darkent with OpenCV and CUDA. I installed darknet according to these instructions:
https://pjreddie.com/darknet/install/
I installed CUDA according to these instructions:
https://docs.nvidia.com/cuda/cuda-installation-guide-linux/index.html
Finally, I installed OpenCV according to these instructions:
http://www.linuxfromscratch.org/blfs/view/svn/general/opencv.html
I then added the following lines to the end of my bashrc:
export PATH=/usr/local/cuda-11.1/bin${PATH:+:${PATH}}
export LD_LIBRARY_PATH=/usr/local/cuda-11.1/lib64${LD_LIBRARY_PATH:+:${LD_LIBRARY_PATH}}
export PKG_CONFIG_PATH=/usr/local/lib/pkgconfig${PKG_CONFIG_PATH:+:${PKG_CONFIG_PATH}}
Next, I modified the Makefile in the darknet directory such that GPU=1, and OPENCV=1. I remade, and ran into a bunch of repeated errors saying:
No package 'opencv' found
gcc -Iinclude/ -Isrc/ -DOPENCV `pkg-config --cflags opencv` -DGPU -I/usr/local/cuda/include/ -Wall -Wno-unused-result -Wno-unknown-pragmas -Wfatal-errors -fPIC -Ofast -DOPENCV -DGPU -c ./src/lstm_layer.c -o obj/lstm_layer.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
I checked, and although I had added the directory "/usr/local/lib/pkgconfig" to my PKG_CONFIG_PATH, there was no opencv.pc file there. I googled this, and read an answer that suggested to create the file manually, so this is what I did, with the following content:
prefix=/usr
exec_prefix=${prefix}
includedir=${prefix}/include
libdir=${exec_prefix}/lib
Name: opencv
Description: The opencv library
Version: 2.x.x
Cflags: -I${includedir}/opencv -I${includedir}/opencv2
Libs: -L${libdir} -lopencv_calib3d -lopencv_imgproc -lopencv_contrib -lopencv_legacy -l
This solved the repeating error mentioned above, but I am still getting a similar error when I make:
./src/image_opencv.cpp:5:10: fatal error: opencv2/opencv.hpp: No such file or directory
5 | #include "opencv2/opencv.hpp"
| ^~~~~~~~~~~~~~~~~~~~
compilation terminated.
I'm not sure if I fixed the first issue, and this is a separate one, or if the first fix just fixed a symptom, and not the problem. Since then, I also tried:
sudo apt install libopencv-dev
to no effect.
pkg-config --modversion
produces: 2.x.x
pkg-config --cflags opencv
produces:
[code]
-I/usr/include/opencv -I/usr/include/opencv2
[/code]
Any help would be greatly appreciated. I am running ubuntu 20.04, kernel 5.4.0-53-generic.
I tried this and it worked, create opencv.pc file with these contents:
# Package Information for pkg-config
prefix=/usr
exec_prefix=${prefix}
libdir=${prefix}/lib/x86_64-linux-gnu
includedir_new=${prefix}/include/opencv4
Name: OpenCV
Description: Open Source Computer Vision Library
Version: 4.5.0
Libs: -L${libdir} -lopencv_dnn -lopencv_ml -lopencv_objdetect -lopencv_shape -lopencv_stitching -lopencv_superres -lopencv_videostab -lopencv_calib3d -lopencv_features2d -lopencv_highgui -lopencv_videoio -lopencv_imgcodecs -lopencv_video -lopencv_photo -lopencv_imgproc -lopencv_flann -lopencv_core
Libs.private: -ldl -lm -lpthread -lrt
Cflags: -I${includedir_new}
and place it in /usr/local/lib/pkgconfig/.
I want to install an OpenCV version locally on OSX in a folder without overwriting the old installation that I need for an old executable.
I followed [these instructions][1], particularly the Building OpenCV from Source Using CMake, Using the Command Line section.
So basically I:
downloaded the source code with git and now it is in the subfolder openCV
Created a new directory cmake_bin_dir
Entered in cmake_bin_dir and created another subdirectory instDir
From the cmake_bin_dir I launched the command cmake -D CMAKE_BUILD_TYPE=DEBUG -D CMAKE_INSTALL_PREFIX=/my/home/Downloads/openCVProject/cmake_bin_dir/instDir/ ../openCV/
From the same directory I launched first make and then sudo make install. This created the *.dylib files in the cmake_bin_dir/instDir directory.
To test the installation I created my project directory (at the same level of cmake_bin_dir.
I tried to compile the file named test.cpp with the command:
g++ -std=c++11 -I../cmake_bin_dir/ -I../openCV/include -I../openCV/modules/core/include/ \
-I../openCV/modules/calib3d/include/ -I../openCV/modules/features2d/include \
-I../openCV/modules/flann/include -I../openCV/modules/dnn/include -I../openCV/modules/highgui/include/ \
-I../openCV/modules/imgcodecs/include -I../openCV/modules/videoio/include -I../openCV/modules/imgproc/include \
-I../openCV/modules/ml/include -I../openCV/modules/objdetect/include -I../openCV/modules/photo/include \
-I../openCV/modules/shape/include -I../openCV/modules/stitching/include -I../openCV/modules/superres/include \
-I../openCV/modules/video/include -I../openCV/modules/videostab/include test.cpp -o test.o
I added the include one by one because I got compilation error each time.
However now I getting a linkage error:
Undefined symbols for architecture x86_64:
"cv::String::deallocate()", referenced from:
cv::String::~String() in test-afd12e.o
cv::String::operator=(cv::String const&) in test-afd12e.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
So my question is how can I compile my program and other projects using the local installation of the OpenCV library?
[1]: https://docs.opencv.org/2.4/doc/tutorials/introduction/linux_install/linux_install.html
Ok I found my error. If anybody will have the same problem try to execute this on terminal:
export DYLD_LIBRARY_PATH=../your/path/lib/:$DYLD_LIBRARY_PATH
In my case the I executed:
export DYLD_LIBRARY_PATH=../cmake_bin_dir/lib/:$DYLD_LIBRARY_PATH
I also created a Makefile with the following content:
CPP = g++ -std=c++11
# OpenCV trunk
CPPFLAGS = -L../cmake_bin_dir/lib/ \
-I../cmake_bin_dir/include \
-I../cmake_bin_dir/ -I../openCV/include -I../openCV/modules/core/include/ \
-I../openCV/modules/calib3d/include/ \
-I../openCV/modules/features2d/include \
-I../openCV/modules/flann/include -I../openCV/modules/dnn/include -I../openCV/modules/highgui/include/ \
-I../openCV/modules/imgcodecs/include -I../openCV/modules/videoio/include -I../openCV/modules/imgproc/include \
-I../openCV/modules/ml/include -I../openCV/modules/objdetect/include -I../openCV/modules/photo/include \
-I../openCV/modules/shape/include -I../openCV/modules/stitching/include -I../openCV/modules/superres/include \
-I../openCV/modules/video/include -I../openCV/modules/videostab/include \
`pkg-config --cflags --libs ../cmake_bin_dir/instDir/lib/pkgconfig/opencv.pc`
# Opencv 2.4.8
#CPPFLAGS = -L/home/krystof/libs/opencv-2.4.8/release/installed/libs \
-I/home/krystof/libs/opencv-2.4.8/release/installed/include
all: test
test: test.cpp
$(CPP) $(CPPFLAGS) $^ -o $#
Now executing make should build the program with the local openCV version.
Ld build/Release-iphoneos/Demo.app/Demo normal arm64
cd /Users/meitu/Desktop/Demo3
export IPHONEO _ DEPLOYMENT _ TARGET=11.0
you have to install the debug version of OpenCV 3.3.
If you use cmake follow the instruction given by
https://docs.opencv.org/2.4/doc/tutorials/introduction/linux_gcc_cmake/linux_gcc_cmake.html
For integration into a makefile under linux you can use the useful commands
pkg-config --cflags opencv
pkg-config --libs opencv
in your Makefile.
Maybe you must compile openCV by yourself setting the debug option.
After installing opencv3 on my OSX,I run this command
g++ -ggdb `pkg-config --cflags --libs opencv` facedetect.cpp -o /tmp/test && /tmp/test
I got this error
ld: library not found for -lippicv
clang: error: linker command failed with exit code 1 (use -v to see invocation)
If you're compiling with Mac OSX, I ran into the same problem and found a solution here, under "Install OpenCV 3 on Mac OSX with brew", "Troubleshooting":
# Find ippicv
find /usr/local -name "libippicv.a"
# For me it is /usr/local/Cellar/opencv3/3.1.0_3/share/OpenCV/3rdparty/lib/libippicv.a
# Make a symlink to /usr/local/lib
ln -s /some/path/OpenCV/3rdparty/lib/libippicv.a /usr/local/lib/
# I used
ln -s /usr/local/Cellar/opencv3/3.1.0_3/share/OpenCV/3rdparty/lib/libippicv.a /usr/local/lib/
Running setup.py bdist_wheel for gnureadline
Error:
DHAVE_RL_CALLBACK -DHAVE_RL_CATCH_SIGNAL -DHAVE_RL_COMPLETION_APPEND_CHARACTER -DHAVE_RL_COMPLETION_DISPLAY_MATCHES_HOOK -DHAVE_RL_COMPLETION_MATCHES -DHAVE_RL_COMPLETION_SUPPRESS_APPEND -DHAVE_RL_PRE_INPUT_HOOK -I. -I/usr/include/python2.7 -c Modules/2.x/readline.c -o build/temp.linux-x86_64-2.7/Modules/2.x/readline.o
In file included from Modules/2.x/readline.c:31:0:
./readline/readline.h:385:1: warning: function declaration isn’t a prototype [-Wstrict-prototypes]
gcc -pthread -shared -Wl,-O1 -Wl,-Bsymbolic-functions -Wl,-z,relro build/temp.linux-x86_64-2.7/Modules/2.x/readline.o readline/libreadline.a readline/libhistory.a -lncurses -o build/lib.linux-x86_64-2.7/gnureadline.so
/usr/bin/ld: cannot find -lncurses
collect2: error: ld returned 1 exit status
error: command 'gcc' failed with exit status 1
Mange Jenkins settings:
Python : CPython-2.7
Path: /usr/bin/python
The problem was gnureadline was in my requirements.txt and when building the virtual environments and installing requirements it could not install the package.
gnureadline isn't required on most OSes. As Ludwig points out in this post:
gnureadline [is only needed] on platforms that don't provide readline
at all, or that substitute readline for an incompatible product like
libedit (i.e. Mac OS X)
So the solution was simply to remove gnureadline from requirements.txt