Cannot find OpenCV 2 Delaunay triangulation functions in OpenCV 3 [duplicate] - c++

This question already has an answer here:
Is there C++ API for Delaunay triangulation in OpenCV?
(1 answer)
Closed 5 years ago.
I have installed OpenCV 3.2.0 on Ubuntu 16 and am developing using C++ in NetBeans 8.2. I am trying the following code which worked perfectly with OpenCV 2.
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <cv.hpp>
#include <highgui.h>
#include <opencv2/core.hpp>
#include <opencv2/highgui.hpp>
#include <opencv2/imgproc.hpp>
#include <opencv2/imgcodecs.hpp>
#include <opencv2/videoio.hpp>
#include <opencv2/imgproc/imgproc_c.h>
#include <vector>
#include <set>
#include <map>
vector< Triangle > CTwoDTriangulation::delaunayDiv(const vector< Point_<T> > & vP, cv::Rect boundRect,
vector<Triangle>& triangles, int& numTriangles, bool lookRight)
{
CvSubdiv2D* subdiv;
int numPts=vP.size();
CvPoint newPoint;
CvMemStorage *storage;
storage = cvCreateMemStorage(0);
subdiv = cvCreateSubdivDelaunay2D( boundRect, storage );
for (size_t e = 0; e<numPts; e++)
{
newPoint=vP.at(e);
if (newPoint.x<(boundRect.x + boundRect.width) && newPoint.y<(boundRect.y + boundRect.height))
cvSubdivDelaunay2DInsert(subdiv, vP.at(e));
}
}
With OpenCV 3, I get the following errors.
../../DraculaFiles/TwoDTriangulation.cpp:4278:60: error: there are no arguments to ‘cvCreateSubdivDelaunay2D’ that depend on a template parameter, so a declaration of ‘cvCreateSubdivDelaunay2D’ must be available [-fpermissive]
subdiv = cvCreateSubdivDelaunay2D( boundRect, storage );
I tried typing cv:: and seeing what functions are available. But I saw nothing similar to CreateSubdivDelaunay2D. I have also done a Google search to see what has replaced cvCreateSubdivDelaunay2D in OpenCV 3 but could not find anything.

cvCreateSubdivDelaunay2D became legacy (so does the whole c-interface for delauny triangulation) and has been removed.
For OpenCV 3 you can refer to the cv::SubDiv class instead.

Related

Why Scalar does not work?

Following code results in build success, but no window. Without "m = Scalar(255,0,0);", it creates black window. Why including scalar does not work?
#include <iostream>
#include <stdio.h>
#include <opencv2/opencv.hpp>
#include <opencv2/imgproc.hpp>
#include <opencv2/core.hpp>
#include <opencv2/highgui.hpp>
using namespace cv;
using namespace std;
int main() {
Mat m = Mat::zeros(200,200,CV_8UC3);
m = Scalar(255,0,0); //without this, it creates window.
imshow("m", m);
waitKey();
}
It will not give you any compilation error as Mat and Scalar are basically array types of OpenCV.
This is a possible duplicate of How to set all pixels of an OpenCV Mat to a specific value?
Your code have to work!
take a look at the doc:
C++: void imshow(const string& winname, InputArray mat)
and I can confirm you is working fine on my environment(opencv320, VisualStudio2017):
you need to clean the project and build again.

Does CvQuadEdge2D have an equivalent in OpenCV 3

I am using OpenCV 3.2 with Netbeans 8.0 on Ubuntu 16(LTS).
CvQuadEdge2D was quite useful in OpenCV 2 but appears to be gone from OpenCV 3. The closest I could find was
struct CV_EXPORTS QuadEdge
{
QuadEdge();
QuadEdge(int edgeidx);
bool isfree() const;
int next[4];
int pt[4];
};
in imageproc.hpp. However
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include <windows.h>
#include <string.h>
#include <cv.hpp>
#include <highgui.h>
#include <opencv2/core.hpp>
#include <opencv2/highgui.hpp>
#include <opencv2/imgproc.hpp>
int main(){
struct CV_EXPORTS QuadEdge* edge
}
results in QuadEdge being "undefined".
In OpenCV 3 the concept behind CvQuadEdge2D is in Edge.
Now you can navigate through edges using getEdge. You can get the list of the vertices of all edges using getEdgeList
QuadEdge itself is a protected member of the class Subdiv2d, so you cannot access it. You should use the new Edge interface.

OpenCV 3.1.0 : How to use BackgroundSubtractorMOG class

I have OpenCV 3.1.0 installed.
I want to use BackgroundSubtractorMOG so in my file i have these includes:
//opencv
#include "opencv2/imgcodecs.hpp"
#include "opencv2/imgproc.hpp"
#include "opencv2/videoio.hpp"
#include <opencv2/highgui.hpp>
#include <opencv2/video.hpp>
#include <opencv2/video/background_segm.hpp>
//C
#include <stdio.h>
//C++
#include <iostream>
#include <sstream>
I declare a pointer to a class of this type:
Ptr<BackgroundSubtractorMOG> pMOG;
And I initialize the pointer like this:
pMOG = createBackgroundSubtractorMOG();
When I try to compile I get this:
/home/edd/Desktop/compvis/FML.cpp:19:5: error: ‘BackgroundSubtractorMOG’ was not declared in this scope
Ptr<BackgroundSubtractorMOG> pMOG; //MOG2 Background subtractor
^
/home/edd/Desktop/compvis/FML.cpp:19:28: error: template argument 1 is invalid
Ptr<BackgroundSubtractorMOG> pMOG; //MOG2 Background subtractor
^
/home/edd/Desktop/compvis/FML.cpp: In function ‘int main(int, char**)’:
/home/edd/Desktop/compvis/FML.cpp:29:42: error: ‘createBackgroundSubtractorMOG’ was not declared in this scope
pMOG = createBackgroundSubtractorMOG(); //MOG approach
^
I tried to look in the documentation. I couldn't figure out what header to include. I couldn't figure out how to instantiate an instance of the class correctly.
What do ?
In the code you've posted, I don't see any statement regarding namespaces. (e.g. using namespace cv in your preamble). Otherwise, you have to preface OpenCV code with cv:: (e.g. cv::Mat frame to declare a Mat object).
EDIT:
#include "opencv2/opencv.hpp"
#include "opencv2/bgsegm.hpp"
...
cv::Ptr<cv::BackgroundSubtractor> mog = cv::bgsegm::createBackgroundSubtractorMOG();
...
And by using the namespace:
#include "opencv2/opencv.hpp"
#include "opencv2/bgsegm.hpp"
using namespace cv
...
Ptr<BackgroundSubtractor> mog = bgsegm::createBackgroundSubtractorMOG();
...
Hope this helps,
MJ

