cvHoughCircles

int _tmain(int argc, _TCHAR* argv[]) {
	IplImage *image = cvLoadImage("LenaGr.jpg", 0);

	CvMemStorage *storage = cvCreateMemStorage(0);
	cvSmooth(image, image, CV_GAUSSIAN, 5, 5);
	CvSeq *results = cvHoughCircles(
		image,
		storage,
		CV_HOUGH_GRADIENT,
		2,
		image -> width / 10
		);

	for(int i = 0; i < results -> total; i++) {
		float *p = (float *) cvGetSeqElem(results, i);
		CvPoint pt = cvPoint(cvRound(p[0]), cvRound(p[1]));
		cvCircle(
			image,
			pt,
			cvRound(p[2]),
			CV_RGB(0xff, 0xff, 0xff)
			);
	}

	cvNamedWindow("Test", CV_WINDOW_AUTOSIZE);
	cvShowImage("Test", image);

	cvWaitKey(0);

	cvReleaseImage(&image);
	cvDestroyWindow("Test");

	return 0;
}

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章