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.
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
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?
I am making a program on raspberry pi and it uses opencv and mysql. they both compile fine when I compile them separately. but after i combine the 2 files I cannot compile them.
I could compile my opencv part using
g++ $(pkg-config --libs --cflags opencv) cv.cpp -o cv -I/home/pi/git/robidouille/raspicam_cv -L/home/pi/git/robidouille/raspicam_cv -lraspicamcv -L/home/pi/git/raspberrypi/userland/build/lib -lmmal_core -lmmal -l mmal_util -lvcos -lbcm_host
without any problem and compile my mysql part using
g++ -w sql.cpp $(mysql_config --cflags) $(mysql_config --libs)
but after I merge the code and try to compile the merged code using
g++ $(pkg-config --libs --cflags opencv) merged.cpp -o merged $(mysql_config --cflags) $(mysql_config --libs) -I/home/pi/git/robidouille/raspicam_cv -L/home/pi/git/robidouille/raspicam_cv -lraspicamcv -L/home/pi/git/raspberrypi/userland/build/lib -lmmal_core -lmmal -l mmal_util -lvcos -lbcm_host
I get an error saying error: ‘conn’ does not name a type
here is my code for that section
MYSQL *conn;
conn = mysql_init(NULL); //error here
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 a tutorial on glib which uses GIOChannel. I'm using Ubuntu 11.04 (Natty Narwhal) with glib-2.30.2 (gtk+-3.2.3) and C code.
The code is from here:
http://library.developer.nokia.com/index.jsp?topic=/GUID-E35887BB-7E58-438C-AA27-97B2CDE7E069/GUID-817C43E8-9169-4750-818B-B431D138D71A.html
The program runs but I the contents of my source test file is not copied to the destination file. I'm not receiving any error or warning messages. The program just does nothing. What's wrong here?
Works now, I changed the line:
g_print("usage:<cp SOURCE> <DESTINATION>\n");
To:
g_print("usage: %s <SOURCE> <DESTINATION>\n", argv[0]);
Then compiled it using:
gcc -Wall $(pkg-config --cflags gio-2.0) -c io.c
gcc -Wall $(pkg-config --libs gio-20) -o io io.o
Run the program using: ./io io.c new_io.c