Instance of overloaded function in OpenCV

Hello I am trying to implement a Fast Feature Detector code,in the initial phase of it i get the following errors
(1)no instance of overloaded function "cv::FastFeatureDetector::detect" matches the argument list
(2)"KeyPointsToPoints" is undefined
Please help me.
#include <stdio.h>
#include "opencv2/core/core.hpp"
#include "opencv2/features2d/features2d.hpp"
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/nonfree/nonfree.hpp"
using namespace cv;
int main()
{
Mat img1 = imread("0000.jpg", 1);
Mat img2 = imread("0001.jpg", 1);
// Detect keypoints in the left and right images
FastFeatureDetector detector(50);
Vector<KeyPoint> left_keypoints,right_keypoints;
detector.detect(img1, left_keypoints);
detector.detect(img2, right_keypoints);
vector<Point2f>left_points;
KeyPointsToPoints(left_keypoints,left_points);
vector<Point2f>right_points(left_points.size());
return 0;
}
The problem is in this line:
Vector<KeyPoint> left_keypoints,right_keypoints;
C++ is case-sensitive, it sees that Vector is something different than vector (what it should really be). Why would Vector work is beyond me, I would have expected an error earlier.
cv::FastFeatureDetector::detect only knows how to work with vector, not a Vector, so try to fix this bug and try again.
Also, KeyPointsToPoints does not exist in the OpenCV library (unless you program it yourself), make sure you use KeyPoint::convert(const vector<KeyPoint>&, vector<Point2f>&) to do the conversion.
There are a few small problems with the code as given. First you are missing using namespace std which is needed to use the vectors the way you are using them. You are also missing the include for vectors #include <vector>. vector<KeyPoints> should also have a lower case v. I'm also not sure if KeyPointsToPoints is part of OpenCV. You may have to implement this function on your own. I'm not sure, I just haven't seen it before.
#include <stdio.h>
#include <vector>
#include "opencv2/core/core.hpp"
#include "opencv2/features2d/features2d.hpp"
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/nonfree/nonfree.hpp"
using namespace cv;
using namespace std;
int main()
{
Mat img1 = imread("0000.jpg", 1);
Mat img2 = imread("0001.jpg", 1);
// Detect keypoints in the left and right images
FastFeatureDetector detector(50);
vector<KeyPoint> left_keypoints,right_keypoints;
detector.detect(img1, left_keypoints);
detector.detect(img2, right_keypoints);
vector<Point2f>left_points;
for (int i = 0; i < left_keypoints.size(); ++i)
{
left_points.push_back(left_keypoints.pt);
}
vector<Point2f>right_points(left_points.size());
return 0;
}
I didn't test the code above. Check out the OpenCV documentation here

How to use FeatureDetector in OpenCV C++?

I am using VS 2008 with OpenCV 2.1 installed as per the installation guide. FeatureDetector/SurfFeatureDetector are listed as classes in the documentation, but they are considered "syntax error : identifier 'SurfFeatureDetector"
This is pretty much the entirety of my code.
#include "cv.h"
#include "highgui.h"
Ptr<FeatureDetector> *detect = new SurfFeatureDetector();
I've tried a bunch of random combinations to get this to work. How can I initialize a featuredetector?
You're declaring a pointer to a cv::Ptr -- you really should just have the cv::Ptr. Change your code to
#include "cv.h"
#include "highgui.h"
using namespace cv;
Ptr<FeatureDetector> detect = new SurfFeatureDetector();
and it should work.
I think you have installation problem, try resinstalling from here: sourceforge.net/projects/opencvlibrary/files/opencv-win/2.2
anther other option is that your precompiler already has __OPENCV_OLD_CV_H__ defined.
Try undefining it before #include "cv.h"
When you type #include "cv.h"
It automatically should include featurs2d. in fact cv.h includes the following:
#include "opencv2/core/core_c.h"
#include "opencv2/core/core.hpp"
#include "opencv2/imgproc/imgproc_c.h"
#include "opencv2/imgproc/imgproc.hpp"
#include "opencv2/video/tracking.hpp"
#include "opencv2/features2d/features2d.hpp"
#include "opencv2/flann/flann.hpp"
#include "opencv2/calib3d/calib3d.hpp"
#include "opencv2/objdetect/objdetect.hpp"
#include "opencv2/legacy/compat.hpp"
You need the OpenCV 2.x style C++ include. See below
#include "opencv2/features2d/features2d.hpp"
#include "cv.h"
#include "highgui.h"
using namespace cv;
Ptr<FeatureDetector> detect = new SurfFeatureDetector();
You need to:
#include <opencv2/nonfree/nonfree.hpp>
(from here: http://answers.opencv.org/question/411/feature-detector-crash/)