redefinition of class when I use calib3d.hpp in opencv - c++

I am working on ubuntu 16.4 in a C++ project and I'm trying to use a function in opencv2/calib3d.hpp but without any success.
I don't have any problem using cv::Point3d for example, but as soon as I add , I get the following error:
/usr/local/include/opencv2/features2d/features2d.hpp:69: error:
redefinition of ‘class cv::KeyPoint’ class CV_EXPORTS_W_SIMPLE
KeyPoint
Here is my code :
#include <iostream>
#include <opencv2/core.hpp>
#include <opencv2/calib3d.hpp>
int main()
{
std::cout << "cv hello"<< std::endl;
return 0;
}
When I use " pkg-config --modversion opencv " to have the version of opencv used I get "3.1.0"
My idea is that I have several version of opencv installed and conflicting.
I am thinking that because in the proposition of completion, when I am adding
#include , I have several equivalent calib3d.hpp propositions.
How can I know if I have multiple version installed ?

Not sure if this is to much effort, but you could specify the OpenCV version with Cmake.
find_package(OpenCV 3.2 REQUIRED PATHS "/path/to/OCV3.2/install/dir/")
Check this answer from #gabriel-devillers:
https://stackoverflow.com/a/45752688/10889595

Related

Cannot create FisherFaceRecognizer with OpenCV 4 (C++)

I'm following an older tutorial on face recognition based on OpenCV in C++ and have an error I can't resolve. The relevant code snippet:
#include "opencv2/core/core.hpp"
#include "opencv2/face.hpp"
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/imgproc/imgproc.hpp"
#include "opencv2/objdetect/objdetect.hpp"
...
Ptr<face::FaceRecognizer> model = face::createFisherFaceRecognizer();
model->train(images, labels);
...
I have my OpenCV compiled correctly with contrib modules, have them included but it still gives the error:
error: 'createFisherFaceRecognizer()' is not a member of 'cv::face'
I also trief this one:
Ptr<face::FaceRecognizer> model = face::FisherFaceRecognizer_create();
error: 'FisherFaceRecognizer_create()' is not a member of 'cv::face'
I looked up the face.hpp, ad the class has a function 'create', so I tried to use it, but this also failed:
Ptr<face::FaceRecognizer> model = face::FisherFaceRecognizer.create();
error: expected primary-expression before '.' token
which is weird since the function has parameters with default values. All the online solutions I treid failed. What was changed in the newer OpenCV versions and how can I create a face recognizer object correctly?
According to the official document,
Ptr<FaceRecognizer> createFisherFaceRecognizer(int num_components=0, double threshold=DBL_MAX)
is used openCV2. Since you use openCV 4, you have to follow the documentation that works with openCV 4.
Try this:
static Ptr<FisherFaceRecognizer> cv::face::FisherFaceRecognizer::create (int num_components = 0, double threshold = DBL_MAX )
On the top of this page, you can adjust the version of openCV library which you have.

Getting error including eigen library in c++

I am trying to use eigen for linear algebra but can't get it to include the eigen library. It keeps on giving me an error even though I am following all the instructions to include the eigen folder while compiling the program. I have tried this in both visual studio 2017 and the MinGW version of gcc. I am giving the relevant part of my code and what I am doing to include the Eigen library.
#include <iostream>
#include <fstream>
using namespace std;
#include <Eigen/Dense>
using Eigen::MatrixXd;
int main()
{
MatrixXd m(2,2);
m(0,0) = 3;
m(1,0) = 2.5;
m(0,1) = -1;
m(1,1) = m(1,0) + m(0,1);
std::cout << m << std::endl;
}
To run this in g++, I am using the command
g++ -I /C:\Users\aqils\Documents\C++\Eigen/ Matrixbasics.cpp -o Matrixbasics.exe
Here C:\Users\aqils\Documents\C++\Eigen
is the path for the unzipped Eigen package.
Matrixbasics.cpp is the name of the c++ file and it's located in the folder
C:\Users\aqils\Documents\C++
The error I get is
"Fatal error: Eigen/Dense: no such file or directory"
To run this in Visual Studio 2017, I have followed these steps to add a folder to a project:
1. Right click on the project name in the solution explorer and hit properties
2. Then look for c++ and find the option for adding a folder.
3. Select the Eigen package folder in the tree view, hit ok and then apply.
4. Run the program. It should now work.
I have spent several frustrating days trying to make this work and have read all related questions on stack overflow as well as several other websites. The answers don't go beyond the above instructions which I am already following. Will be really grateful if someone can help me fix the problem.
You can replace this line:
#include <Eigen/Dense>
by:
#include <eigen3/Eigen/Dense>

OpenCV on C++/Namespace issue?

