Using Eigen Library with OpenCV 2.3.1 - c++

I have trouble in using Eigen3 Library along with OpenCV application in C++.
I have installed Eigen3 library on my Ubuntu using the following command:
sudo apt-get install libeigen3-dev
I am able to compile and use sample Eigen3 applications (Eigen3 library is installed and it works) when I use the following command to compile.
g++ -I/usr/include/eigen3 Eig.cpp -o Eig
I want to use the installed Eigen library with OpenCV.
I compiled OpenCV source with following flags:
cmake -D WITH_TBB=ON -D BUILD_NEW_PYTHON_SUPPORT=ON -D WITH_V4L=OFF -D INSTALL_C_EXAMPLES=ON -D INSTALL_PYTHON_EXAMPLES=ON -D BUILD_EXAMPLES=ON USE_EIGEN=/usr/include/eigen3 ..
My OpenCV code includes the following headers and namespace:
#include <opencv2/core/core.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <assert.h>
#include <opencv2/core/eigen.hpp>
using namespace cv;
using namespace std;
using namespace Eigen;
However, when I normally compile OpenCV application, my compiler gives me the following error:
In file included from Read.cpp:6:
/usr/local/include/opencv2/core/eigen.hpp:54: error: expected ‘,’ or ‘...’ before ‘::’ token
/usr/local/include/opencv2/core/eigen.hpp: In function ‘void cv::eigen2cv(int)’:
/usr/local/include/opencv2/core/eigen.hpp:56: error: ‘src’ was not declared in this scope
/usr/local/include/opencv2/core/eigen.hpp:56: error: ‘Eigen’ is not a class or namespace
/usr/local/include/opencv2/core/eigen.hpp:60: error: ‘dst’ was not declared in this scope
/usr/local/include/opencv2/core/eigen.hpp:66: error: ‘dst’ was not declared in this scope
How do I solve this problem?

I just had to include
#include <Eigen/Dense>
before including OpenCV headers thats all. I compiled them by including the Eigen lib headers and OpenCV lib headers.

First i would double check that the eigen include directions are found.
You can use a CMakeList.txt to do so (and you should use the cmake functions to find headers and link to libraries instead of compiler flags)
Next you could try to remove the using namespaces
using namespace cv;
using namespace std;
using namespace Eigen;

Related

emscripten and boost library: how to compile existing project for webassembly?

I have an existing project written on C++ that I would like to compile for webassembly using emscripten. The code calls boost library:
#include <boost/program_options.hpp>
#include <iostream>
#include <string>
#include <exception>
#include <algorithm>
#include <iterator>
#include <boost/filesystem/fstream.hpp>
#include <boost/filesystem/exception.hpp>
#include <boost/filesystem/convenience.hpp>
#include <boost/thread/thread.hpp>
#include <boost/lexical_cast.hpp>
#include <boost/assign.hpp>
I have compiled the necessary parts of boost library using emscripten as static libraries and converted them from bc to a-files using emar. Now I'm trying to compile the project feeding the compiler with the precompiled libraries:
(part of Makefile)
C_OPTIONS= -O3 -DNDEBUG -g \
/home/hiisi/workspace/boost_libs/program_options/build/emscripten-1.38.38/release/link-static/threading-multi/libs/cmdline.bc.a \
/home/hiisi/workspace/boost_libs/program_options/build/emscripten-1.38.38/release/link-static/threading-multi/libs/config_file.bc.a \
/home/hiisi/workspace/boost_libs/program_options/build/emscripten-1.38.38/release/link-static/threading-multi/libs/convert.bc.a \
/home/hiisi/workspace/boost_libs/program_options/build/emscripten-1.38.38/release/link-static/threading-multi/libs/libboost_program_options.bc.a \
However make still complains on the very first occurrence of boost in the code:
main.cpp:1:10: fatal error: 'boost/program_options.hpp' file not found
#include <boost/program_options.hpp>
^~~~~~~~~~~~~~~~~~~~~~~~~~~
1 error generated.
shared:ERROR: compiler frontend failed to generate LLVM bitcode, halting
The question may sound little bit naive, but how do I correctly do this? The project compiles perfectly fine with g++, but not em++
All I had to do is to make sure that boost lib presents in emscripten include directory. In my case that was emsdk/fastcomp/emscripten/system/include/ I made a symlink to system' boost library there and everything worked like a charm.
You have to add the include directories to use boost.
That would be an argument that look like this:
... -I/home/hiisi/workspace/boost_libs/include ...

‘Mat’ was not declared in this scope opencv

I followed this guide to install openCV on Ubuntu:
https://docs.opencv.org/master/d7/d9f/tutorial_linux_install.html
When I try to execute the following program:
#include <opencv2/core/core.hpp>
#include <opencv2/imgcodecs.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#include <iostream>
#include <math.h>
#include <tiffio.h>
using namespace std;
int main(){
string imageName("images/400nm.tif");
TIFF* tif = TIFFOpen(imageName.c_str(), "r");
Mat image;
return 0;
}
I get the following error executing the command "g++ ssim.cpp -o ssim -ltiff":
ssim.cpp: In function ‘int main()’: ssim.cpp:19:3: error: ‘Mat’ was
not declared in this scope Mat image; ^~~ ssim.cpp:19:3: note:
suggested alternative: In file included from
/usr/local/include/opencv2/core.hpp:59:0,
from /usr/local/include/opencv2/core/core.hpp:48,
from ssim.cpp:2: /usr/local/include/opencv2/core/mat.hpp:771:18: note: ‘cv::Mat’
class CV_EXPORTS Mat
Does somebody know why I get this and how to solve it?
I'm new at using opencv and libtiff so I have no idea about what to do to solve...
It's not really necessary to build openCV from source. Try installing it with
sudo apt-get install libopencv-dev
and try to compile it again.
Also like you said in your comment, make sure you either use namespace cv or cv::Mat.
Using the command:
g++ ssim.cpp -o ssim -ltiff -lopencv_core -lopencv_highgui -lopencv_imgproc -lopencv_imgcodecs
I don't get compiler errors but when I try to execute the command ./ssim I get:
./ssim: error while loading shared libraries: libopencv_core.so.3.4: cannot open shared object file: No such file or directory

