VisionPro获取斑点(Blob)的外接矩形和最小外接矩形的方法

在斑点工具图形选项里可以看到“显示限定框”和“显示主要限定框”。

Blob工具提供这两个接口我们就可以通过脚本来获取它的几何信息了,如四个点的坐标等。

代码中的rect是提前声明的CogRectangleAffine。

  • 2
    点赞
  • 34
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
以下是使用VisionPro获取Blob最小外接矩形,然后创建与输入图像等大的图像,间画矩形并填充颜色,最后做图像差的代码: ``` Sub ProcessImage() ' Load image Dim img As CogImage8Grey Set img = New CogImage8Grey img.Load("C:\Images\input.jpg") ' Threshold image Dim thresholdTool As CogThresholdTool Set thresholdTool = New CogThresholdTool thresholdTool.InputImage = img thresholdTool.Run Set img = thresholdTool.OutputImage ' Find blobs Dim blobTool As CogBlobTool Set blobTool = New CogBlobTool blobTool.InputImage = img blobTool.Run Dim blobs As CogBlobResults Set blobs = blobTool.Results ' Get minimum bounding rectangles Dim mbrTool As CogMBRTool Set mbrTool = New CogMBRTool mbrTool.InputImage = img mbrTool.Results = blobs mbrTool.Run ' Create output image Dim outputImg As CogImage8Grey Set outputImg = New CogImage8Grey outputImg.Create img.Width, img.Height ' Draw rectangles and fill with color Dim rect As CogRectangle For Each rect In mbrTool.Results outputImg.FillRect rect.CenterX - rect.Width / 2, rect.CenterY - rect.Height / 2, rect.Width, rect.Height, 255 Next rect ' Compute image difference Dim diffTool As CogImage8InvertTool Set diffTool = New CogImage8InvertTool diffTool.InputImage = img diffTool.Run Set img = diffTool.OutputImage img.Combine outputImg, cogImageOperationSubtract ' Display result Dim disp As CogDisplay Set disp = New CogDisplay disp.Image = img disp.Fit(True) End Sub ``` 这个代码首先加载图像,然后对其进行阈值处理,找到Blob获取最小外接矩形,并创建一个与输入图像大小相同的输出图像。然后,它循环遍历每个最小外接矩形,绘制矩形和填充颜色。最后,它使用CogImage8InvertTool计算输入图像与输出图像的差异,并将其显示在CogDisplay对象中。你可以根据自己的需求修改代码来实现不同的功能。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值