Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Libcamera/RPI 64bit Example using Code Blocks with OpenCV files located in /opt/opencv-4.5.5 #3

Open
reshuler opened this issue Feb 21, 2022 · 7 comments

Comments

@reshuler
Copy link

Hi Qengineering,

I tried the Libcamera RPI 64bit example, but code blocks fails to located the OpenCV libraries. I updated the libraries paths in the project and verified that pkg_config could locate the opencv library files. Qt and the CLI work okay when compiling opencv code. I can compile the Librcamera opencv rpi bullseye 64 bit example via cli without any errors and the app runs.

I'm not sure why code blocks can't find the libraries even though the paths are updated in the project. I suspect that code blocks is not using pkg_config as expected and needed.

Can you recommend how to get code blocks to find the opencv libraries when the files are located in '/opt/ and not '/usr/local' [default location]?

I separated the Qt and OpenCV libraries files so that I can move the libraries to different RPIs and along with an application - main goal is minimum install over head and management.

Thanks for sharing great information on setting up RPIs for OpenCV, Qt, and other tools.

Thanks,
Robert

@Qengineering
Copy link
Owner

See side 22 in the first OpenCV example.
If it's not clear, please let me know.

@reshuler
Copy link
Author

Hi Qengineering,

I verified the setting were correct per slide 22, but the code blocks still can not find the libraries. Below are the error messages, and below is my 'GStreamter_RPi_64_Bullseye.cbp.

Thanks for the help,
Robert

||=== Build: Debug in GStreamer RPi 64 Bullseye (compiler: GNU GCC Compiler) ===|
/usr/bin/ld: obj/Debug/main.o||in function main':| /home/pi/opencv-dev/examples/main.cpp|31|undefined reference to cv::VideoCapture::VideoCapture(std::__cxx11::basic_string<char, std::char_traits, std::allocator > const&, int)'|
/usr/bin/ld: /home/pi/opencv-dev/examples/main.cpp|32|undefined reference to cv::VideoCapture::isOpened() const'| /usr/bin/ld: /home/pi/opencv-dev/examples/main.cpp|37|undefined reference to cv::namedWindow(std::__cxx11::basic_string<char, std::char_traits, std::allocator > const&, int)'|
/usr/bin/ld: /home/pi/opencv-dev/examples/main.cpp|38|undefined reference to cv::Mat::Mat()'| /usr/bin/ld: /home/pi/opencv-dev/examples/main.cpp|43|undefined reference to cv::VideoCapture::read(cv::_OutputArray const&)'|
/usr/bin/ld: /home/pi/opencv-dev/examples/main.cpp|48|undefined reference to cv::imshow(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, cv::_InputArray const&)'| /usr/bin/ld: /home/pi/opencv-dev/examples/main.cpp|50|undefined reference to cv::waitKey(int)'|
/usr/bin/ld: /home/pi/opencv-dev/examples/main.cpp|54|undefined reference to cv::VideoCapture::release()'| /usr/bin/ld: /home/pi/opencv-dev/examples/main.cpp|55|undefined reference to cv::destroyAllWindows()'|
/usr/bin/ld: /home/pi/opencv-dev/examples/main.cpp|38|undefined reference to cv::Mat::~Mat()'| /usr/bin/ld: /home/pi/opencv-dev/examples/main.cpp|31|undefined reference to cv::VideoCapture::~VideoCapture()'|
/usr/bin/ld: /home/pi/opencv-dev/examples/main.cpp|38|undefined reference to cv::Mat::~Mat()'| /usr/bin/ld: /home/pi/opencv-dev/examples/main.cpp|31|undefined reference to cv::VideoCapture::~VideoCapture()'|
||error: ld returned 1 exit status|
||=== Build failed: 14 error(s), 0 warning(s) (0 minute(s), 0 second(s)) ===|

<CodeBlocks_project_file>










































































</CodeBlocks_project_file>

@reshuler
Copy link
Author

GStreamer_RPi_64_Bullseye.cbp file attached.
GStreamer_RPi_64_Bullseye.cbp.txt

@Qengineering
Copy link
Owner

The rather unusual location of OpenCV (/opt/opencv-4.5.5) gives you these errors.
Looking at the linker option pkg-config --libs --cflags opencv4, you include all OpenCV libraries in one command.
Examining the opencv4.pc gives you (default location /usr/local/lib/pkgconfig) :

