halcon_皮革

在这里插入图片描述
*

 This program demonstrates the use of the photometric stereo technique
* for the inspection of leather samples.
* Input are 4 images taken from a leather sample with light coming from
* different orientations.
* 
* Initialization
dev_update_off ()
dev_close_window ()
dev_open_window (0, 0, 640, 480, 'black', WindowHandle)
set_display_font (WindowHandle, 14, 'mono', 'true', 'false')
Message := 'Inspect leather samples using photometric stereo'
disp_message (WindowHandle, Message, 'window', 12, 12, 'black', 'true')
disp_continue_message (WindowHandle, 'black', 'true')
stop ()
* 
* Part 1
* 
* Show input images with different illumination
read_image (Images, 'photometric_stereo/leather_1_0' + [1:4])
for I := 1 to 4 by 1
    Message := 'Sample 1: Acquire image ' + I + ' of 4'
    select_obj (Images, ObjectSelected, I)
    dev_display (ObjectSelected)
    disp_message (WindowHandle, Message, 'window', 12, 12, 'black', 'true')
    wait_seconds (0.5)
endfor
* 
* 
* Apply photometric stereo to determine the albedo
Tilts := [6.1,95.0,-176.1,-86.8]
Slants := [41.4,42.6,41.7,40.9]
ResultType := ['gradient','albedo']
photometric_stereo (Images, HeightField, Gradient, Albedo, Slants, Tilts, ResultType, 'poisson', [], [])
* 
* Display the albedo image
dev_display (Albedo)
disp_message (WindowHandle, 'The defect is clearly visible in the albedo image', 'window', 12, 12, 'black', 'true')
disp_continue_message (WindowHandle, 'black', 'true')
stop ()
* 
* Detect defects
* 
var_threshold (Albedo, Region, 15, 15, 0.4, 0.4, 'light')
connection (Region, ConnectedRegions)
select_shape (ConnectedRegions, SelectedRegions, 'area', 'and', 10, 99999)
union1 (SelectedRegions, RegionUnion)
closing_circle (RegionUnion, RegionClosing, 3.5)
connection (RegionClosing, Defects)
area_center (Defects, Area, Row, Column)
gen_circle (Circle, Row, Column, gen_tuple_const(|Row|,sqrt(Area) + 30))
* Display the defects
dev_display (Albedo)
dev_set_color ('red')
dev_set_draw ('margin')
dev_set_line_width (4)
dev_display (Circle)
disp_message (WindowHandle, 'Albedo image with defect', 'window', 12, 12, 'black', 'true')
disp_continue_message (WindowHandle, 'black', 'true')
stop ()
* 
* Part 2
* 
* Show input images with different illumination
read_image (Images, 'photometric_stereo/leather_2_0' + [1:4])
for I := 1 to 4 by 1
    Message := 'Sample 2: Acquire image ' + I + ' of 4'
    select_obj (Images, ObjectSelected, I)
    dev_display (ObjectSelected)
    disp_message (WindowHandle, Message, 'window', 12, 12, 'black', 'true')
    wait_seconds (0.5)
endfor
* 
* 
* Apply photometric stereo to determine the albedo
photometric_stereo (Images, HeightField, Gradient, Albedo, Slants, Tilts, ResultType, 'poisson', [], [])
threshold (Albedo, Region1, 128, 255)
* 
* Display the albedo image
dev_display (Albedo)
Message := 'These defects are difficult to detect in the albedo image.'
Message[1] := 'Therefore, we use the gradient information to detect them.'
disp_message (WindowHandle, Message, 'window', 12, 12, 'black', 'true')
disp_continue_message (WindowHandle, 'black', 'true')
stop ()
* 
* Detect texture defects using gradient information.
* We are looking for areas with little surface changes.
* 
derivate_vector_field (Gradient, Curl, 1, 'curl')
derivate_gauss (Curl, CurlGradient, 1, 'gradient')
* 
* Display changes of the curl of the gradient field
dev_display (CurlGradient)
Message := 'Changes in the gradient curl'
disp_message (WindowHandle, Message, 'window', 12, 12, 'black', 'true')
disp_continue_message (WindowHandle, 'black', 'true')
stop ()
* 
* Detect texture defects
threshold (CurlGradient, Region, 0, 0.01)
rank_region (Region, RegionCount, 10, 10, 30)
connection (RegionCount, ConnectedRegions)
select_shape (ConnectedRegions, SelectedRegions, 'area', 'and', 2000, 99999)
union1 (SelectedRegions, RegionUnion)
rank_region (RegionUnion, RegionCount1, 25, 25, 170)
connection (RegionCount1, NoTextured)
* 
* Display texture defects
dev_display (Albedo)
dev_set_draw ('margin')
dev_set_color ('red')
dev_set_line_width (3)
dev_display (NoTextured)
disp_message (WindowHandle, 'Non-textured areas on leather', 'window', 12, 12, 'black', 'true')
stop ()
* 
* Detect scratches using curvature information.
* We are looking for areas with high curvature
* 
derivate_vector_field (Gradient, MeanCurvature, 1, 'mean_curvature')
* 
* Display the mean curvature of the surface
dev_display (MeanCurvature)
Message := 'Mean curvature of the surface'
disp_message (WindowHandle, Message, 'window', 12, 12, 'black', 'true')
disp_message (WindowHandle, 'Press F5', 'image', 720, 850, 'black', 'true')
stop ()
* 
* Detect scratches
abs_image (MeanCurvature, ImageAbs)
threshold (ImageAbs, Region2, 0.15, 255)
connection (Region2, ConnectedRegions1)
select_shape (ConnectedRegions1, SelectedRegions1, 'area', 'and', 10, 99999)
union1 (SelectedRegions1, RegionUnion1)
closing_circle (RegionUnion1, RegionClosing, 1.5)
connection (RegionClosing, ConnectedRegions2)
select_shape (ConnectedRegions2, SelectedRegions2, 'max_diameter', 'and', 50, 99999)
select_gray (SelectedRegions2, MeanCurvature, SelectedRegions3, 'deviation', 'and', 0.2, 255)
* 
* Display scratches
dev_display (Albedo)
dev_set_draw ('margin')
dev_set_color ('red')
dev_set_line_width (3)
dev_display (SelectedRegions3)
disp_message (WindowHandle, 'Deep scratch', 'window', 12, 12, 'black', 'true')
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值