I am new to C++ so I get some trouble to use openCV on my C++ project. I'm using Xcode as an IDE.
So I used brew to install opencv using the two command lines:
brew install opencv3 --with-ffmpeg --with-tbb --with-contrib
brew reinstall opencv3 --HEAD --with-python3 --with-ffmpeg --with-tbb --with-contrib
I checked the path to add to my project to load the library using recursivity, so I added on Xcode the path for header path and library:
/usr/local/Cellar/**
I also tried to install it another way, but still got the same issue:
brew install opencv
And adding the path to:
/usr/local/include/**
Everything seems to work since the library is detected, but import is not working because I got namespace errors in the openCV files, for instance:
No type named 'unique_ptr' in namespace 'std'
No member named 'allocator_traits' in namespace 'std'; did you mean 'allocator_arg_t'?
I checked on the internet and maybe it should be due to the the C++ language dialect or standard library, but I use GNU ++ 14 and libc++ . From what I found it should be working in that config, but I still got the issues. Do you have any ideas ?
EDIT: I don't even try to use it yet, I just used the include and print an hello:
#include <iostream>
#include "cv.h"
int main(int argc, char *argv[]){
std::cout<<"hello";
}
I also tried cv.hpp instead of cv.h, still not working
Thanks a lot !
I don't think you are using the correct #include paths, if you look at the OpenCV Example, you need the following for OpenCV 3.0 to open an image:
#include <opencv2/core/core.hpp>
#include <opencv2/imgcodecs.hpp>
#include <opencv2/highgui/highgui.hpp>
None of these are like the headers that you have, which are likely for older versions.
This tutorial looks like a very sensible one to get up and running with xcode, and the example at the bottom looks like a better start

Using Caffe in C++; Unable to pass caffe::SolverParameter to function without error

I am attempting to compile the "Hello World XOR" C++ example given by:
https://medium.com/#shiyan/caffe-c-helloworld-example-with-memorydata-input-20c692a82a22
Hardware:
EX50-UD3R Motherboard
GT-640 NVidia cards (2 Cards)
Intel 980 (6 core)
16Gig (4x4) DDR3 RAM
Environment:
Ubuntu 16.04.2 LTS Kernel: 4.4.0-78-generic
Eclipse Neon3 R4.6.3
CUDA 8.0
Caffe: whatever ver I downloaded from Berkley on 06/04/2017
I followed the installation instructions for installing Caffe in Ubuntu 16.04: https://github.com/BVLC/caffe/wiki/Ubuntu-16.04-or-15.10-Installation-Guide
and all the make commands succeeded.
However when I try to use the libraries in a simple cpp program:
#include <memory>
#include <cstdlib> // Provides NULL, rand, size_t;
#include <stdio.h> // For printf
#include <cstring> // For string
#include "/home/caffe-master/include/caffe/layers/memory_data_layer.hpp"
#include "/home/caffe-master-path>/include/caffe/caffe.hpp"
void blah( caffe::SolverParameter *sp);
int main()
{
... standard c++ code to generate random data deleted for brevity...
caffe::SolverParameter solver_param; // No errors given here for this declaration
blah( solver_param); // Simple function created to test error, same error appears here
caffe::ReadSolverParamsFromTextFileOrDie( path, &solver_param); // Actual function from XOR example, same error
caffe::ReadSolverParamsFromTextFileOrDie("./solver.prototxt", &solver_param); // This also gives same error
boost::shared_ptr<caffe::Solver<float> > solver(caffe::SolverRegistry<float>::CreateSolver(solver_param)); // Same error here
... code that would of passed random data to caffe deleted ...
return 0;
}
void blah( caffe::SolverParameter *sp)
{
std::cout << "BLAH: " << sp->rms_decay_;
return;
}
In Eclipse Neon I get the following error for any line that includes the variable solver_param including the lines that where I created the simple function blah which takes one argument of type caffe::SolverParameter *
Invalid arguments 'Candidates are:
void ReadSolverParamsFromTextFileOrDie(const std::__cxx11::basic_string,std::allocator> &, ? *)' caffe_hellow.cpp /caffe line 47 Semantic Error
I tried setting the full paths in the include path and that got rid of some errors, I added the libpath in eclipse to include caffe and boost and that got rid of more errors leaving only this one for now. I've been searching for a solution, looking at the .hpp caffe files to try to understand them and trying different settings in eclipse to get rid of this error but nothing works. Casting did not work either.
For some reason it does not recognize any variable declared as type SolverParameter as a compatible argument to a function that requires it. The error message gives "? *" as the argument type. What does that mean? Can you help? Thank you.
You need to include
#include "caffe/proto/caffe.pb.h"
For all caffe.proto related declarations
I am able to compile now. It is a consequence of being a noob at using IDE.
I had to add the libraries in Project->Properties->GCC C++ Linker-> Libraries (-l):
caffe
boost_system
glog
... and this may not be needed ... cuda
I also needed to add -L paths for the above. Then I needed to update either /etc/environment or .bashrc to include the paths for caffe and cuda in the LD_LIBRARY_PATH variable otherwise I would get an unable t link binary error. Again cuda may not be needed to solve this error the other three sure are. I plan to use Cuda-C to access the GPU processors. Thank you Shai for your response on the protoc item it lead me to the other comments on including libraries.

How to properly include Armadillo in CLion (without having false errors)?

When I use the header-only Armadillo C++ library in CLion, the IDE indicates (highlights) multiple (false) errors in the code, however the usage of Armadillo is valid and the code builds and runs without any errors.
For example, in a very simple Armadillo test project, the IDE indicates 3 errors, as written in the comments:
#include <iostream>
#include "armadillo"
using namespace std;
using namespace arma;
int main() {
cout << "Armadillo version: " << arma_version::as_string() << endl;
// Returns 5.0.1 (Ankle Biter)
mat A(2,3); // Error: Too many arguments, expected 0
A.fill(99);
A(1,2) += 101.0; // Error: Called object is not a function
A.print("A = ");
A.set_size(4,5); // Error: Too many arguments, expected 1
A.fill(77);
A.print("A = ");
return 0;
}
Since Armadillo is header-only, I did not modify the default CMakeLists.txt file, only included the main header in main.cpp and copied armadillo_bits to the project directory.
I've tried to configure Armadillo with CMake, but on Windows it seems Armadillo's bundled CMakeLists.txt just copies the includes and creates a config.hpp in my working dir.
Is there a way to index symbols in header-only libraries?
CLion version is 1.0 (141.353), Armadillo version is 5.0.1.
My platform is Windows 8.1 x64, and I'm using MinGW v64 4.9.2 (x86_64-4.9.2-win32-seh-rt_v4-rev2)
The CLion project is available in this repository.
Thanks to anyone trying to investigate this issue.