Halcon(图像预处理)
* 创建一个空的仿射变换矩阵
hom_mat2d_identity (HomMat2DIdentity)
* 设置平移矩阵
hom_mat2d_translate (HomMat2DIdentity, 64, 64, HomMat2DTranslate)
* 设置旋转矩阵
hom_mat2d_rotate (HomMat2DTranslate, 0.78, 0, 0, HomMat2DRotate)
* 设置缩放矩阵
hom_mat2d_scale (HomMat2DRotate, 2, 2, 0, 0, HomMat2DScale)
应用仿射变换矩阵:
* 应用于像素点
affine_trans_pixel (HomMat2DScale, 64, 64, RowTrans, ColTrans)
* 应用于二维点
affine_trans_point_2d (HomMat2DScale, RowTrans, ColTrans, Qx, Qy)
* 应用于图像
affine_trans_image (Image, ImageAffineTrans, HomMat2DScale, 'constant', 'false')
* 应用于区域
affine_trans_region (Region, RegionAffineTrans, HomMat2DScale, 'nearest_neighbor')
* 应用于XLD轮廓
affine_trans_contour_xld (, ContoursAffineTrans, HomMat2DScale)
*关闭当前显示窗口,清空屏幕
dev_close_window ()
*读取测试图像
read_image (Image_display, 'data/display.jpg')
*将图像转化为灰度图像
rgb1_to_gray (Image_display, GrayImage)
*获取图像的尺寸
get_image_size(Image_display,imageWidth, imageHeight)
*新建显示窗口,适应图像尺寸
dev_open_window (0, 0, imageWidth, imageHeight, 'black', WindowHandle1)
dev_display (GrayImage)
*初始化角点坐标
XCoordCorners := []
YCoordCorners := []
*阈值处理,提取较暗的区域
threshold(GrayImage,DarkRegion,0, 80)
*分离不相连的区域
connection (DarkRegion, ConnectedRegions)
*选择面积最大的暗色区域,即屏幕区域
select_shape_std (ConnectedRegions, displayRegion, 'max_area', 70)
*裁剪屏幕区域
reduce_domain (GrayImage, displayRegion, displayImage)
*创建边缘轮廓
gen_contour_region_xld (displayRegion, Contours, 'border')
*将轮廓分割为边
segment_contours_xld (Contours, ContoursSplit, 'lines', 5, 4, 2)
*获取边的数量
count_obj (ContoursSplit, Number)
*存储每条边的起点位置
for index:=1 to Number by 1
select_obj(ContoursSplit, ObjectCurrent, index)
*拟合每条边
fit_line_contour_xld (ObjectCurrent, 'tukey', -1, 0, 5, 2, RowBegin, ColBegin, RowEnd, ColEnd, Nr, Nc, Dist)
*存储每条边的顶点x坐标
tuple_concat (XCoordCorners, RowBegin, XCoordCorners)
*存储每条边的顶点y坐标
tuple_concat (YCoordCorners, ColBegin, YCoordCorners)
endfor
* 投影变换给四个特征点与校正后的坐标建立关联
XOff:= 100
YOff:= 100*imageHeight/imageWidth
hom_vector_to_proj_hom_mat2d (XCoordCorners, YCoordCorners, [1,1,1,1], [YOff,YOff,imageHeight-YOff,imageHeight-YOff], [XOff,imageWidth-XOff,imageWidth-XOff,XOff], [1,1,1,1], 'normalized_dlt', HomMat2D)
*投影变换
projective_trans_image (Image_display, Image_rectified, HomMat2D, 'bilinear', 'false', 'false')
* 显示校正结果
dev_display (Image_rectified)
*关闭当前显示窗口,清空屏幕
dev_close_window ()
*读取测试图像
read_image (Image_display, 'data/display.jpg')
*获取图像的尺寸
get_image_size(Image_display,imageWidth, imageHeight)
*新建显示窗口,适应图像尺寸
dev_open_window (0, 0, imageWidth, imageHeight, 'black', WindowHandle)
dev_display (Image_display)
gen_rectangle1 (ROI_0, 52, 46, 456, 574)
*裁剪屏幕区域
reduce_domain (Image_display, ROI_0, reducedImage)
dev_open_window (0, 400, imageWidth, imageHeight, 'black', WindowHandle1)
* 显示校正结果
dev_display (reducedImage)
dev_close_window ()
read_image (board, 'data/boardEqu')
get_image_size(board, imageWidth, imageHeight)
dev_open_window (0, 0, imageWidth, imageHeight, 'black', WindowHandle)
dev_display (board)
rgb1_to_gray (board, GrayImage)
*直方图均衡
equ_histo_image (GrayImage, ImageEquHisto)
dev_display (ImageEquHisto)
dev_close_window ()
read_image (boardtext, 'data/text.jpg')
get_image_size(boardtext, imageWidth, imageHeight)
dev_open_window (0, 0, imageWidth, imageHeight, 'black', WindowHandle)
dev_display (boardtext)
emphasize (boardtext, ImageEmphasize, 10, 10, 1.5)
dev_display(ImageEmphasize)
dev_close_window ()
read_image (boardtext, 'data/text.jpg')
get_image_size(boardtext, imageWidth, imageHeight)
dev_open_window (0, 0, imageWidth, imageHeight, 'black', WindowHandle)
dev_display (boardtext)
scale_image_max (boardtext, ImageScaleMax)
dev_display(ImageScaleMax)
dev_close_window ()
read_image (test, 'data/defocusComponnet.jpg')
get_image_size(test, imageWidth, imageHeight)
dev_open_window (0, 0, imageWidth, imageHeight, 'black', WindowHandle)
dev_display (test)
shock_filter (test, SharpenedImage, 0.5, 20, 'canny', 12.5)
dev_display(SharpenedImage)
read_image (ImageNoise, 'data/marker.jpg')
mean_image (ImageNoise, ImageMean, 9,9)
dev_display(ImageMean)
read_image (ImageNoise, 'data/marker.jpg')
median_image (ImageNoise, ImageMedian, 'circle', 3, 'continued')
dev_display(ImageMedian)
read_image (ImageNoise, 'data/marker.jpg')
gauss_filter(ImageNoise, ImageGauss, 5)
dev_display(ImageGauss)
read_image (test, 'data/label')
*通道分离
decompose3(test, image1, image2, image3)
mean_image (image1, Mean1, 9, 9)
emphasize (Mean1, em1, 5, 5, 1.5)
illuminate (em1, ImageI1, 20, 20, 0.55)
equ_histo_image (image2, ImageEquHisto2)
equ_histo_image (image3, ImageEquHisto3)
compose3 (ImageI1, ImageEquHisto2, ImageEquHisto3, MultiChannelImage)
dev_display(MultiChannelImage)
dev_close_window ()
read_image (test, 'data/label')
get_image_size(test, imageWidth, imageHeight)
dev_open_window (0, 0, imageWidth, imageHeight, 'black', WindowHandle)
*通道分离
decompose3(test, image1, image2, image3)
mean_image (image1, Mean1, 9, 9)
emphasize (Mean1, em1, 5, 5, 1.5)
illuminate (em1, ImageI1, 20, 20, 0.55)
equ_histo_image (image2, ImageEquHisto2)
equ_histo_image (image3, ImageEquHisto3)
compose3 (ImageI1, ImageEquHisto2, ImageEquHisto3, MultiChannelImage)
dev_display(MultiChannelImage)
dev_open_window (0, 0, imageWidth, imageHeight, 'black', WindowHandle)
*增强对比度
emphasize (MultiChannelImage, ImageEmphasize, 10, 10, 5)
*高斯滤波
gauss_filter(ImageEmphasize, ImageGauss, 3)
dev_display(ImageGauss)