【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.

  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

D-Nolan

请我喝杯咖啡吧,鼓励一下创作!

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值