OpenCV and convexityDefects - c++

So i am really new to openCV and all the image recognition stuff. So i use monodevelop and i installed OpenCV using apt-getand i included these files
include "opencv2/highgui/highgui.hpp"
include "opencv2/imgproc/imgproc.hpp"
include <opencv2/opencv.hpp>
include <opencv2/imgproc/imgproc.hpp>
include<iostream>
include<vector>
include<algorithm>
include <X11/Xlib.h>
include <X11/Xutil.h>
but this function convexityDefects() shows as undefined
EDIT
So the problem is that the compiler shows that function convexityDefects is not defined in this scope
Here is the full code that i cant get to work -> Code
Could you please point me out!?
Thank you.

So i found the answer i was looking for.....
The libraries i used to compile my project where in wrong location.
so i used pkg-config --libs --cflags opencv to find exactly where are my libs....
After that i included these libraries in Code-Blocks and everything magicly started to work.

Related

openCV libraries call local path that does not exist

i am making a simple c++ program with openCV library included. Eclipse IDE recognises openCV commands and library locations, but when i try to build the project, compiler gives external error, referring to opencv.hpp or core.hpp file calling a "opencv2/core.hpp" path, which does not exist in opencv folder. I figured out that the problem is linked to the way core.hpp is called, but the library files are read-only.
From what i saw in opencv.hpp file, this relative "opencv2/[module].hpp" reference is not only for the core, but all other modules as well. There is no opencv2 folder inside the one to where openCV is installed at all, in fact.
I've tried reinstalling and remaking openCV with different making arguments, using a different IDE and including direct search folders in eclipse. The problem, apparently, lies in the files themselves, or the way it maybe gets installed in the system the wrong way. The problem persists on both my main ubuntu machine and the ARMbian orange pi.
i get this error when trying to include any openCV library that contains
#include "opencv2/[opencv module].hpp" in it
as a result, compilation is terminated with the error message stating "/usr/local/include/opencv4/opencv2/opencv.hpp:52:28: fatal error: opencv2/core.hpp: No such file or directory"
edit 1: GCC c++ compiler options are -Iusr/local/include/opencv4/opencv2 -O3 -Wall -c -fmessage-length=0 and linker's options are -L/usr/local/lib.
The code is a simple displayImage
#include <opencv4/opencv2/opencv.hpp>
#include <opencv4/opencv2/imgproc.hpp>
#include <opencv2/highgui/highgui.hpp>
using namespace cv;
int main( int argc, char** argv )
{
Mat image;
image = imread( argv[1], 1 );
namedWindow( "Display Image", CV_WINDOW_AUTOSIZE );
imshow( "Display Image", image );
waitKey(0);
return 0;
}
edit 2: $ pkg-config --libs opencv does not see openCV as installed in the system, altho i've made sure to run make install and ldconfig on the path. This may be a signal of faulty installation, but this is just a sidenote, not entirely related to main problem. I have tried reinstalls and to different folders, but this also persists as well as a main problem
apparently, #sgarizvi 's comment was the answer. I just needed to set the include path to I/usr/local/include/opencv4 and it worked. After that, the error was fixed.
I am replying to my own question to close the case, as i cannot upvote/veryfy a comment
In your case, since your include path is /usr/local/include/opencv4/opencv2
Replace the first three lines
#include <opencv4/opencv2/opencv.hpp>
#include <opencv4/opencv2/imgproc.hpp>
#include <opencv2/highgui/highgui.hpp>
by
#include <opencv.hpp>
#include <imgproc.hpp>
#include <highgui.hpp>

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

C++ Boost and ImageMagick++ API issue

While developing Raspberry Pi library compiled by g++4.9.2 I have met compability issue between boost (1.6.2) and ImageMagick++ API (7.0). When compiling this code:
#include <Magick++.h>
#include <boost/filesystem.hpp>
#include <boost/foreach.hpp>
I got these boost errors:
__assert_fail was not declared in this scope (path_trails.hpp)
...
__assert_fail was not declared in this scope (path.hpp)
...
__assert_fail was not declared in this scope (shared_ptr.hpp)
When deleting #include <Magick++.h> line everything runs fine. Unfortunately I need boost and ImageMagick as well in this source file. How to solve this issue?
A simple workaround is to include Magick++.h after boost.
#include <boost/filesystem.hpp>
#include <boost/foreach.hpp>
#include <Magick++.h>
I don't have a proper explanation for this problem but it seems to come from a clash when using different headers including assert.h (I had the same problem using the assimp library and ImageMagick) but I don't get why the order matters.
Reproducing your case, assert.h is included in:
cassert for boost
MagickCore/pixel-accessor.h for Magick++.h
If someone has an explanation for this problem feel free to edit.

OpenCV3.10 core.hpp must be compiled in C++

i have installed OpenCV 3.10 and the linked the opencv_world310.lib to release and opencv_world310d.lib to debug.
Moreover I put the compiler options in search directory to ...opencv\build\include. I got a undefined reference error when i left out #include <opencv2/highgui.hpp. Now that i have included it my code looks like this:
#include <stdio.h>
#include "opencv/cv.h"
#include "opencv/highgui.h"
#include <opencv2/highgui.hpp>
int main(void){
printf("HALLO!");
return 0;
}
When i try to build it core.hpp opens and the error: core.hpp must be compiled in C++ occurs.
I am using the GNU GCC Compiler in Codeblocks.
What should i do to solve the problem?
Check you compiler options. Open CV 3.10 C++ API requires code to be compiled as C++, but not C. You can use answer to "CodeBlocks: change project language c and c++" question to change the options.
Also use the new Open CV 3.10 API
#include <opencv2/opencv.hpp>`
instead of all the other Open CV header files. This header includes core functionality. To enable highgui module you need to define HAVE_OPENCV_HIGHGUI in your project settings.

error: ‘cv::fisheye’ has not been declared

I wanted to write a camera calibration for a 140 deg fisheye lens.
As the normal calibration of opencv is not working with these lenses I found that there seems to be a cv::fisheye module within the calib3d bundle.
But every time I try to compile my code the g++ states:
error: ‘cv::fisheye’ has not been declared
the problem is that the documentation of opencv 2.4.11 contains the methods and the additional namespace.
I have the following includes in my c++ file:
//OPENCV Stuff
#include "opencv2/opencv.hpp"
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/calib3d/calib3d.hpp"
#include "opencv2/features2d/features2d.hpp"
the call of the function looks like that:
double rmsL = cv::fisheye::calibrate(objectPoints, imagePointsLeft, imagesize, cameraMatrices[LEFT], distCoeffs[LEFT], rvecs, tvecs);
I am compiling with the include path for pkg-config
OPENCV = `pkg-config opencv --cflags --libs`
In fact the normal calibration stuff is working properly as well as any other opencv related stuff.
Is anyone out there able to help me with tis problem?
It would be quiet nice to use the fisheye calibration because of the wide fov and its improvements for calculating the disparity map.
Cheers hGen
Do you use these compile options?
-I/pathto/opencv/include -L/pathto/library lopencv_core
error: ‘cv::fisheye’ has not been declared is a compilation error. Not a linker error. Which means, your compiler is not able to look for defnitions of cv::fisheye.
Either try to give explicit path.
#include "path/to/opencv2/.....h"
or
Provide the include path in -I switch.
g++ -I<path to opencv2> *.cpp -l <path to opencv2 lib> -o <target-name>