zoukankan      html  css  js  c++  java
  • halcon 药丸查找

    
    dev_close_window ()
    dev_update_off ()
    read_image (baseImage, 'blister/blister_reference')
    get_image_size (baseImage, Width, Height)
    dev_open_window_fit_image (baseImage, 0, 0, -1, -1, WindowHandle)
    set_display_font (WindowHandle, 16, 'mono', 'true', 'false')
    dev_set_draw ('margin')
    dev_set_line_width (3)
    * 1.分离通道>二值化得到外部区域>仿射变换得到基准图片>生成药丸区域
    * 2.读取图片>仿射变换图片位置到基准>获取药丸位置>遍历药丸二值化判断是否有无放错
    
    * 分离通道
    access_channel (baseImage, Image, 1)
    * 得到外部区域
    threshold (Image, Region, 60, 255)
    connection (Region, ConnectedRegions)
    select_shape (ConnectedRegions, SelectedRegions, 'area', 'and', 50000, 9999999)
    shape_trans (SelectedRegions, RegionTrans, 'convex')
    * 仿射变换
    orientation_region (RegionTrans, Phi)
    area_center (RegionTrans, Area, Row, Column)
    vector_angle_to_rigid (Row, Column, Phi, Row, Column, 0, HomMat2D)
    affine_trans_image (Image, Base_image, HomMat2D, 'constant', 'false')
    * 生成药丸区域
    gen_empty_obj (base_inner_cp_region)
    cp_row_number := 5
    cp_column_number := 3
    for Index := 1 to cp_row_number by 1
        * 外循环控制row 内循环控制column 
        row := 85+(Index-1)*71
        for Index1 := 1 to cp_column_number by 1
            column := 160+(Index1-1)*151
            gen_rectangle2 (Rectangle, row, column, 0, 67, 30)
            concat_obj (base_inner_cp_region, Rectangle, base_inner_cp_region)
        endfor
    endfor
    union1 (base_inner_cp_region, union_base_inner_cp_region)
    affine_trans_region (RegionTrans, RegionAffineTrans, HomMat2D, 'nearest_neighbor')
    orientation_region (RegionAffineTrans, Base_phi)
    area_center (RegionAffineTrans, Area1, Base_row, Base_column)
    image_count := 6
    for Index2 := 1 to image_count by 1
        read_image (Image1, 'blister/blister_'+Index2$'02')
        decompose3 (Image1, ImageR, ImageG, ImageB)
        threshold (ImageB, Region1, 200, 255)
        connection (Region1, ConnectedRegions1)
        select_shape (ConnectedRegions1, SelectedRegions1, 'area', 'and', 50000, 9999999)
        fill_up (SelectedRegions1, RegionFillUp)
        shape_trans (RegionFillUp, RegionTrans1, 'convex')
        orientation_region (RegionTrans1, now_phi)
        area_center (RegionTrans1, Area2, now_row, now_column)
        vector_angle_to_rigid (now_row, now_column, now_phi, Base_row, Base_column, Base_phi, HomMat2D1)
        affine_trans_image (Image1, show_image, HomMat2D1, 'constant', 'false')
        affine_trans_image (ImageB, ImageAffineTrans, HomMat2D1, 'constant', 'false')
        reduce_domain (ImageAffineTrans, union_base_inner_cp_region, image_reduce_out_imageB)
        * 二值化得到产品
        mean_image (image_reduce_out_imageB, mean_ImageB, 15, 15)
        dyn_threshold (image_reduce_out_imageB, mean_ImageB, RegionDynThresh, 10, 'dark')
        fill_up (RegionDynThresh, RegionFillUp1)
        opening_circle (RegionFillUp1, RegionOpening, 15)
        * 遍历拿到每一个产品判断灰度值
        gen_empty_obj (is_null)
        gen_empty_obj (is_error)
        count_obj (base_inner_cp_region, Number)
        for Index3 := 1 to Number by 1
            select_obj (base_inner_cp_region, select_region, Index3)
            intersection (select_region, RegionOpening, intersection_out_image)
            min_max_gray (intersection_out_image, image_reduce_out_imageB, 0, Min, Max, Range)
            area_center (intersection_out_image, Area3, Row1, Column1)
            * 判断是否为空
            
            if(Area3>0)
                if (Area3<3700 or Min<60)
                    concat_obj (is_error, intersection_out_image, is_error)
                    disp_message (WindowHandle, 'NG', 'window', 12, 600, 'red', 'true')
                endif
            else
                concat_obj (is_null, select_region, is_null)
                disp_message (WindowHandle, 'NG', 'window', 12, 600, 'red', 'true')
            endif
        endfor
        
        * 显示
        dev_display (show_image)
        dev_set_color ('green')
        dev_display (RegionOpening)
        count_obj (is_null, is_null_num)
        count_obj (is_error, is_error_num)
        dev_set_color ('red')
        dev_display (is_null)
        dev_display (is_error)
        stop ()
    endfor
    吾虽浪迹,却未迷失本心
  • 相关阅读:
    20200925--矩阵加法(奥赛一本通P93 6 多维数组)
    20200924--图像相似度(奥赛一本通P92 5多维数组)
    20200923--计算鞍点(奥赛一本通P91 4)
    20200922--计算矩阵边缘元素之和(奥赛一本通P91 3二维数组)
    20200921--同行列对角线的格(奥赛一本通P89 2 二维数组)
    磨人的.net core 3.1(二) DataReader的问题
    磨人的.net core 3.1(一) CORS的问题
    Vue SSR问题:返回的js打包文件为HTML文件
    axios与.net core API实现文件下载
    .Net Core API中基于System.Threading.Timer的定时任务
  • 原文地址:https://www.cnblogs.com/lddragon1/p/15786990.html
Copyright © 2011-2022 走看看