11111111111
知识共享平台
知识共享平台

讨教大学平台

  • 首页
  • 免费课
  • 精品课
  • 讨教题库
  • 企业服务

    hot

  • 下载APP
  • 证书查询
  • 关于我们
我问
讨教号
搜索
消息
  • 我的文章

    我的关注

    我的问答

    我的秘密

    我的评论

    我的订阅

    我的打赏

    我的钱包

    我的通知

    我的设置

    退出登录

  • ×

    登录

    讨教 | 通行证

    登录
    立即注册
    忘记密码?
    使用微信登录

    提问 ×

    写下你的问题,准确的表述更容易得到答案

    类型话题

    选择支付方式
    您的讨教币 111 付费金额

    机器视觉的应用,如何应用机器视觉来检测距离

    熊猫人
    2019-05-03 17:08:03
    2篇 作品
    1254 总阅读量

    先贴图为证



    在工业应用领域,距离测量的应用也是比较多的。



    举个例子,在瓶装检测中,由于某些异常操作,导致瓶中的液体装不满,这样的产品是不能流入市场的。



    半瓶水的液体先不说我买不买,就是买回来也不敢喝。



    因此,在产品出厂或入库之前,必须经过检测这一关。



    今天,我们就充当检测员,看看这些东西是怎么检测的吧!



    如果你手边有Halcon软件,自己跑跑程序;如何你没有,呵呵,问我要啊!这个软件还需要许可证,呵呵,问我要啊!可惜了,族规有要求,传女不传男!我也没办法啊!




    废话不多说,开始!

    Go!  Go!   Go!



    注意注意,这次我不检测瓶中液体高度,我要检测瓶口高度。如下图





    我要检测这部分的高度!!!


    为什么???



    因为族规有要求,不测寻常路!!!

    我也没办法!




    产品拿到手,第一步,分析产品特点。

    我们看看上图,你说你要怎么检测红线框内的高度,那模模糊糊的是啥!而且,这图中还有那么多瓶子,咋检?再瞅瞅,框内的瓶与框外的都是灰色的,颜色都是差不多,你说咋检?




    这位兄台,莫着急!慢慢听来!



  • 一幅图中有多个待检测对象——需要模板匹配!



  • 因为你也不知道它会在哪,只能,不敢打包票,最好使用模板匹配的方法找到它们的位置。




    2. 假如说我们找到了匹配的位置,然后应该怎么做呢?



    找到了位置,我们就直接进行检测!


    怎么检测,在Halcon中,我们可以先创建个测量对象,然后基于此对象ID所包含的区域中可自动检测垂直于长边的短边距离!



    咳咳,说的有点装*了,说白了,就是你在图中画个矩形,Halcon中的有个函数会直接帮你计算出来距离。



    如果你仔细一点,我会告诉你计算的是短距离,如下图。




    这下子你就明白了吧!



    它测的就是短边的距离!



    原来,测量距离超级简单啊,画个矩形就可以了!!!



    有了上面的分析,我们的思路,或者说我的思路就很明确了啊!先创建了模板,然后模板匹配,然后在匹配到的对象中测量距离!



    So easy !!!



    注意,注意,我要放大招了!


    我要狠心地贴出程序了!



    想运行看看的,赶紧走起!!!



    如果你看了程序,觉得哪里有疑问的,别害羞,要留言。



    如果你觉得程序还可以,你想报答我,点最下面的广告!




    * This program is to measure the distance between the top of the bottleneck and 

    * the bottom of the bottoleneck

    * The ideas to achieve this is 

    * First, Create shape model based on the bottleneck shape to locate the bottle

    * Second, Measure the distance based on the measure object.


    * Date: 2018-03-27



    * Read Image

    read_image (Image, 'C:/Users/Public/Documents/MVTec/HALCON-12.0/examples/images/ampoules/ampoules_01.png')

    get_image_size (Image, Width, Height)

    dev_close_window ()

    dev_open_window (0, 0, Width, Height, 'black', WindowHandle)

    dev_display (Image)

    set_draw (WindowHandle, 'margin')

    * create the reduce domain by rectangle

    gen_rectangle1 (ROI_0, 236, 206, 296, 250)

    reduce_domain (Image, ROI_0, ImageReduced)

    * area center

    area_center (ROI_0, Area, RowRef, ColumnRef)

    * create shape model

    create_shape_model (ImageReduced, 'auto', 0, 0, 'auto', 'auto', 'use_polarity', 'auto', 'auto', ModelID)

    * define the length and width of the measure rectangle object

    ROI_width := 15

    ROI_height:= 45

    * show the rectangle 

    gen_rectangle2 (ROI_1, 253, 459, rad(-90), ROI_height, ROI_width)

    * create the rectangle measure object

    gen_measure_rectangle2 (0, 0, rad(90), ROI_height, ROI_width, Width, Height, 'bilinear', MeasureHandle)

    * set fonts

    set_display_font (WindowHandle, 16, 'mono', 'true', 'false')


    for I:=1 to 8 by 1

        * read images    

        read_image (Image1, 'C:/Users/Public/Documents/MVTec/HALCON-12.0/examples/images/ampoules/ampoules_'+ I$'02d')

        * find shape. The MinScore is very important. If larger, more noise will be.

        find_shape_model (Image1, ModelID, 0, 0, 0.90, 0, 0.5, 'least_squares', 0, 0.9, Row, Column, Angle, Score)


        * Mulity Shape found

        for J:=0 to |Score| -1 by 1

            

            if(|Score[J]|==1)

                * set the cross at the center found

                gen_cross_contour_xld (Cross1, Row[J], Column[J], 6, 0)

                translate_measure (MeasureHandle, Row[J]-5, Column[J])

                

                gen_rectangle2 (ROI_2, Row[J], Column[J], rad(-90), ROI_height, ROI_width)

                

                * Measure the edge

                * The Sigma and threshold are very important.

                measure_pairs (Image1, MeasureHandle, 1.2, 10, 'all', 'all', RowEdgeFirst, ColumnEdgeFirst, AmplitudeFirst, RowEdgeSecond, ColumnEdgeSecond, AmplitudeSecond, IntraDistance, InterDistance)


                 if(|RowEdgeFirst|!=0)

                     disp_message (WindowHandle, InterDistance$'.2f', 'window', RowEdgeFirst[0], ColumnEdgeFirst[0], 'black', 'true')

                 else

                     disp_message (WindowHandle, 'None Found', 'window', 20, 0, 'black', 'true')

                 endif

                * Show it

                for edge:=0 to |RowEdgeFirst|- 1 by 1 

                    gen_cross_contour_xld (Cross, RowEdgeFirst[edge], ColumnEdgeFirst[edge], 10, 0)

                endfor

            endif

        endfor


     stop ()

        

    endfor

    clear_shape_model (ModelID)

    close_measure (MeasureHandle)

    本网站内容仅代表作者本人的观点,不代表本网站的观点和看法,与本网站立场无关,如有侵权请联系讨教。
    给作者打赏,鼓励TA抓紧创作
    0人打赏金额
    熊猫人
    2篇 作品
    1254 总阅读量
    评论
    您可能感兴趣的文章

    什么是大数据?看完这个视频你就明白了

    你真的知道什么是“大数据”吗?5分钟,带你get 9个重点

    什么才是真正的数字化转型?数字化转型转型什么?

    什么才是真正的数字化转型?

    转型不畏 | 数字化转型,怎能“拖泥带水”?

    A家观点 | 数字化转型下,中小企业如何迈向智能制造?

    热门话题 更多话题
    精益生产 质量管理 智能制造
    职场效率 项目管理 讨教
    AI 大数据 六西格玛
    ×

    给作者打赏,鼓励TA抓紧创作!

    选择支付方式
    选择打赏金额
    注:打赏的收益归作者,非平台

    微信扫描支付

    打赏金额: 1元

    ×

    给作者打赏,鼓励TA抓紧创作!

    您的讨教币
    填写您打赏讨教币数量
    输入密码

    111

    注:打赏的收益归作者,非平台

    微信扫描支付

    打赏金额: 1元