opencv 2.4 SIFT compile error - opencv

openCV has changed feature detectors/descriptors (as usually) with new version. I've already found, that I need to add
#include "opencv2/nonfree/nonfree.hpp"
#include "opencv2/nonfree/features2d.hpp"
however, it still doesn`t work. The error I get is:
error: ‘cv::SIFT::DetectorParams’ has not been declare
I use standard command for building
gcc `pkg-config --cflags --libs opencv` -o descriptorExtractor main.cpp
and all the libraries, etc. should be linked correctly
pkg-config --cflags --libs opencv
-I/opt/ros/fuerte/include/opencv -I/opt/ros/fuerte/include -L/opt/ros/fuerte/lib -lopencv_calib3d -lopencv_contrib -lopencv_core -lopencv_features2d -lopencv_flann -lopencv_gpu -lopencv_highgui -lopencv_imgproc -lopencv_legacy -lopencv_ml -lopencv_nonfree -lopencv_objdetect -lopencv_photo -lopencv_stitching -lopencv_ts -lopencv_video -lopencv_videostab
What's wrong with openCV again? Please, don't ask me why do I need SIFT from openCV and not from some other software or binary, I just need it...

I do not remember it well... but I think the issue was that I didn't use
cv::initModule_nonfree();

Related

Why do I get an error when compiling opencv code with make even if the particular missing files exist?

I've got the following makefile:
OBJS:= main.o
CV_LIBS:= -I/usr/local/include/opencv4 -I/usr/local/include -L/usr/local/lib/ -lopencv_core -lopencv_imgproc -lopencv_highgui -lopencv_ml -lopencv_video -lopencv_features2d -lopencv_calib3d -lopencv_objdetect -lopencv_contrib -lopencv_legacy -lopencv_flann
main: $(OBJS)
g++ $(OBJS) $(CV_LIBS) -O3 -ffast-math -o main -Wall -g
main.o: main.h
g++ -c main.cpp -Wall -g
My main.h file has the following line:
#include <opencv4/opencv2/objdetect.hpp>
I get the following error:
/usr/local/include/opencv4/opencv2/objdetect.hpp:47:10: fatal error: opencv2/core.hpp: No such file or directory
47 | #include "opencv2/core.hpp"
I have tried the following as well with no luck:
#include <opencv2/objdetect.hpp>
Error:
main.h:4:10: fatal error: opencv2/objdetect.hpp: No such file or directory
I can confirm there is an objdetect.hpp in both:
/usr/local/include/opencv4/opencv2/ and
/usr/local/include/opencv4/opencv2/objdetect.hpp
I have looked at this question, but unfortunately I'm not using cmake. What am I doing wrong? Many thanks.
If you look at the compile line that make prints out (which you didn't include in your question), it's pretty straightforward why you get this error.
The compile line, that compiles main.c into main.o, looks like this:
g++ -c main.cpp -Wall -g
You can clearly see that there is no reference to the directories you need to include header files here.
Your makefile has this:
CV_LIBS:= -I/usr/local/include/opencv4 -I/usr/local/include -L/usr/local/lib/ -lopencv_core -lopencv_imgproc -lopencv_highgui -lopencv_ml -lopencv_video -lopencv_features2d -lopencv_calib3d -lopencv_objdetect -lopencv_contrib -lopencv_legacy -lopencv_flann
where you are combining compiler flags, such as -I, with linker flags, such as -L and -l in the same variable, calling them all "LIBS", and adding them only to the link line.
You need to put the compiler flags into the compile command, and the linker flags into the link command:
CPPFLAGS = -I/usr/local/include/opencv4 -I/usr/local/include
CV_LIBS = -L/usr/local/lib/ -lopencv_core -lopencv_imgproc -lopencv_highgui -lopencv_ml -lopencv_video -lopencv_features2d -lopencv_calib3d -lopencv_objdetect -lopencv_contrib -lopencv_legacy -lopencv_flann
main: $(OBJS)
g++ $(OBJS) $(CV_LIBS) -O3 -ffast-math -o main -Wall -g
main.o: main.h
g++ $(CPPFLAGS) -c main.cpp -Wall -g
FYI, it's more correct for you to use #include <opencv2/objdetect.hpp> in your source code, not #include <opencv4/opencv2/objdetect.hpp>

"opencv2: no such file or directory" while trying to build Darknet?

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/.

Trying to compile character_recognition.cpp from opencv_contrib samples

I've just installed opencv 3.2 and tesseract module. Now I'm tryng to compile the character_recognition.cpp sample in the opencv_contrib folder. If I use the command pkg-config --cflags --libs opencv it displays
-I/usr/local/include/opencv -I/usr/local/include -L/usr/local/lib -lopencv_stitching -lopencv_superres -lopencv_videostab -lopencv_aruco -lopencv_bgsegm -lopencv_bioinspired -lopencv_ccalib -lopencv_dpm -lopencv_freetype -lopencv_fuzzy -lopencv_line_descriptor -lopencv_optflow -lopencv_reg -lopencv_saliency -lopencv_stereo -lopencv_structured_light -lopencv_phase_unwrapping -lopencv_rgbd -lopencv_surface_matching -lopencv_tracking -lopencv_datasets -lopencv_text -lopencv_face -lopencv_plot -lopencv_dnn -lopencv_xfeatures2d -lopencv_shape -lopencv_video -lopencv_ximgproc -lopencv_calib3d -lopencv_features2d -lopencv_flann -lopencv_xobjdetect -lopencv_objdetect -lopencv_ml -lopencv_xphoto -lopencv_highgui -lopencv_videoio -lopencv_imgcodecs -lopencv_photo -lopencv_imgproc -lopencv_core
But if I try to compile che cpp file
g++ -ggdb `pkg-config --cflags --libs opencv` character_recognition.cpp -o character_recognition
it says me that cv::imread(cv::String const&, int) it's not defined and this kind of error for every function of the opencv libraries that is used in the code.
Seems thats I can't link the libraries. Can you help me?

compiling embedded axis camera software using opencv. Make file changes

I am developing and embed application for an axis camera. I would like to use opencv with my project. Currently, after running create-package.sh artpec-4, I received errors that it was skipping incompatible libraries, then it stooped once it couldn't find he first library that was incompatible. I looked up this issue and one solution is to compile opencv using the new architecture. If I included the source code for opencv in my project I think it could work. This would most likely be the best solution, because I don't know if I could get opencv installed on the camera.
I have downloaded the opencv source files at
http://sourceforge.net/projects/opencvlibrary/files/opencv-unix/2.4.6.1/opencv-2.4.6.1.tar.gz/download
essentially, I would like to know what files I will need from that .rar, where I should put them, and how to change the makefile to compile it all into a usable application.
here is my current main makefile
AXIS_USABLE_LIBS = UCLIBC GLIBC
include $(AXIS_TOP_DIR)/tools/build/Rules.axis
PROGS = myapp
CFLAGS += -Wall -g -O2
#CFLAGS += -I/usr/include/opencv -I/usr/include/opencv2
#LIBS += -L/usr/lib -lopencv_core -lopencv_imgproc -lopencv_highgui -lopencv_ml -lopencv_video -lopencv_features2d -lopencv_calib3d -lopencv_objdetect -lopencv_contrib -lopencv_legacy -lopencv_flann
LDFLAGS += -lnet_http -lcapture
ifneq ($(AXIS_OPT_DEBUG),y)
ifneq ($(AXIS_OPT_STATIC),y)
# Strip the binaries when building unless debug or static
# $(CXX) $(LDFLAGS) $^ $(LDLIBS) -o $# `pkg-config --cflags --libs opencv`
LDFLAGS += -s
endif
endif
SRCS = myapp.cpp
OBJS = $(SRCS:.cpp=.o)
all: $(PROGS)
$(PROGS): $(OBJS)
$(CXX) $^ -o $# $(LDFLAGS) $(LDLIBS) -L/usr/lib -lopencv_core -lopencv_imgproc -lopencv_calib3d -lopencv_video -lopencv_features2d -lopencv_ml -lopencv_highgui -lopencv_objdetect -lopencv_contrib -lopencv_legacy
$(OBJS) : $(GENERATED_H)
# Install the package on the camera
install: $(PROGS)
create-package.sh
install-onto-target.sh
clean:
rm -f $(PROGS) *.o core
You will need core and highgui modules then (libopencv_core, libopencv_highgui).
Check modules/highgui/include/opencv2/highgui.hpp and modules/highgui/src/cap.cpp. In the second one there are procedures for most of functions You are looking for. The similar named functions are connected with fact, that OpenCV uses other libraries for video streams. If You are not going to use image processing capabilities of OpenCV it might be a better idea to take a look at libraries specialised in image/video reading and writing.

craycc and OpenCV

I'm trying to compile a simple hello world type program that reads an image file with OpenCv while MPI is initialised using. It works fine with gcc (mpicc), but I'm trying to use craycc for reasons I won't get into. When I do this, I get an errors that all the libraries are not found. It seems to be looking in a strange path.
Can anyone take some guesses at what's happening here? Could my pkg-config opencv.pc file be giving the wrong path? Is the typedef error triggering this (when I find the line and comment it out the warning disappears by the missing libraries remain)?
I'll try sleeping on it and see what comes up. Thanks for taking the time to read this folks, and I'll be sure to report back if I find anything.
#hector-xe6-7:~/work/disparity> cc `pkg-config --cflags --libs opencv` hello.c -o hello
CC-301 craycc: WARNING File = /home/d34/d34/s1138832/work/OpenCV-2.3/include/opencv2/core/types_c.h, Line = 159
The indicated "typedef" name has already been declared (with same type).
typedef unsigned short ushort;
^
Total warnings detected in hello.c: 1
/opt/cray/cce/8.0.4/cray-binutils/x86_64-unknown-linux-gnu/bin/ld: cannot find -lopencv_core
/opt/cray/cce/8.0.4/cray-binutils/x86_64-unknown-linux-gnu/bin/ld: cannot find -lopencv_imgproc
/opt/cray/cce/8.0.4/cray-binutils/x86_64-unknown-linux-gnu/bin/ld: cannot find -lopencv_highgui
/opt/cray/cce/8.0.4/cray-binutils/x86_64-unknown-linux-gnu/bin/ld: cannot find -lopencv_ml
/opt/cray/cce/8.0.4/cray-binutils/x86_64-unknown-linux-gnu/bin/ld: cannot find -lopencv_video
/opt/cray/cce/8.0.4/cray-binutils/x86_64-unknown-linux-gnu/bin/ld: cannot find -lopencv_features2d
/opt/cray/cce/8.0.4/cray-binutils/x86_64-unknown-linux-gnu/bin/ld: cannot find -lopencv_calib3d
/opt/cray/cce/8.0.4/cray-binutils/x86_64-unknown-linux-gnu/bin/ld: cannot find -lopencv_objdetect
/opt/cray/cce/8.0.4/cray-binutils/x86_64-unknown-linux-gnu/bin/ld: cannot find -lopencv_contrib
/opt/cray/cce/8.0.4/cray-binutils/x86_64-unknown-linux-gnu/bin/ld: cannot find -lopencv_legacy
/opt/cray/cce/8.0.4/cray-binutils/x86_64-unknown-linux-gnu/bin/ld: cannot find -lopencv_flann
Solved this by adding a -dynamic flag when compiling.

Resources