【OpenCV 基础知识 21】霍夫变换圆形检测

作者 : admin 本文共1122个字,预计阅读时间需要3分钟 发布时间: 2024-06-9 共3人阅读

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.

本站无任何商业行为
个人在线分享 » 【OpenCV 基础知识 21】霍夫变换圆形检测
E-->