【OpenCV 基础知识 21】霍夫变换圆形检测
program cv_HoughCircles;
{KaTeX parse error: Expected ‘EOF’, got ‘}’ at position 16: APPTYPE CONSOLE}̲ {R *.res}
uses
System.SysUtils,
ocv.highgui_c,
ocv.core_c,
ocv.core.types_c,
ocv.imgproc_c,
ocv.imgproc.types_c,
uResourcePaths;
const
filename = cResourceMedia + ‘opencv_logo_with_text_sm.png’;
type
TFloatArray = array [0 … 10] of Single;
pFloatArray = ^TFloatArray;
var
image: pIplImage = nil;
src: pIplImage = nil;
storage: pCvMemStorage;
results: pCvSeq;
i: Integer;
p: pFloatArray;
pt: TCvPoint;
begin
try
image := cvLoadImage(filename, CV_LOAD_IMAGE_GRAYSCALE);
WriteLn(Format('[i] image: %s', [filename]));
src := cvLoadImage(filename);
storage := cvCreateMemStorage(0);
cvSmooth(image, image, CV_GAUSSIAN, 5, 5);
results := cvHoughCircles(image, storage, CV_HOUGH_GRADIENT, 10, image^.width / 5);
for i := 0 to results^.total - 1 do
begin
p := pFloatArray(cvGetSeqElem(results, i));
pt := CvPoint(cvRound(p^[0]), cvRound(p^[1]));
cvCircle(src, pt, cvRound(p^[2]), CV_RGB(255, 0, 0));
end;
cvNamedWindow('cvHoughCircles', 1);
cvShowImage('cvHoughCircles', src);
cvWaitKey(0);
cvReleaseMemStorage(storage);
cvReleaseImage(image);
cvReleaseImage(src);
cvDestroyAllWindows();
except
on E: Exception do
WriteLn(E.ClassName, ‘: ‘, E.Message);
end;
end.