haben Sie einen Blick auf den folgenden CodeUnterschied zwischen „Kantenerkennung“ und „Bildkonturen“
#include <iostream>
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/imgproc/imgproc.hpp>
using namespace std;
using namespace cv;
Mat src, grey;
int thresh = 10;
const char* windowName = "Contours";
void detectContours(int,void*);
int main()
{
src = imread("C:/Users/Public/Pictures/Sample Pictures/Penguins.jpg");
//Convert to grey scale
cvtColor(src,grey,CV_BGR2GRAY);
//Remove the noise
cv::GaussianBlur(grey,grey,Size(3,3),0);
//Create the window
namedWindow(windowName);
//Display the original image
namedWindow("Original");
imshow("Original",src);
//Create the trackbar
cv::createTrackbar("Thresholding",windowName,&thresh,255,detectContours);
detectContours(0,0);
waitKey(0);
return 0;
}
void detectContours(int,void*)
{
Mat canny_output,drawing;
vector<vector<Point>> contours;
vector<Vec4i>heirachy;
//Detect edges using canny
cv::Canny(grey,canny_output,thresh,2*thresh);
namedWindow("Canny");
imshow("Canny",canny_output);
//Find contours
cv::findContours(canny_output,contours,heirachy,CV_RETR_TREE,CV_CHAIN_APPROX_SIMPLE,Point(0,0));
//Setup the output into black
drawing = Mat::zeros(canny_output.size(),CV_8UC3);
//Draw contours
for(int i=0;i<contours.size();i++)
{
cv::drawContours(drawing,contours,i,Scalar(255,255,255),1,8,heirachy,0,Point());
}
imshow(windowName,drawing);
}
Theoretisch Contours
Mittel Kurven zu erfassen. Edge detection
bedeutet Erkennung von Kanten. In meinem obigen Code habe ich Kantenerkennung mit Canny
und Kurvenerkennung durch findContours()
durchgeführt. Im Folgenden sind die resultierenden Bilder
Canny Bild
Contours Bild
OK, also jetzt, wie man sehen kann, gibt es keinen Unterschied! Also, was ist der tatsächliche Unterschied zwischen diesen 2? In OpenCV-Tutorials wird nur der Code angegeben. Ich habe eine Erklärung dazu gefunden, was Contours
ist, aber dieses Problem wird nicht angesprochen.
Bitte helfen!
Ich schlage vor, Sie verwenden cv :: Weichzeichnen() vor cv :: Canny(). Dies kann den Großteil der Unordnung beseitigen, während die Hauptkanten beibehalten werden. – Bull