On Ubuntu 14.4 with OpenCV 3.1.0 :
I'm trying to compile and run this file http://docs.opencv.org/3.0-last-rst/_downloads/facerec_fisherfaces.cpp
but I don't know what to write in the compile.sh file to make it executable
I found this compile.sh but it doesn't work :
LIBS="-lopencv_imgproc -lopencv_highgui -lopencv_core -lopencv_objdetect"
g++ -I/usr/local/include/opencv -I/usr/local/include/opencv2 -L/usr/lib -L/usr/local/lib -fpic -Wall -c "untitled.cpp" $LIBS
g++ -shared -I/usr/local/include/opencv -I/usr/local/include/opencv2 -o libuntitled.so untitled.o -L/usr/local/lib $LIBS
g++ -I/usr/local/include/opencv -I/usr/local/include/opencv2 -o untitled untitled.o -L/usr/local/lib $LIBS
exit 0
A good answer for my own question :)
you'll need to rebuild opencv with opencv_contrib (please see readme there for build instructions).
please see 3.1 docs http://docs.opencv.org/ref/master/tutorial_face_main.html#gsc.tab=0, not the old 3.0 ones
LIBS="-lopencv_imgproc -lopencv_imgcodecs -lopencv_highgui -lopencv_core -lopencv_objdetect -lopencv_face"
the old 2.4 samples won't run as-is, please have a look at the current https://github.com/Itseez/opencv_contrib/tree/master/modules/face/samples
Related
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>
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'm new to Opencv version 3.1.0 and trying to compile the code of facerec_fisherfaces.cpp http://docs.opencv.org/3.0-last-rst/_downloads/facerec_fisherfaces.cpp
using this compile.sh file
LIBS="-lopencv_imgproc -lopencv_highgui -lopencv_core -lopencv_objdetect -lopencv_contrib"
g++ -I/usr/local/include/opencv -I/usr/local/include/opencv2 -L/usr/lib -L/usr/local/lib -fpic -Wall -c "untitled.cpp" $LIBS
g++ -shared -I/usr/local/include/opencv -I/usr/local/include/opencv2 -o libuntitled.so untitled.o -L/usr/local/lib $LIBS
g++ -I/usr/local/include/opencv -I/usr/local/include/opencv2 -o untitled untitled.o -L/usr/local/lib $LIBS
exit 0
the error in the terminal is :
No such file or directory
#include "opencv2/face.hpp"
A proper answer to my question :)
you need to download so extra modules from :
https://github.com/Itseez/opencv_contrib
I'm writing a basic example of opencv, but make command give me message
g++-4.7.real: error: pkg-config --cflags opencv: No such file or directory
g++-4.7.real: error: pkg-config --libs opencv: No such file or directory
issue command pkg-config --cflag opencv give me result as:
-I/usr/local/include/opencv -I/usr/local/include
and pkg-config --libs opencv give me:
-I/usr/local/include/opencv -I/usr/local/include
vudao#vudaopc:~/work/nmath/ntrainer$ pkg-config --libs opencv
/usr/local/lib/libopencv_contrib.a /usr/local/lib/libopencv_stitching.a /usr/local/lib/libopencv_nonfree.a /usr/local/lib/libopencv_superres.a /usr/local/lib/libopencv_ocl.a /usr/local/lib/libopencv_ts.a /usr/local/lib/libopencv_videostab.a /usr/local/lib/libopencv_gpu.a /usr/local/lib/libopencv_photo.a /usr/local/lib/libopencv_objdetect.a /usr/local/lib/libopencv_legacy.a /usr/local/lib/libopencv_video.a /usr/local/lib/libopencv_ml.a /usr/local/lib/libopencv_calib3d.a /usr/local/lib/libopencv_features2d.a /usr/local/lib/libopencv_highgui.a /usr/local/share/OpenCV/3rdparty/lib/libIlmImf.a /usr/local/share/OpenCV/3rdparty/lib/liblibjasper.a /usr/local/share/OpenCV/3rdparty/lib/liblibtiff.a /usr/local/lib/libopencv_imgproc.a /usr/local/lib/libopencv_flann.a /usr/local/lib/libopencv_core.a /usr/lib/i386-linux-gnu/libbz2.so /usr/lib/i386-linux-gnu/libpng.so /usr/lib/i386-linux-gnu/libjpeg.so /usr/lib/i386-linux-gnu/libz.so -lswscale -lavformat -lavutil -lz -lSDL -lasound -lavcodec -lgthread-2.0 -lglib-2.0 -lgobject-2.0 -lfontconfig -lfreetype -lpango-1.0 -lcairo -lgdk_pixbuf-2.0 -lpangocairo-1.0 -lpangoft2-1.0 -lgio-2.0 -latk-1.0 -lgdk-x11-2.0 -lgtk-x11-2.0 -lrt -lpthread -lm -ldl -lstdc++
Below is my Makefile:
CC=g++
CFLAGS=-O2 -g 'pkg-config --cflags opencv'
LDFLAGS='pkg-config --libs opencv'
BIN=ntrainer
ntrainer : ntrainer.cpp
$(CC) $(CFLAGS) $(LDFLAGS) -o $(BIN) ntrainer.cpp
My system is Ubuntu 12.10. I have installed opencv-2.4.7 successfully (I think) following instructions here http://www.samontab.com/web/2011/06/installing-opencv-2-2-in-ubuntu-11-04/
I also have configured and exported PKG_CONFIG_PATH into /etc/bash.bashrc, I'v also ran ldconfig
Please someone tell me what I'm missing? And how to correct it.
Thanks too much.
You used incorrect quotes. You should use ` instead of ':
CC=g++
CFLAGS=-O2 -g `pkg-config --cflags opencv`
LDFLAGS=`pkg-config --libs opencv`
For me, the file was there but the path was wrong:
I had to look for the opencv.pc file, make sure it is in the path for the pkgconfig program to find (i.e. in one of the pkgconfig folders) and then make sure the prefix path in there is right.
In my case it was wrong because it was not installed via make install but i made a make package package because it was cross-compiled, and the path I had installed it at didn't match the CMAKE path.
running
pkg-config --cflags opencv
or
pkg-config --libs opencv
tells you where it is looking for the files, so you can make sure they match.
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.