C++ Opencv Undefied Refrence contrib module - c++

I am getting the error Undefined refrence to cv::createFisherFaceRecognizer.
My header looks like this
#include "opencv2/core/core.hpp"
#include "opencv2/contrib/contrib.hpp"
#include "opencv2/imgproc/imgproc.hpp"
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/objdetect/objdetect.hpp"
#include <iostream>
#include <fstream>
#include <sstream>
The line that is causing the error is
Ptr<FaceRecognizer> model = createFisherFaceRecognizer();
I have also tried this with the same error
Ptr<FaceRecognizer> model = createFisherFaceRecognizer(0, DBL_MAX);
I'm compiling the program with:
g++ -L/usr/lib/uv4l/uv4lext/armv61 -luv4lext -Wl,-rpath,'/usr/lib/uv4l/uv4lext/armv6l' opencv_test.cpp -lopencv_core -lopencv_contrib -lopencv_imgproc -lopencv_objdetect -lopencv_highgui -o opencv_test
and I am getting the error:
opencv_test.cpp:(.text+0x5d8):undefined refrence to 'cv::createFisherFaceRecognizer(int,double)'
The strange thing is that the other libs seem to be linked fine so I don't know how just one library would be improperly linked.
This is running in on a raspberry pi using the raspbian distro
Thanks for any help.

After trying to figure out what was happening... I used apt-get remove to remove the contrib module and then re-installed it... I now believe that this was a symptom of a larger linking error because I have 2 different versions of opencv running on the same machine... In any event I hope this helps someone out.

Related

Compiler unable to link/find GLFW [duplicate]

This question already has answers here:
How do I link GLFW
(3 answers)
Closed 4 years ago.
I am trying to run a modified program that can be found at cpp-pointcloud.cpp. I am having difficulties getting it to build.
As it is now my file structure is:
-pointcloud.cpp
-librealsense/
-examples
-example.hpp
And I am building it with the command:
g++ -std=c++11 pointcloud.cpp -lrealsense -lopencv_core -lopencv_imgproc -lopencv_highgui -o ir
The imports of the pointcloud.cpp file are as follows:
// License: Apache 2.0. See LICENSE file in root directory.
// Copyright(c) 2015 Intel Corporation. All Rights Reserved.
#include <librealsense/rs.hpp>
#include <librealsense2/rs.hpp>
#include "librealsense/examples/example.hpp"
#include <chrono>
#include <vector>
#include <sstream>
#include <iostream>
#include <algorithm>
And they are:
#pragma once
#define GLFW_INCLUDE_GLU
#include <GLFW/glfw3.h>
#include <vector>
#include <string>
#include <sstream>
#include <iostream>
#include <algorithm>
In the example.hpp file.
My issue is that it cannot seem to find the glfw files. I get a bunch of errors like:
pointcloud.cpp:(.text+0xdf5): undefined reference to `glPopMatrix'
Which is bizarre to me as I'm confident that i've installed the GLFW3 package. And I believed that includes that use the angle brackets search for installed packages on your operating system.
I've ran this command successfully:
sudo apt-get install libglfw3 libglfw3-dev
I tried adding
#include <GLFW/glfw3.h>
to the pointcloud.cpp file but it actually gave me more errors!
I miss be misunderstanding something conceptually here, so if any of you could point me in the right direction that would be great thanks.
You have to link GLFW with pkg-config cf How do I link GLFW
$ gcc `pkg-config --cflags glfw3` -o foo foo.c `pkg-config --static --libs glfw3`
you can locate the libraries using locate or whereis ( update database before with sudo updatedb , https://unix.stackexchange.com/questions/194088/how-to-check-if-a-shared-library-is-installed ) or find ( /www.lifewire.com/uses-of-linux-command-find-2201100 ) i.e.
sudo updatedb ( may take some time ... )
locate libglfw
or
sudo find /usr/lib -name '*libglfw*'
possibly also check all dependencies required for libglfw using ldd

‘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

Compile error : fatal error: 'boost/numeric/ublas/matrix.hpp' file not found

These are the header files and libraries
#include <iostream>
#include <algorithm>
#include <stdio.h>
#include <math.h>
#include <vector>
#include <numeric>
#include <strings.h>
#include <assert.h>
#include <dirent.h>
#include <boost/numeric/ublas/matrix.hpp>
#include <boost/numeric/ublas/io.hpp>
#include <boost/geometry.hpp>
#include <boost/geometry/geometries/point_xy.hpp>
#include <boost/geometry/geometries/polygon.hpp>
#include <boost/geometry/geometries/adapted/c_array.hpp>
#include "mail.h"
I am trying to compile this c++ file I got using
g++ -O3 -DNDEBUG -o evaluate_object evaluate_object.cpp
The compile output
evaluate_object.cpp:13:10: fatal error: 'boost/numeric/ublas/matrix.hpp' file
not found
#include <boost/numeric/ublas/matrix.hpp>
^
1 error generated.
Ps: I run on macos sierra 10.12
I have tried install boost by these ways:
sudo port install boost
brew install boost
sudo port install boost +universal
But I still got the same problem.
I would be happy to get out of this noob zone.
I am a macos newbie too.
It seems that your "boost" includes directory is not present within environment defined include directories. You might want to specify one by passing "-I" argument to g++ command, i.e.
g++ -O3 -DNDEBUG -I/usr/local/Cellar/blahblah -o evaluate_object evaluate_object.cpp
Also your code is incomplete and perhaps if you actually call some of the boost functions you might need to add some objects for linking and then you will face "undefined reference to" error. To overcome such you need to specify "-L" flag for your g++ command.

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

Connecting Mongodb to C++ API #include problems

I got the mongoshell and Json file all set up. I need help connecting Mongodb to C++
I typed this in the command prompt but it gave a a syntax error. (my file name is ConnectorMain.cpp)
-I/usr/local/include -L/usr/local/lib -pthread -lmongoclient -lboost_thread-mt -lboost_filesystem -lboost_program_options -lboost_system app/ConnectorMain.cpp -o ConnectorMain
This person had the same problem: Mongo C++ Driver: mongo/client/dbclient.h: No such file or directory
The reason that there you need to type this in the cmd pmt is because it will allow you to access the weird #inclue files like: #include "mongo/client/dbclient.h"
I've visited http://api.mongodb.org/cplusplus/current/files.html
and this is the dbclient.h file
#pragma once
#ifdef MONGO_EXPOSE_MACROS
#error dbclient.h is for C++ driver consumer use only
#endif
#define LIBMONGOCLIENT_CONSUMER
#include "mongo/client/redef_macros.h"
#include "mongo/pch.h"
#include "mongo/client/connpool.h"
#include "mongo/client/dbclient_rs.h"
#include "mongo/client/dbclientcursor.h"
#include "mongo/client/dbclientinterface.h"
#include "mongo/client/gridfs.h"
#include "mongo/client/init.h"
#include "mongo/client/sasl_client_authenticate.h"
#include "mongo/client/syncclusterconnection.h"
#include "mongo/util/net/ssl_options.h"
#include "mongo/client/undef_macros.h"
and it is crazy cause of all the headers so I am trying to figure out how to hook this all up and as the forum says it has to do with setting up a -I or -L because it relates to this forum http://docs.mongodb.org/ecosystem/tutorial/getting-started-with-cpp-driver/#installing-the-driver-library-and-headers but that is in Linux.
Please help if you know how to do this. p.s. do I need to download boost and perl or something I saw that on another post. Anyways all the help is appreciated!