跳一跳中从skeleton骨架里拟合椭圆
By
admin
at 2018-02-25 • 0人收藏 • 2164人看过
跳一跳中有圆形的跳板, 嗯,不对,是椭圆形的跳板.
我们通过骨架获得到的边界需要进行椭圆模拟,然后找到中心点
read_image (Image, 'C:/Users/Administrator/Desktop/halcon_T1T/testsave.png') dev_close_window () dev_open_window_fit_image (Image, 0, 0, -1, -1, WindowHandle) dev_display (Image) //因为事先处理图片为边界黑色,所以只选择黑色部分 threshold (Image, Regions, 0, 200) //膨胀选中的全部线段:使每个像素点都链接起来,成为一个完整的不断的线条 dilation_rectangle1 (Regions, RegionDilation, 30, 30) //抽取膨胀后的粗线条的骨架 skeleton (RegionDilation, Skeleton) //把图片中的所有曲线联合分离 connection (Skeleton, ConnectedRegions) //选中准备拟合的这个线段 select_obj (ConnectedRegions, ObjectSelected2, 2) //将骨架转换为xld线 gen_contours_skeleton_xld (ObjectSelected2, Contours, 1, 'filter') //把xld线拆分为线和圆弧 segment_contours_xld (Contours, ContoursSplit, 'lines_ellipses', 5, 4, 2) //对这些弧线进行排序,按照"行"先后排序,这样跳跳里面这个应该是最上面的 sort_contours_xld (ContoursSplit, SortedContours, 'upper_left', 'true', 'row') //选择最上面那个弧线 select_obj (SortedContours, ObjectSelected3, 1) //拟合为椭圆 fit_ellipse_contour_xld (ObjectSelected3, 'fitzgibbon', -1, 0, 0, 200, 3, 2, Row3, Column3, Phi1, Radius1, Radius2, StartPhi, EndPhi, PointOrder) //绘制椭圆 gen_ellipse_contour_xld (ContEllipse, Row3, Column3, Phi1, Radius1, Radius2, 0, 6.28318, 'positive', 1.5) //画出椭圆中心点 disp_cross (WindowHandle, Row3, Column3, 50, 0)
2 个回复 | 最后更新于 2018-02-25
另外一种写法:
这种适应性差,只为学习用
将图片进行灰度之后,阈值缩放加深对比色,然后利用灰度方块统一色调,整个画面图形就全是黑色了,然后找边缘...这里就又问题了.边缘有些顺序不一致.....
// var ret,Image1, Image2, Image3 = halconc.decompose3 (gameImage, 0,0,0); var ret,ROI_0 = halconc.gen_rectangle1 (0, 218.498, 2.83828, 1223.44, 746.162); var ret,ImageReduced = halconc.reduce_domain (Image3, ROI_0, 0); var flag = 0; for(y=219;1223;1){ var ret,base_Grayval = halconc.get_grayval (ImageReduced, y, 3, 0) for(x=3;745;1){ var ret,single_Grayval = halconc.get_grayval (ImageReduced, y, x, 0) var dec_val = math.abs(single_Grayval-base_Grayval) if(dec_val!=0){ //if(flag ==0){ var ret = halconc.set_grayval (ImageReduced, y, x, 0) //}else { // var ret = halconc.set_grayval (ImageReduced, y, x, 255) //} //flag ++; }else { //if(flag != 0){ // var ret = halconc.set_grayval (ImageReduced, y, x-1, 0) // flag = 0; //}else { var ret = halconc.set_grayval (ImageReduced, y, x, 255) //} } } } var ret,ImageMin1 = halconc.gray_erosion_rect (ImageReduced, 0, 8, 8) var ret = halconc.disp_obj(ImageMin1,Hwindow); var ret,Edges1 = halconc.edges_sub_pix (ImageMin1, 0, 'canny', 1, 20, 40) var ret,ContoursSplit = halconc.segment_contours_xld (Edges1, 0, 'lines_ellipses', 5, 4, 2) var ret,SortedContours = halconc.sort_contours_xld (ContoursSplit, 0, 'upper_left', 'true', 'row') var ret,ObjectSelected = halconc.select_obj (SortedContours, 0, 9) var ret = halconc.set_color(Hwindow,"magenta"); var ret = halconc.set_line_width(Hwindow,3); var ret = halconc.disp_obj(ObjectSelected,Hwindow);
登录后方可回帖
下面是找图片中方形物体的中心点:(圆形点的是上面的,但是怎么判断是方的或者是圆的??)