# Package Information for pkg-config

prefix=/usr/local
exec_prefix=${prefix}
libdir=${exec_prefix}/lib
includedir=${prefix}/include/opencv4

Name: OpenCV
Description: Open Source Computer Vision Library
Version: 4.5.4
Libs: -L${exec_prefix}/lib -lopencv_gapi -lopencv_stitching -lopencv_aruco -lopencv_barcode -lopencv_bgsegm -lopencv_bioinspired -lopencv_ccalib -lopencv_dnn_objdetect -lopencv_dnn_superres -lopencv_dpm -lopencv_face -lopencv_freetype -lopencv_fuzzy -lopencv_hdf -lopencv_hfs -lopencv_img_hash -lopencv_intensity_transform -lopencv_line_descriptor -lopencv_mcc -lopencv_quality -lopencv_rapid -lopencv_reg -lopencv_rgbd -lopencv_saliency -lopencv_stereo -lopencv_structured_light -lopencv_phase_unwrapping -lopencv_superres -lopencv_optflow -lopencv_surface_matching -lopencv_tracking -lopencv_highgui -lopencv_datasets -lopencv_text -lopencv_plot -lopencv_videostab -lopencv_videoio -lopencv_wechat_qrcode -lopencv_xfeatures2d -lopencv_shape -lopencv_ml -lopencv_ximgproc -lopencv_video -lopencv_xobjdetect -lopencv_objdetect -lopencv_calib3d -lopencv_imgcodecs -lopencv_features2d -lopencv_dnn -lopencv_flann -lopencv_xphoto -lopencv_photo -lopencv_imgproc -lopencv_core
Libs.private: -ldl -lm -lpthread -lrt
Cflags: -I${includedir}

The prefix /usr/local/ at the first line sets the whole chain at the wrong direction.
I don't know if replacing with /opt/opencv-4.5.5 will solve the issue.

One way to get the app running is by removing all OpenCV references in the build options, (the pkg-config --libs --cflags opencv4).
Next, search for the libopencv_core.so on your machine. /opt/opencv-4.5.5/lib/?
Finally, add manually all the needed libraries in your project. (Often one library depends on another; a whole chain)

@reshuler
Copy link
Author

contents of the opencv4.pc, which created during the opencv build.

Package Information for pkg-config

prefix=/opt/opencv-4.5.5
exec_prefix=${prefix}
libdir=${exec_prefix}/lib
includedir=${prefix}/include/opencv4

Name: OpenCV
Description: Open Source Computer Vision Library
Version: 4.5.5
Libs: -L${exec_prefix}/lib -lopencv_gapi -lopencv_stitching -lopencv_aruco -lopencv_barcode -lopencv_bgsegm -lopencv_bioinspired -lopencv_ccalib -lopencv_dnn_objdetect -lopencv_dnn_superres -lopencv_dpm -lopencv_face -lopencv_freetype -lopencv_fuzzy -lopencv_hdf -lopencv_hfs -lopencv_img_hash -lopencv_intensity_transform -lopencv_line_descriptor -lopencv_mcc -lopencv_quality -lopencv_rapid -lopencv_reg -lopencv_rgbd -lopencv_saliency -lopencv_stereo -lopencv_structured_light -lopencv_phase_unwrapping -lopencv_superres -lopencv_optflow -lopencv_surface_matching -lopencv_tracking -lopencv_highgui -lopencv_datasets -lopencv_text -lopencv_plot -lopencv_videostab -lopencv_videoio -lopencv_wechat_qrcode -lopencv_xfeatures2d -lopencv_shape -lopencv_ml -lopencv_ximgproc -lopencv_video -lopencv_xobjdetect -lopencv_objdetect -lopencv_calib3d -lopencv_imgcodecs -lopencv_features2d -lopencv_dnn -lopencv_flann -lopencv_xphoto -lopencv_photo -lopencv_imgproc -lopencv_core
Libs.private: -ldl -lm -lpthread -lrt
Cflags: -I${includedir}

@reshuler
Copy link
Author

Odd that it works okay with Qt and from the command line.

Command Line compile command:
g++ main.cpp -o main pkg-config --cflags --libs opencv4

@reshuler
Copy link
Author

HI Qengineering,

I added all the of the opencv libxxx.so files to Code Blocks and the example built. I guess code blocks is not using pkg_config.

Thanks for the help,
Robert

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants