Ask Your Question
0

How to install xphoto from opencv_contrib [closed]

asked 2015-12-17 07:59:49 -0600

DrCrime gravatar image

updated 2015-12-18 08:57:59 -0600

Hi,

I want to use the cv::xphoto::balanceWhite() function in my code. However, I have some problems installing the library. So far I understood that I need opencv 3.0.0 combined with the opencv_contrib repository. To install these I followed mostly the instructions by Rodrigo Berriel and the README.md in the opencv_contrib repository.

The steps I performed where (my operating system is Ubuntu 14.04):

sudo apt-get -y install libopencv-dev build-essential cmake git libgtk2.0-dev pkg-config python-dev python-numpy libdc1394-22 libdc1394-22-dev libjpeg-dev libpng12-dev libtiff4-dev libjasper-dev libavcodec-dev libavformat-dev libswscale-dev libxine-dev libgstreamer0.10-dev libgstreamer-plugins-base0.10-dev libv4l-dev libtbb-dev libqt4-dev libfaac-dev libmp3lame-dev libopencore-amrnb-dev libopencore-amrwb-dev libtheora-dev libvorbis-dev libxvidcore-dev x264 v4l-utils unzip qt5-default libvtk6-dev zlib1g-dev libwebp-dev libpng-dev libtiff5-dev libopenexr-dev libgdal-dev libx264-dev yasm libxine2-dev libeigen3-dev python-tk python3-dev python3-tk python3-numpy ant default-jdk doxygen

These dependencies are probably more than I need. I combined the recommendations from several pages.

wget https://github.com/Itseez/opencv/archive/3.0.0.zip -O opencv-3.0.0.zip
git clone https://github.com/Itseez/opencv_contrib.git
unzip opencv-3.0.0.zip
cd opencv-3.0.0
mkdir -pv build
cd build

cmake -D CMAKE_BUILD_TYPE=RELEASE \
      -D OPENCV_EXTRA_MODULES_PATH=../../opencv_contrib/modules \
      -D CMAKE_INSTALL_PREFIX=/usr/local \
      -D WITH_TBB=ON \
      -D WITH_V4L=ON \
      -D WITH_QT=ON \
      -D WITH_OPENGL=ON \
      -D BUILD_opencv_ximgproc=OFF \
      -D BUILD_opencv_python2=OFF \
      -D BUILD_opencv_python3=OFF \
      ..

I removed ximgproc and python because these modules gave me some errors during configuration. However, I am only interested in xphoto anyway.

make -j 8
sudo make install
sudo /bin/bash -c 'echo "/usr/local/lib" > /etc/ld.so.conf.d/opencv.conf'
sudo ldconfig

This process goes through without any errors. Further, I can compile my opencv code that does not contain any contrib modules so far. But, as soon as I add a call to the following code, compilation fails.

#include "opencv2/xphoto.hpp"
#include "opencv2/imgproc.hpp"
#include "opencv2/highgui.hpp"
#include "opencv2/core/utility.hpp"
#include "opencv2/imgproc/types_c.h"
...
cv::Mat whiteBalanced;
cv::xphoto::balanceWhite(ImageOriginal, whiteBalanced, cv::xphoto::WHITE_BALANCE_SIMPLE);

I identified the problem so far, that the compiler (clang) does not find the include files. I searched my machine and only found them scattered in the opencv_contrib repository, but not installed in a common place like /usr/include.

So my assumption is that opencv got compiled and installed correctly, however the modules from the opencv_contrib repository where only compiled but not installed.

Is there a step missing or did I something wrong during the installation? How do you compile opencv together with the xphoto module?

Thank you very much.

supplement: If I compile with the options:

cmake -D CMAKE_BUILD_TYPE=RELEASE \
      -D OPENCV_EXTRA_MODULES_PATH=../../opencv_contrib/modules \
      -D CMAKE_INSTALL_PREFIX=/usr/local \
      -D WITH_TBB=ON \
      -D WITH_V4L=ON \
      -D WITH_QT=ON \
      -D WITH_OPENGL=ON \
      -D BUILD_opencv_ximgproc=ON \
      -D BUILD_opencv_python2=OFF \
      -D BUILD_opencv_python3=OFF \
      ..

I get the error:

[ 94%] Building CXX object modules/ximgproc/CMakeFiles/opencv_ximgproc.dir/src/sparse_match_interpolators.cpp.o
In file included from /home/mkreim/bin/opencv/opencv/opencv-3.0.0/modules/core/include/opencv2/core.hpp:54:0,
                 from /home/mkreim/bin/opencv ...
(more)
edit retag flag offensive reopen merge delete

Closed for the following reason the question is answered, right answer was accepted by berak
close date 2015-12-21 03:04:18.046312

Comments

if you disable the ximgproc module in cmake, the corresponding headers won't get copied with the install

what went wrong building ximgproc ?

berak gravatar imageberak ( 2015-12-17 08:08:15 -0600 )edit

I added the error message I get when I compile with ximgproc to the original post.

DrCrime gravatar imageDrCrime ( 2015-12-17 13:57:28 -0600 )edit

blunt guess : it's a synchronization problem. delete your build folder, update both opencv(trunk) and contrib, start from scratch.

berak gravatar imageberak ( 2015-12-17 14:02:16 -0600 )edit
1

Thanks a lot for your "blunt guess". I am using the opencv git repository now (instead of the stable relase zip file). I can compile opencv + modules now. However, when I try to link my own code I run into trouble. I documented everything in my original post as Supplement 2. Do you see the mistake in the linking process? Thanks in advance!

