1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
|
#include <vector>
#include <cv.h>
#include <highgui.h>
using namespace cv;
int main(int argc, char *argv[])
{
Mat img = imread("hough.png");
Mat gray;
cvtColor(img,gray,CV_BGR2GRAY);
vector<Point> pts;
for( int y = 0; y < gray.rows; y++ )
{
uchar* ptr = gray.ptr<uchar>(y);
for( int x = 0; x < gray.cols; x++ )
if (ptr[x] == 0) pts.push_back(Point(x,y));
}
RotatedRect rec = fitEllipse(Mat(pts));
ellipse(img,rec,CV_RGB(255,0,0),2);
cvNamedWindow("image", CV_WINDOW_AUTOSIZE);
imshow("image",img);
waitKey();
return 0;
} |
Partager