When compiling demo OpenCV code, such as,
g++ HoughLines_Demo.cpp `pkg-config opencv --cflags --libs` -o HoughLines_Demo,
the compiler cannot find the header files:
HoughLines_Demo.cpp:7:33: fatal error: opencv2/imgcodecs.hpp: No such file or directory
#include "opencv2/imgcodecs.hpp"
^
If I downloaded opencv-3.0.0 correctly, these header files do exist on my computer already, right? If so, what do I need to do to link them correctly?
The exact error message:
Running:
Ubuntu 14.04,
g++-4.8,
4.8.4-2 ubuntu1~14.04
Update:
Looking up this problem more, the problem should be outdated OpenCV code. I ran pkg-config --modversion opencv which returned 2.4.8. I could have sworn I was running 3.0.0 . What is going on here?
Related
I need to use cv_bridge and transfer the images to vison wx. I am using makefile to link / compile. The problem I have is I don't know where the header files are for the opencv 3.2 libraries. This is on a Jetson Xavier, opencv 3.2 may have been installed by the SDK Manager, or I may have installed it later. Anyway, I just reinstalled it now using the command
sudo apt-get install --reinstall libopencv-core3.2
To identify the compiler and linker flags, I run the the two pkg-config commands
pkg-config --cflags cv_bridge
-I/opt/ros/melodic/include -I/usr/include/opencv -I/opt/ros/melodic/include
pkg-config --libs cv_bridge
-L/opt/ros/melodic/lib -lcv_bridge /usr/lib/aarch64-linux-gnu/libopencv_core.so.3.2.0 /usr/lib/aarch64-linux-gnu/libopencv_imgproc.so.3.2.0 /usr/lib/aarch64-linux-gnu/libopencv_imgcodecs.so.3.2.0 -lrosconsole -lrosconsole_log4cxx -lrosconsole_backend_interface /usr/lib/aarch64-linux-gnu/liblog4cxx.so /usr/lib/aarch64-linux-gnu/libboost_regex.so /usr/lib/aarch64-linux-gnu/libboost_system.so /usr/lib/aarch64-linux-gnu/libboost_thread.so /usr/lib/aarch64-linux-gnu/libboost_chrono.so /usr/lib/aarch64-linux-gnu/libboost_date_time.so /usr/lib/aarch64-linux-gnu/libboost_atomic.so /usr/lib/aarch64-linux-gnu/libpthread.so -lroscpp_serialization -lrostime /usr/lib/aarch64-linux-gnu/libboost_date_time.so /usr/lib/aarch64-linux-gnu/libboost_system.so /usr/lib/aarch64-linux-gnu/libboost_thread.so /usr/lib/aarch64-linux-gnu/libboost_chrono.so /usr/lib/aarch64-linux-gnu/libboost_atomic.so /usr/lib/aarch64-linux-gnu/libpthread.so -lcpp_common /usr/lib/aarch64-linux-gnu/libboost_system.so /usr/lib/aarch64-linux-gnu/libboost_thread.so /usr/lib/aarch64-linux-gnu/libboost_chrono.so /usr/lib/aarch64-linux-gnu/libboost_date_time.so /usr/lib/aarch64-linux-gnu/libboost_atomic.so /usr/lib/aarch64-linux-gnu/libpthread.so /usr/lib/aarch64-linux-gnu/libconsole_bridge.so.0.4
From the above output, there is a opencv core library at
ls /usr/lib/aarch64-linux-gnu/libopencv_core.so.3.2.0
/usr/lib/aarch64-linux-gnu/libopencv_core.so.3.2.0
The problem is I can't find the header files for opencv 3.2. From the output above, the header files should be in directory
-I/usr/include/opencv
In directory /usr/include/opencv, there is a subdirectory
/usr/include/opencv4/opencv2_orig/core/version.hpp
And that contains the version.hpp file which contains these lines showing the version is version is 4.1.1.
file: /usr/include/opencv4/opencv2_orig/core/version.hpp
#define CV_VERSION_MAJOR 4
#define CV_VERSION_MINOR 1
#define CV_VERSION_REVISION 1
So, how can I install the header files for opencv version 3.2, that go with cv_bridge? Also, there may be a ROS package solution to this question, that may be more appropriate since cv_bridge library is in /opt/ros/melodic/lib.
Hmmm I see there's no tag for cv-bridge. I think that means I'm in the wrong blog. Any suggestion where I should post this question?
Opencv 3.2 can be installed using the command below, and the header files are placed in /usr/include/opencv2. I believe what has occurred is opencv4 was installed, and at that time the header files for opencv 3.2 were removed.
sudo apt install libopencv-dev=3.2.0+dfsg-4ubuntu0.1
Here is an example of linking cpp code step_2 with rosbag, cv_bridge, and opencv (3.2). The include -I/opt/ros/melodic/include is not required, it is generated by the rosbag pkg-config command, but is included for clarity, to identify location of cv_bridge header.
g++ step_2.cpp -o step_2 `pkg-config --cflags --libs rosbag` \
-I/opt/ros/melodic/include \
-L/usr/lib/aarch64-linux-gnu/ -lopencv_core -lopencv_highgui \
-L/opt/ros/melodic/lib -lcv_bridge
ref ros perception
I want to use gcc in docker/singularity image to compile a program. Using local gcc, I use gcc tc.c -I PATH_TO_LIB without any error. To use the gcc in the image, I use the following command line.
singularity exec gcc_5.1.0.sif gcc tc.c -I PATH_TO_LIB
But the problem is that gcc cannot find the .h file in the library path. It returns the following error.
fatal error: csmith.h: No such file or directory
#include "csmith.h"
I have read the related questions but I cannot solve my problem.
I'm trying to compile a OpenCV C++ code on raspberry pi.
OpenCV requires cv.h to be included. When I try to compile I get:
"fatal error: cv.h: No such file or directory."
I have tried these:
g++ -c -Ihome/pi/OpenCV-2.3.1/include/opencv file.cpp
g++ -c -Ipi/OpenCV-2.3.1/include/opencv file.cpp
g++ -c -IOpenCV-2.3.1/include/opencv file.cpp
Do any of you have any ideas?
This is a general question and not related only to OpenCV.
For the general problem of including any header file
1. Try to see if the file is really at the included directory or no
2. Try to look for it in the folder
I am trying to build the OpenCV samples which come with the source package and I get the following:
CMake Error at CMakeLists.txt:10 (ocv_check_dependencies):
Unknown CMake command "ocv_check_dependencies".
I did install OpenCV using
cmake .
make
sudo make install
and I got a tutorial snippet working (thus I suppose it is installed correctly as a library). However, compiling the samples does not work.
I guess I have to somehow configure CMake to have “ocv_check_dependencies” - but how? I am lost!
Actually for OpenCV 2.4.4 beta the root CMakeList.txt file says:
OCV_OPTION(BUILD_EXAMPLES "Build all examples"
-DBUILD_EXAMPLES=ON worked just fine for me.
I got it.
In order to build the samples one has to change the default configuration for cmake by providing it via -D. What I did wrong was that I tried to execute cmake from within the samples directory.
The proper way to build the samples is invoking cmake like so (from within the root directory of the unpacked archive):
cmake -DBUILD_SAMPLES .
which will turn samples ON. One can proceed using make, make install than. The samples can be found in bin after building.
See also FAQ
How to compile OpenCV sample code ?
# For OpenCV 3
cd /path/to/opencv/samples/cpp/
#Compile
g++ -ggdb `pkg-config --cflags --libs opencv` facedetect.cpp -o facedetect
#run
./facedetect
Works for me.
googled from this link
mydragonisland's build instructions almost worked for me; with a minor reordering and including accents:
g++ facedetect.cpp -o facedetect `pkg-config --libs opencv`
The macro 'ocv_check_dependencies' is defined in: your_path_to/opencv/cmake/OpenCVModule.cmake
# ensures that all passed modules are available
# sets OCV_DEPENDENCIES_FOUND variable to TRUE/FALSE
macro(ocv_check_dependencies)
set(OCV_DEPENDENCIES_FOUND TRUE)
foreach(d ${ARGN})
if(d MATCHES "^opencv_[^ ]+$" AND NOT HAVE_${d})
set(OCV_DEPENDENCIES_FOUND FALSE)
break()
endif()
endforeach()
endmacro()
The top level CMakeLists.txt contains 'include' commands for files from opencv/cmake/ . Which is why the macro is available when you compile by calling cmake from the root of the opencv sources.
Reason
error message context:
CMake Error at CMakeLists.txt:10 (ocv_check_dependencies):
Unknown CMake command "ocv_check_dependencies".
This error message happens because cmake can't find the definition of ocv_check_dependencies
That's why the console said Unknown CMake command
Solution
If cmake cannot find where ocv_check_dependencies is defined
Just like #Nick Hockings Said:
ocv_check_dependencies is a macro defined in Your/OpenCV/path/OpenCVModule.cmake
macro(ocv_check_dependencies)
set(OCV_DEPENDENCIES_FOUND TRUE)
foreach(d ${ARGN})
if(d MATCHES "^opencv_[^ ]+$" AND NOT HAVE_${d})
set(OCV_DEPENDENCIES_FOUND FALSE)
break()
endif()
endforeach()
endmacro()
The fastest way is to copy this snippet above to your CMakeList.txt file right above where ocv_check_dependencies is
Therefore, cmake can finally understand what it is
That should do the trick, i hope no one else will bother with this question in the future
I got similar errors. My approach is as following:
1) cd xxx/samples 2) mkdir build 3) cd build 4) cmake .. 5) make
Now it works. We could not build individual project under their source files.
Following steps works for me.
Export toolchain path.
cd opencv-3.3.0/samples
cross_cmake &&
cross_make
cd opencv-3.3.0/samples/cpp/
I'm trying to compile simple OpenCV code on the BeagleBoard XM, running Ångström Linux.
I know my way in OpenCV, but only under Windows and Visual Studio. I'm fairly with non-Microsoft OSes.
I think I've installed OpenCV on the BeagleBoard (opkg install opencv, right?), and I've transferred my code, which for now look like this:
#include <opencv2/opencv.h>
int main()
{
cv::Mat img(100, 100, CV_8U);
cv::imshow("Hello world", img);
cv::waitkey();
return 0;
}
How can I compile this code under the BeagleBoard? How can I tell it where the .so files are? Where are the OpenCV .so files?
Have a look at ECE597 OpenCV on the BeagleBoard for installation instructions.
If you have installed it properly, then open a terminal window and browse to the folder where you have put the code. Once there, use the following command to compile the code in file "main.cpp"
g++ main.cpp -o out `pkg-config --cflags --libs opencv`
After the code is compiled, use the following command to execute it.
./out
Also look at the answers to Stack Overflow question How to install OpenCV on Ångström Linux?.
export LD_LIBRARY_PATH=/usr/local/lib
gcc `pkg-config --cflags opencv` -g -o NameOfProgram main.cpp `pkg-config --libs opencv`
Probably these commands should the work. Just don't forget to change the cpp filename if needed. See this.