opencv2/core/eigen.hpp Eigen: does not name a type [duplicate]

I have trouble in using Eigen3 Library along with OpenCV application in C++.
I have installed Eigen3 library on my Ubuntu using the following command:
sudo apt-get install libeigen3-dev
I am able to compile and use sample Eigen3 applications (Eigen3 library is installed and it works) when I use the following command to compile.
g++ -I/usr/include/eigen3 Eig.cpp -o Eig
I want to use the installed Eigen library with OpenCV.
I compiled OpenCV source with following flags:
cmake -D WITH_TBB=ON -D BUILD_NEW_PYTHON_SUPPORT=ON -D WITH_V4L=OFF -D INSTALL_C_EXAMPLES=ON -D INSTALL_PYTHON_EXAMPLES=ON -D BUILD_EXAMPLES=ON USE_EIGEN=/usr/include/eigen3 ..
My OpenCV code includes the following headers and namespace:
#include <opencv2/core/core.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <assert.h>
#include <opencv2/core/eigen.hpp>
using namespace cv;
using namespace std;
using namespace Eigen;
However, when I normally compile OpenCV application, my compiler gives me the following error:
In file included from Read.cpp:6:
/usr/local/include/opencv2/core/eigen.hpp:54: error: expected ‘,’ or ‘...’ before ‘::’ token
/usr/local/include/opencv2/core/eigen.hpp: In function ‘void cv::eigen2cv(int)’:
/usr/local/include/opencv2/core/eigen.hpp:56: error: ‘src’ was not declared in this scope
/usr/local/include/opencv2/core/eigen.hpp:56: error: ‘Eigen’ is not a class or namespace
/usr/local/include/opencv2/core/eigen.hpp:60: error: ‘dst’ was not declared in this scope
/usr/local/include/opencv2/core/eigen.hpp:66: error: ‘dst’ was not declared in this scope
How do I solve this problem?
I just had to include
#include <Eigen/Dense>
before including OpenCV headers thats all. I compiled them by including the Eigen lib headers and OpenCV lib headers.
First i would double check that the eigen include directions are found.
You can use a CMakeList.txt to do so (and you should use the cmake functions to find headers and link to libraries instead of compiler flags)
Next you could try to remove the using namespaces
using namespace cv;
using namespace std;
using namespace Eigen;

Including dlib in Qt project

I am trying to add dlib library to my Qt5 project.
I've build dlib with gcc 4.9.3 using CMake without NO_GUI_SUPPORT (i.e. with GUI) and without ISO_CPP_ONLY. I've compiled it into shared library with CMAKE_INSTALL_PREFIX = my_qt_project_dir/dlib, installed and included it into my project:
# DLIB
INCLUDEPATH += $$PWD/dlib/include/
LIBS += -L$$PWD/dlib/lib/
LIBS += -ldlib
I am including this headers in code:
#include <dlib/image_processing.h>
#include <dlib/gui_widgets.h>
#include <dlib/image_io.h>
#include <dlib/dir_nav.h>
#include <dlib/opencv.h>
but during compilation get this errors
some of them:
/dlib/include/dlib/image_processing/../matrix/matrix_la.h:64:45: error: macro "sign" passed 2 arguments, but takes just 1
/dlib/include/dlib/image_processing/../matrix/matrix_math_functions.h:83:27: error: expected unqualified-id before 'const'
/dlib/include/dlib/image_processing/../matrix/matrix_la.h:1034:9: error: 'matrix' has not been declared
I am using CMake 3.3.1, QtCreator 3.4.2, Qt 5.4.2, gcc 4.9.3 running on gentoo 4.0.9.
How to deal with this?
Someone #defined the word "sign" and it's stomping on the code. Figure out what code creates the sign #define and #include it after other headers.

Tesseract-ocr, baseapi.h fatal error: platform.h file not found

I am working on engineering work on license plate recognition and therefore started from a simple code. Namely, I downloaded all the libraries or OpenCV, Tesseract and Leptonica but when you try to compile I have a problem with the file baseapi.h located in the library Tesseract.
Compiles the following command: g++ main.cpp -lopencv_core -lopencv_highgui -lopencv_imgproc -ltesseract
Error The compiled: tesseract-ocr/api/baseapi.h:27:22: fatal error: platform.h: No such file or directory
The beginning of my code:
#include <iostream>
#include "opencv2/imgproc/imgproc.hpp"
#include "opencv2/highgui/highgui.hpp"
#include "leptonica-1.69/src/allheaders.h"
#include "tesseract-ocr/api/baseapi.h"
using namespace std;
using namespace tesseract;
using namespace cv;
...
try to install dev packages
$ sudo apt install tesseract-ocr-dev
$ sudo apt install libleptonica-dev