|
仿射变换:图像分辨率过大,内存消耗严重,此时较多的分割感兴趣的区域进行算法分析,算法分析完成后,需要将结果仿射变换回原图的过程。
- read_image (Image, 'C:/Users/ysw/Desktop/视频讲解/图像处理视频Halcon/仿射变换/defect4.bmp')
- count_channels(Image, Channels)
- if(Channels>1)
- rgb1_to_gray(Image, Image)
- endif
- get_image_size(Image, Width, Height)
- **** 二值化操作 ********
- threshold (Image, Regions, 3, 255)
- connection(Regions, ConnectedRegions)
- select_shape (ConnectedRegions, SelectedRegions, 'area', 'and', 100, 178455)
- fill_up(SelectedRegions, RegionFillUp)
- **** 水平矫正 ********
- smallest_rectangle2(RegionFillUp, Row, Column, Phi, Length1, Length2)
- if(Phi>rad(45))
- Phi := Phi-rad(45)
- elseif(Phi<-rad(45))
- Phi := Phi+rad(90)
- else
- endif
- vector_angle_to_rigid(Height/2,Width/2,0,Height/2,Width/2,-Phi,HomMat2D)
- *********************** 仿射变换 *********************************
- affine_trans_image(Image, ImageAffinTrans, HomMat2D, 'constant', 'false')
- affine_trans_region(RegionFillUp, RegionAffineTrans, HomMat2D, 'false')
- ***** 产生一个矩形,查看仿射变换后的结果,截取目标所在的像素区域 ************
- inner_rectangle1(RegionAffineTrans, Row1, Column1, Row2, Column2)
- gen_rectangle1(Rectangle, Row1, Column1, Row2, Column2)
- reduce_domain(ImageAffinTrans, Rectangle, ImageReduced)
- crop_part(ImageReduced, ImagePart, Row1, Column1, Column2-Column1, Row2-Row1)
- ********* 二值化处理 ******************
- threshold (ImagePart, Regions1, 0, 5)
- connection(Regions1, ConnectedRegions1)
- *********** 仿射反变换 ***************
- hom_mat2d_identity(HomMat2DIdentity)
- hom_mat2d_translate(HomMat2DIdentity,Row1,Column1,HomMat2DTranslate)
- hom_mat2d_rotate(HomMat2DTranslate,Phi,Height/2,Width/2,HomMat2DRotate)
- affine_trans_region(ConnectedRegions1,RegionAffineTrans1, HomMat2DRotate, 'false')
- *********** 标记 ********************
- area_center(RegionAffineTrans1, Area, Row3, Column3)
- if(|Row3|>0)
- tuple_gen_const(|Row3|,10,Radius)
- gen_circle_contour_xld(RegionAffineTrans1,Row3,Column3,Radius,0,6.28,'positive',1)
- else
- gen_empty_obj(ConnectedRegions1)
- endif
复制代码
|
|