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.
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 want to compile opencv4.0 with Makefile but undefined reference error occur.
i have used to opencv in Windows and code is just simple code that only show image for test in ubuntu18.10.
but it work if i typing line below on shell.
g++ -o simple main.cpp $(pkg-config opencv4 --libs --cflags)
my Makefile is below
CC = g++
CFLAGS = -W -Wall
SRCS = main.cpp
TARGET = simple
OPENCV = $(pkg-config opencv4 --libs --cflags)
LIBS = $(OPENCV)
$(TARGET):$(SRCS)
$(CC) $(CFLAGS) -o $(TARGET) $(SRCS) $(LIBS)
clean:
rm -f $(OBJECTS) $(TARGET) core
and my opencv4.pc is below.
# 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.0.0
Libs: -L${exec_prefix}/lib -lopencv_gapi -lopencv_stitching -lopencv_aruco -lopencv_bgsegm -lopencv_b
Libs.private: -ldl -lm -lpthread -lrt -L/usr/lib/x86_64-linux-gnu -lGL -lGLU
Cflags: -I${includedir}
and error is below.
g++ -W -Wall -o simple main.cpp
/usr/bin/ld: /tmp/cciHsvhP.o: in function `main':
main.cpp:(.text+0x70): undefined reference to `cv::imread(cv::String const&, int)'
/usr/bin/ld: main.cpp:(.text+0xc4): undefined reference to `cv::imshow(cv::String const&, cv::_InputArray const&)'
....
collect2: error: ld returned 1 exit status
make: *** [Makefile:11: simple] Error 1
I assume you're using GNU Make, since you are working on Ubuntu Linux.
I also assume what you have posted as:
$(TARGET):$(SRCS)
$(CC) $(CFLAGS) -o $(TARGET) $(SRCS) $(LIBS)
is mis-formatted in the posting and that your Makefile really contains:
$(TARGET):$(SRCS)
(CC) $(CFLAGS) -o $(TARGET) $(SRCS) $(LIBS)
with the recipe command tab-indented as it must be.
In your Makefile you believe that:
OPENCV = $(pkg-config opencv4 --libs --cflags)
is a shell-expansion of the command pkg-config opencv4 --libs --cflags that
assigns the output of the command to the Make variable OPENCV. It is not.
It is simply a Make expansion of the string pkg-config opencv4 --libs --cflags,
just as in the next line:
LIBS = $(OPENCV)
$(OPENCV) is the Make expansion of the Make variable OPENCV and not the shell
expansion of a shell command OPENCV.
The string pkg-config opencv4 --libs --cflags is not a Make variable that has a value (obviously).
Neither can it be an invocation of a GNU Make-function
$(pkg-config ...), as there is no such GNU Make function.
So $(pkg-config opencv4 --libs --cflags) expands to nothing. Hence:
LIBS = $(OPENCV)
makes $(LIBS) expand to nothing, and:
$(CC) $(CFLAGS) -o $(TARGET) $(SRCS) $(LIBS)
expands to the same as:
$(CC) $(CFLAGS) -o $(TARGET) $(SRCS)
which is why the opencv libraries are missing from your linkage and the linkage fails.
To assign the output of a shell command to a Make variable, using the $(shell ...) function:
OPENCV := $(shell pkg-config opencv4 --libs --cflags)
Then $(OPENCV) and $(LIBS) will acquire the correct value.
BTW...
Note that your clean recipe attempts to delete a file, core, that is never created by your Makefile.
And..
Be aware that the recipe:
$(TARGET):$(SRCS)
(CC) $(CFLAGS) -o $(TARGET) $(SRCS) $(LIBS)
represents in general the most inefficient possible way of automating a
program's build process with Make, because it will recompile all of the N
source files in $(SRCS) whenever you change even 1 of them. In your particular
case as posted, it doesn't matter because N = 1. But when N = 1 there is no
need for Make. In anticipation of writing more professional projects where N is large, you
might like to work through Chapter 2 An Introduction to Makefiles,
at least, in the GNU Make manual.
This part of your makefile is likely broken:
$(TARGET):$(SRCS)
$(CC) $(CFLAGS) -o $(TARGET) $(SRCS) $(LIBS)
It looks like a leading tab character is missing on the second line.
It is not used, so make uses the default rule for building executables from .cpp files, which does not use the LIBS variable (only CFLAGS).
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
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();