I need to use OpenCV+FFMPEG in a Xeon Phi without root permission.
My environment is:
OpenCV version: 3.1.0
Host OS: Linux
Target OS: Phi Co-Processor
Compiler & CMake: ICC 15.0.2 & CMake 3.5.2 (installed in my home)
When I compile OpenCV with GCC in my home, it works fine. I compile with
cmake -D CMAKE_INSTALL_PREFIX=$HOME/lib/opencv-3.1.0 -D WITH_GTK=ON ..
all works fine by setting LD_CONFIG_PATH and PKG_CONFIG_PATH env variables od ffmpeg and opencv.
Now, i need to use my code in a PHi CoProcessor, so I compile my code with
icc -mmic -Wall -std=c++11 -DNO_DEFAULT_MAPPING -I /home/spm1407/lib/opencv-3.1.0/include/ -I /home/spm1501/fastflow/ -O3 -o farm farm.cpp -pthread -L/home/spm1407/lib/opencv-3.1.0/lib -lopencv_core -lopencv_highgui -lopencv_imgcodecs -lopencv_videoio -lopencv_video -lopencv_imgproc -lpthread
(Please ignore FastFlow)
Compiler returns
x86_64-k1om-linux-ld: skipping incompatible /home/spm1407/lib/opencv-3.1.0/lib/libopencv_core.so when searching for -lopencv_core
x86_64-k1om-linux-ld: cannot find -lopencv_core
x86_64-k1om-linux-ld: skipping incompatible /home/spm1407/lib/opencv-3.1.0/lib/libopencv_highgui.so when searching for -lopencv_highgui
x86_64-k1om-linux-ld: cannot find -lopencv_highgui
x86_64-k1om-linux-ld: skipping incompatible /home/spm1407/lib/opencv-3.1.0/lib/libopencv_imgcodecs.so when searching for -lopencv_imgcodecs
x86_64-k1om-linux-ld: cannot find -lopencv_imgcodecs
x86_64-k1om-linux-ld: skipping incompatible /home/spm1407/lib/opencv-3.1.0/lib/libopencv_videoio.so when searching for -lopencv_videoio
x86_64-k1om-linux-ld: cannot find -lopencv_videoio
x86_64-k1om-linux-ld: skipping incompatible /home/spm1407/lib/opencv-3.1.0/lib/libopencv_video.so when searching for -lopencv_video
x86_64-k1om-linux-ld: cannot find -lopencv_video
x86_64-k1om-linux-ld: skipping incompatible /home/spm1407/lib/opencv-3.1.0/lib/libopencv_imgproc.so when searching for -lopencv_imgproc
x86_64-k1om-linux-ld: cannot find -lopencv_imgproc
if i omit mmic flag, compiler works fine.
How can i resolve this issue? Any suggest?
Thanks.
Related
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/.
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
I try to compile some files from the opencv-2.4.8/apps/haarfinder but i get the following error:
ld: library not found for -llibtbb.dylib
Notice the double l in the filename.
I try to follow the tutorial here:
http://coding-robin.de/2013/07/22/train-your-own-opencv-haar-classifier.html
And in the comments i readed:
After many, many hours of pondering and looking around. I decided to
take it as a spelling error in some file so I decided to look into
opencv files and search for that "-llibtbb" and finally found it. I
corrected it to only "libtbb" and its finally working.
Sadly he didn't mention what file that was.
I tried with sublime 'Find in files' but i can't find it.
Can someone else take a look or help me in another way?
Like if i know where libtbb.dylib is stored i might be able to duplicate it and add the spelling error myself.
please help, i'm lost :)
Suppose libtbb.dylib is in /usr/local/lib/libtbb.dylib and opencv.pc is in /usr/local/lib/pkgconfig (The location may vary depending on where you install tbb and pkg-config)
Then edit /usr/local/lib/pkgconfig/opencv.pc, change -llibtbb.dylib to /usr/local/lib/libtbb.dylib
Old question, but I needed it, or rather I found this better solution - and this may help other searchers.
Follow the instructions in the github description, rather than that blog post: https://github.com/mrnugget/opencv-haar-classifier-training
This corrects the spelling error in the command line:
g++ `pkg-config --libs --cflags opencv | sed 's/libtbb\.dylib/tbb/'`\
-I. -o mergevec mergevec.cpp\
cvboost.cpp cvcommon.cpp cvsamples.cpp cvhaarclassifier.cpp\
cvhaartraining.cpp\
-lopencv_core -lopencv_calib3d -lopencv_imgproc -lopencv_highgui -lopencv_objdetect
I installed opencv 2.4.12 with tbb from homebrew on El Capitan, and then separately downloaded the source from github in order to compile mergevec and the s/libtbb\.dylib/tbb/ fix on its own still didn't help.
My fix was to add -L/usr/local/lib to the start of the g++ arguments as by default it wasn't searching for my homebrew libs. I also had to add cvsamplesoutput.cpp as mentioned in another answer to fix the following error:
Undefined symbols for architecture x86_64:
"IOutput::createOutput(char const*, IOutput::OutputType)", referenced from:
JpgDatasetGenerator::JpgDatasetGenerator(char const*) in cvhaartraining-8f5a1b.o
PngDatasetGenerator::PngDatasetGenerator(char const*) in cvhaartraining-8f5a1b.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
The final command that worked for me was:
g++ -L/usr/local/lib `pkg-config --libs --cflags opencv | sed 's/libtbb\.dylib/tbb/'`\
-I. -o mergevec mergevec.cpp cvboost.cpp cvcommon.cpp cvsamples.cpp\
cvhaarclassifier.cpp cvhaartraining.cpp cvsamplesoutput.cpp -lopencv_core\
-lopencv_calib3d -lopencv_imgproc -lopencv_highgui -lopencv_objdetect
If the libtbb.dylib file already exists like in my case in the /usr/local/lib folder then all you need to do is to run this command:
export DYLD_LIBRARY_PATH=/usr/local/lib
IOutput is an interface where their methods are declared at ioutput.h and must be implemented somewhere. I found out they were implemented at cvsamplesoutput.cpp so we just need ask gcc to compile that file. For that the correct command should be:
g++ `pkg-config --libs --cflags opencv | sed 's/libtbb\.dylib/tbb/' ` -I. -o mergevec mergevec.cpp cvboost.cpp cvcommon.cpp cvsamples.cpp cvhaarclassifier.cpp cvhaartraining.cpp cvsamplesoutput.cpp -lopencv_core -lopencv_calib3d -lopencv_imgproc -lopencv_highgui -lopencv_objdetect
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.
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.