dev_update_pc ('off')
dev_update_window ('off')
dev_update_var ('off')
read_image (Image, 'D:/任务/emodelimage.bmp')
get_image_size (Image, Width, Height)
dev_close_window ()
dev_open_window (0, 0, Width, Height, 'black', WindowHandle)
dev_set_color ('red')
dev_display (Image)
*画ROI区域
draw_rectangle1 (WindowHandle, Row1, Column1, Row2, Column2)
gen_rectangle1 (Rectangle, Row1, Column1, Row2, Column2)
*相减
reduce_domain (Image,Rectangle, ImageReduced)
create_scaled_shape_model (ImageReduced, 'auto', -0.39, 0.79, 'auto', 0.9, 1.1, 'auto', 'auto', 'use_polarity', 'auto', 'auto', ModelID)
get_shape_model_contours (ModelContours, ModelID, 1)
area_center (Rectangle, Area, RowRef, ColumnRef)
* vector_angle_to_rigid (0, 0, 0, RowRef, ColumnRef, 0, HomMat2D)
* affine_trans_contour_xld (ModelContours, ContoursAffinTrans, HomMat2D)
dev_display (Image)
* dev_display (ContoursAffinTrans)
read_image (Image1, 'D:/任务/inspectImage4.bmp')
get_image_size (Image1, Width1, Height1)
reduce_domain (Image1, Rectangle, ImageReduced1)
create_scaled_shape_model (ImageReduced1, 'auto', -0.39, 0.79, 'auto', 0.9, 1.1, 'auto', 'auto', 'use_polarity', 'auto', 'auto', ModelID1)
* get_shape_model_contours (ModelContours1, ModelID1, 1)
abs_diff_image (ImageReduced1, ImageReduced, ImageAbsDiff, 1)
rgb1_to_gray (ImageAbsDiff, GrayImage)
threshold (GrayImage, Regions, 20, 255)
connection (Regions, ConnectedRegions)
select_shape (ConnectedRegions, SelectedRegions, 'area', 'and', 9.59, 500)
union1 (SelectedRegions, RegionUnion)
area_center (RegionUnion, Area1, Row, Column)
if (Area1>100)
smallest_rectangle2 (RegionUnion, Row3, Column3, Phi, Length1, Length2)
gen_rectangle2_contour_xld (Rectangle1, Row3, Column3, Phi, Length1, Length2)
dev_display (Image1)
dev_display(Rectangle1)
disp_message (WindowHandle, '检测到有异物', 'BinImage', RowRef, ColumnRef, 'red', 'true')
else
disp_message (WindowHandle, '检测通过', 'BinImage', RowRef, ColumnRef, 'green', 'true')
endif
文章图片
文章图片
【halcon|Halcon检测图片有无异物并标记】
推荐阅读
- python|数字图像基本操作——图像采样、量化、算术运算、点运算实验结果及分析
- OpenCV从入门到精通|OpenCV中的图像处理 —— 改变颜色空间+图像几何变换
- OpenCV从入门到精通|OpenCV的核心操作 —— 图像的基本操作+图像上的算术运算
- 图像处理|人工智能最新研究发展方向——OCR文字识别简述
- python|数字图像处理-Python实现BMP图片(位图)旋转-代码实例
- 数字图像处理|灰度图像--图像分割 阈值处理之OTSU阈值
- 图像处理|OpenCV Tutorials(三)矩阵的掩码(或卷积)操作
- 日常小技巧|任意角度旋转图片(python)
- 算法|2021APMCM赛后总结——边缘检测