印刷网格校正后比较图片缺陷的例子 grid_rectification

* This example program shows how the grid rectification
* can be used to generate arbitrary distortion maps based on
* self-defined grids.

* The example application is a print inspection.
* It is assumed that only distortions in the vertical direction
* of the printed document are present, which could,
* e.g., be caused by an inaccurate paper transport.
* These distortions are determined and applied
* to the reference image. Then the test image is compared
* with the distorted reference image.

* The example program uses component-based matching for the
* determination of the corresponding points in the test and
* the reference image. Then, it generates a distorted grid
* from which the rectification map is derived.
假定 在垂直方向上 的扭曲
* Read and preprocess images
dev_close_window ()
ImgPath := '3d_machine_vision/grid_rectification/'
read_image (ImageRef, ImgPath+'document_original')
get_image_size (ImageRef, WidthRef, HeightRef)
dev_open_window_fit_image (ImageRef, 0, 0, 600, 600, WindowHandleRef)
dev_display (ImageRef)
dev_open_window (0, 600*WidthRef/HeightRef+8, 50, 50, 'black', WindowHandleTest)
准备 确定 对应点 基于组件的 匹配
* Prepare the determine of corresponding points by component based matching
prepare_determination_of_corresponding_points (ImageRef, RootRanking, ComponentModelID, RowCompRef, ColumnCompRef, UpperRow, LowerRow, DRowUpper, DRowLower)
disp_continue_message (WindowHandleRef, 'black', 'true')
stop ()

* Online phase
for ImgNum := 1 to 2 by 1
    read_image (ImageTest, ImgPath+'document_distorted_'+ImgNum$'02d')
    get_image_size (ImageTest, WidthTest, HeightTest)
    dev_open_window_fit_image (ImageRef, 0, 600*WidthRef/HeightRef+8, 600, 600, WindowHandleTest)
    dev_display (ImageTest)
    determine_corresponding_points (ImageTest, ComponentMarkers, DistortionMarkers, ComponentModelID, RootRanking, DRowUpper, DRowLower, UpperRow, LowerRow, ColumnCompRef, RowRef, ColRef, RowTest, ColTest)
    dev_set_color ('green')
    dev_display (ComponentMarkers)
    dev_set_color ('orange red')
    dev_display (DistortionMarkers)
    disp_continue_message (WindowHandleRef, 'black', 'true')
    stop ()
    *  确定 扭曲的 网格 点的坐标
    * Determine coordinates of distorted grid points
    GridSpacing := 10
    ColShift := mean(ColTest-ColRef)
    RefGridColValues := []
    for HelpCol := -0.5 to WidthTest+GridSpacing by GridSpacing
        RefGridColValues := [RefGridColValues, HelpCol+ColShift]
    endfor
    MinValue := 0
    MaxValue := HeightTest+GridSpacing
    sample_corresponding_values (RowTest, RowRef-0.5, MinValue, MaxValue, GridSpacing, RefGridRowValues)
    RefGridRow := []
    RefGridCol := []
    dev_update_off ()
    Ones := gen_tuple_const(|RefGridColValues|, 1)
    for r := 0 to |RefGridRowValues|-1 by 1
        RefGridRow := [RefGridRow, RefGridRowValues[r]*Ones]
        RefGridCol := [RefGridCol, RefGridColValues]
    endfor
    dev_update_on ()
    * 

    stop()

*生成扭曲的网格畸变的map

    * Generate distortion map from distorted grid
    gen_arbitrary_distortion_map (Map, GridSpacing, RefGridRow, RefGridCol, |RefGridColValues|, WidthRef, HeightRef, 'bilinear')
    * 
    * Map test image and compare it to reference image
    map_image (ImageRef, Map, ImageMapped)
    crop_part (ImageMapped, ImagePart, 0, 0, WidthTest, HeightTest)
    sub_image (ImagePart, ImageTest, ImageSub, 1, 128)
    dev_display (ImageSub)
    disp_continue_message (WindowHandleRef, 'black', 'true')
    stop ()
    * 
    * Visualize  differences
    MinDev := 100

    MinSize := 5

**可视化差异

    visualize_differences (ImageSub, ImageTest, ComponentMarkers, DistortionMarkers, MinDev, MinSize, 1)
    disp_continue_message (WindowHandleRef, 'black', 'true')
    stop ()
endfor
clear_component_model (ComponentModelID)
dev_update_window ('on')
dev_set_draw ('fill')
dev_close_window ()
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值