Registriert seit: 12. Dez 2005
Ort: Schweiz
1.024 Beiträge
Delphi XE6 Starter
|
AW: Erkennen von geometrien in Bild
8. Sep 2015, 15:19
Habe nun OpenCV gefunden. Ist aber C++
Habe nun kurz ein kleines Consolenprogramm mit OpenCV geschrieben, welches diese Aufgabe erledigt!
Anbei die exe im zip.
hier der Code:
Code:
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/imgproc/imgproc.hpp"
#include <iostream>
using namespace cv;
using namespace std;
static void help()
{
cout << "\nThis program demonstrates circle finding with the Hough transform.\n"
"Usage:\n"
"./houghcircles <image_name>, Default is pic1.png\n" << endl;
}
int main(int argc, char** argv)
{
const char* filename = argc >= 2 ? argv[1] : "board.jpg";
Mat img = imread(filename, 0);
if(img.empty())
{
help();
cout << "can not open " << filename << endl;
return -1;
}
Mat cimg;
medianBlur(img, img, 5);
cvtColor(img, cimg, COLOR_GRAY2BGR);
vector<Vec3f> circles;
HoughCircles(img, circles, CV_HOUGH_GRADIENT, 1, 10,
100, 30, 1, 30 // change the last two parameters
// (min_radius & max_radius) to detect larger circles
);
char myBuf[10];
for( size_t i = 0; i < circles.size(); i++ )
{
Vec3i c = circles[i];
cout << "x:" << Point(c[0],c[1]).x << " y:" << Point(c[0],c[1]).y << " r:" << c[2] << endl;
circle( cimg, Point(c[0], c[1]), c[2], Scalar(0,0,255), 1, CV_AA);
circle( cimg, Point(c[0], c[1]), 2, Scalar(0,255,0), 1, CV_AA);
}
imshow("detected circles", cimg);
waitKey();
return 0;
}
|
|
Zitat
|