craycc and OpenCV - 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.

Related

Compile OpenCV code with icc and mmic flag

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.

ld: library not found for -llibtbb.dylib

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

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.

How do I link the library containing 'pyrUp' for opencv?

I've been compiling and linking opencv code successfully for the past few days with the following command:
g++ motion.cpp -o motion `pkg-config --cflags --libs opencv`
But I have recently added a call to the pyrUp() function:
pyrUp( in, out, Size( 640,480 ) );
Now when I compile I get the following linker error:
motion.cpp:(.text+0x1385): undefined reference to `cv::pyrUp(cv::_InputArray const&, cv::_OutputArray const&, cv::Size_<int> const&, int)'
collect2: ld returned 1 exit status
What am I missing? Is there an alternative function I should be using? I thought I was already linking in all of the opencv libraries.
As i understand it the pkg-config(REF) loads a config file from here /usr/local/lib/pkgconfig/opencv.pc which contains a number of settings.
You may have to add the specific lib that contains pyrup on to the end of this line
Libs: -L${libdir} -lopencv_core -lopencv_imgproc -lopencv_highgui
-lopencv_ml -lopencv_video -lopencv_features2d -lopencv_calib3d -lopencv_objdetect -lopencv_contrib -lopencv_legacy -lopencv_flann
The opencv.pc file may also reside in a different folder from that listed above.
It may also be that your using a version of openCV that doesn't come with a precompiled library. In which case you would have to add the source of the .cpp file for this function as an argument. I'm not actually sure how to do this as i use an ID and not the command line.
What am I missing?
You are putting libraries at the beginning of your link line, which is wrong. Move them to the end instead.

opencv 2.4 SIFT compile error

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();

Resources