halcon19.11
时间: 2023-07-25 10:03:45 浏览: 135
好的,我会使用 HALCON 19.11 版本的 HDevelop 编程语言来实现您的要求。
以下是代码实现:
```
* 读取图像
read_image (Image, 'brake_disk_part_01.png')
* 转为灰度图像
rgb1_to_gray (Image, GrayImage)
* 二值化
threshold (GrayImage, BinaryImage, 128, 255)
* 寻找圆
dev_set_draw ('margin')
find_filled_circles (BinaryImage, CircleResults, 10, 50, 5, 'positive', 'geometric', 0.5, 10)
* 计算圆心坐标和面积
get_circle_contour (CircleContours, CircleResults)
area_center (CircleContours, CircleAreas, CircleCenters)
* 找出面积最大的圆
tuple_sort_index (CircleAreas, SortedIndex)
tuple_length (SortedIndex, NumCircles)
tuple_lastn (SortedIndex, IndexMax, 1)
tuple_select (CircleCenters, IndexMax, MaxCircleCenter)
tuple_select (CircleAreas, IndexMax, MaxCircleArea)
* 在图像上画出圆和连线
dev_display (Image)
dev_display (CircleContours)
dev_set_color ('red')
dev_display_line (0, MaxCircleCenter[1], 4096, MaxCircleCenter[1])
dev_display_line (MaxCircleCenter[0], MaxCircleCenter[1], MaxCircleCenter[0], 0)
* 计算连线长度和夹角
Distance := sqrt ((MaxCircleCenter[0]^2) + (MaxCircleCenter[1]^2))
Angle := atan2 (MaxCircleCenter[1], MaxCircleCenter[0]) * 180 / pi
* 显示结果
disp_message (WindowHandle, 'Max circle area: ' + MaxCircleArea, 'window', 10, 10, 'black', 'true')
disp_message (WindowHandle, 'Distance to origin: ' + Distance, 'window', 30, 10, 'black', 'true')
disp_message (WindowHandle, 'Angle to horizontal: ' + Angle, 'window', 50, 10, 'black', 'true')
```
此代码将会完成您的要求。您可以根据实际需要进行调整和修改。
阅读全文
相关推荐
![txt](https://img-home.csdnimg.cn/images/20241231045021.png)
![hdev](https://img-home.csdnimg.cn/images/20250102104920.png)
![rar](https://img-home.csdnimg.cn/images/20241231044955.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![-](https://img-home.csdnimg.cn/images/20241231044955.png)
![-](https://img-home.csdnimg.cn/images/20241231044955.png)
![-](https://img-home.csdnimg.cn/images/20241231045053.png)
![-](https://img-home.csdnimg.cn/images/20241231044955.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)