DrCrime gravatar imageDrCrime ( 2015-12-18 09:00:58 -0600 )edit
1

ah, this seems a faily easy one now:

//usr/local/lib/libopencv_imgcodecs.so.3.0: error adding symbols: DSO missing from command line

you're missing -lopencv_imgcodecs (needed for imread())

berak gravatar imageberak ( 2015-12-18 09:04:12 -0600 )edit

I have one further question: What is the common style in this forum for making edits to my posts? Should I keep adding supplements to my original question or should I rewrite the entire questions if I get new information from your answers? Thanks.

DrCrime gravatar imageDrCrime ( 2015-12-18 09:04:33 -0600 )edit

Thanks, that was really quite easy. However, that changes the problem to

main.o: In function `main':
main.cpp:294: undefined reference to `cv::xphoto::balanceWhite(cv::Mat const&, cv::Mat&, int, float, float, float, float)'
collect2: error: ld returned 1 exit status
make: *** [all] Error 1

But the compilation does work fine. Why does it not find the balanceWhite() function?

DrCrime gravatar imageDrCrime ( 2015-12-18 09:07:38 -0600 )edit

ah, just keep it the way it is. rewriting usually kills a lot of context (needed to understand comments)

did it work ?

berak gravatar imageberak ( 2015-12-18 09:08:58 -0600 )edit

oh, i missed that, it's -lopencv_xphoto (and it's the linker, which complains, not the compiler)

berak gravatar imageberak ( 2015-12-18 09:11:14 -0600 )edit
1

Thanks a lot. That worked.

DrCrime gravatar imageDrCrime ( 2015-12-21 02:49:47 -0600 )edit

1 answer

Sort by ยป oldest newest most voted
1

answered 2015-12-21 03:04:36 -0600

DrCrime gravatar image

updated 2015-12-21 03:06:38 -0600

Thanks to berak, I was able to install the current opencv library with the additional opencv_contrib repository on my Ubuntu 14.04 machine.

To build and install the library I performed the following steps:

sudo apt-get update
sudo apt-get upgrade
sudo apt-get -y install libopencv-dev build-essential cmake git libgtk2.0-dev pkg-config python-dev python-numpy libdc1394-22 libdc1394-22-dev libjpeg-dev libpng12-dev libtiff4-dev libjasper-dev libavcodec-dev libavformat-dev libswscale-dev libxine-dev libgstreamer0.10-dev libgstreamer-plugins-base0.10-dev libv4l-dev libtbb-dev libqt4-dev libfaac-dev libmp3lame-dev libopencore-amrnb-dev libopencore-amrwb-dev libtheora-dev libvorbis-dev libxvidcore-dev x264 v4l-utils unzip qt5-default libvtk6-dev zlib1g-dev libwebp-dev libpng-dev libtiff5-dev libopenexr-dev libgdal-dev libx264-dev yasm libxine2-dev libeigen3-dev python-tk python3-dev python3-tk python3-numpy ant default-jdk doxygen

mkdir -pv opencv
cd opencv

git clone https://github.com/Itseez/opencv.git
cd opencv/
git pull
cd ..

# opencv contrib
git clone https://github.com/Itseez/opencv_contrib.git
cd opencv_contrib/
git pull
cd ..

cd opencv/
mkdir -pv build
cd build

cmake -D CMAKE_BUILD_TYPE=RELEASE \
      -D OPENCV_EXTRA_MODULES_PATH=../../opencv_contrib/modules \
      -D CMAKE_INSTALL_PREFIX=/usr/local \
      -D WITH_TBB=ON \
      -D WITH_V4L=ON \
      -D WITH_QT=ON \
      -D WITH_OPENGL=ON \
      -D BUILD_opencv_ximgproc=ON \
      -D BUILD_opencv_python2=ON \
      -D BUILD_opencv_python3=OFF \
      ..

make
sudo make install
sudo /bin/bash -c 'echo "/usr/local/lib" > /etc/ld.so.conf.d/opencv.conf'
sudo ldconfig

These steps are from the install script by Rodrigo Berriel. I adapted them following the very helpful comments by berak.

After the installation I was able to build some C++ code calling the white balance function from xphoto:

cv::Mat whiteBalanced;
cv::xphoto::balanceWhite(ImageOriginal, whiteBalanced, cv::xphoto::WHITE_BALANCE_SIMPLE);

The code could be compiled:

g++ -g -O2 -W -Wall -Wextra -Werror -pedantic -std=c++11 -I/usr/local/include/ -c main.cpp

and linked:

g++ -W -Wall -Wextra -Werror -pedantic -std=c++11 -o Main.bin main.o -L/usr/local/lib/ -lopencv_calib3d -lopencv_contrib -lopencv_core -lopencv_features2d -lopencv_flann -lopencv_gpu -lopencv_highgui -lopencv_imgproc -lopencv_legacy -lopencv_ml -lopencv_objdetect -lopencv_ocl -lopencv_photo -lopencv_stitching -lopencv_superres -lopencv_ts -lopencv_video -lopencv_videostab -lopencv_imgcodecs -lopencv_xphoto

Thanks a lot for your help!

edit flag offensive delete link more

Comments

+1 for coming back with a writeup, what worked in the end, much appreciated !

berak gravatar imageberak ( 2015-12-21 03:06:08 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2015-12-17 07:59:49 -0600

Seen: 5,775 times

Last updated: Dec 21 '15