博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
2016-06-17
阅读量:4915 次
发布时间:2019-06-11

本文共 4030 字,大约阅读时间需要 13 分钟。

* In this program the size of raw fish sticks is measured

* before they are coated with bread crumbs.
* First, the fish sticks are segmented from the background.
* Then, their dimensions are measured, compared to the
* required minimum size, and the result is displayed.
*

*设置不刷新

dev_update_off ()

*关闭显示窗口

dev_close_window ()

*读取图像

read_image (Image, 'food/fish_sticks_raw_01')

*打开一个显示窗口,-1,-1表示用上一次的窗口的大小

dev_open_window_fit_image (Image, 0, 0, -1, -1, WindowHandle)

*设置显示字体

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

*设置画图为空心

dev_set_draw ('margin')

*保存系统参数到一个临时变量,最后再把这个参数给还原过去

get_system ('store_empty_region', StoreEmptyRegion)

*设置系统参数 store_empty_region

set_system ('store_empty_region', 'true')
* 每像素的换算参数
cm_per_pix := 0.0373

*目标的长度

TargetLength := 9.0

*上公差是多少

ToleranceHigh := 0.8

*下公差是多少

ToleranceLow := 0.2
* 设置图像张数为10
NumImages := 10

*进行for循环

for I := 1 to NumImages by 1
read_image (Image, 'food/fish_sticks_raw_' + I$'.2')
*
* Segment the raw fish sticks 选择比较白的地方
threshold (Image, Region, 50, 255)
connection (Region, ConnectedRegions)
fill_up (ConnectedRegions, RegionFillUp)
select_shape (RegionFillUp, SelectedRegions, 'area', 'and', 1000, 99999)
*
* Select the regions that do not intersect the image border
boundary (Image, RegionBorder, 'inner')
intersection (SelectedRegions, RegionBorder, RegionIntersection)
area_center (RegionIntersection, Area, Row1, Column1)
ValidRegionIndices := find(Area,0) + 1
if (ValidRegionIndices[0] == 0)
ValidRegionIndices := []
endif
select_tuple_larger (Area, 0.0, RegionAtBorderIndices)
RegionAtBorderIndices := RegionAtBorderIndices + 1
select_obj (SelectedRegions, ValidSticks, ValidRegionIndices)
select_obj (SelectedRegions, StickAtBorder, RegionAtBorderIndices)
*
* Check the size of the fish sticks
smallest_rectangle2 (ValidSticks, Row, Column, Phi, Length1, Length2)
FishLength1 := Length1 * 2 * cm_per_pix
select_tuple_larger (FishLength1, TargetLength - ToleranceLow, IndicesGood)
select_tuple_larger (FishLength1, TargetLength + ToleranceHigh, IndicesBad1)
tuple_remove (IndicesGood, IndicesBad1, IndicesGood)
select_tuple_larger (-FishLength1, -(TargetLength - ToleranceLow), IndicesBad2)
IndicesBad := [IndicesBad1,IndicesBad2]
RowGood := subset(Row,IndicesGood)
ColumnGood := subset(Column,IndicesGood)
RowBad := subset(Row,IndicesBad)
ColumnBad := subset(Column,IndicesBad)
FishLength1Good := subset(FishLength1,IndicesGood)
FishLength1Bad := subset(FishLength1,IndicesBad)
if (|IndicesGood| > 0)
gen_rectangle2 (GoodSticks, RowGood, ColumnGood, subset(Phi,IndicesGood), subset(Length1,IndicesGood), subset(Length2,IndicesGood))
else
gen_empty_obj (GoodSticks)
endif
if (|IndicesBad| > 0)
gen_rectangle2 (BadSticks, RowBad, ColumnBad, subset(Phi,IndicesBad), subset(Length1,IndicesBad), subset(Length2,IndicesBad))
else
gen_empty_obj (BadSticks)
endif
*
* Display the results
dev_display (Image)
dev_set_color ('white')
dev_set_line_width (1)
dev_display (ValidSticks)
dev_set_line_width (3)
dev_set_color ('yellow')
dev_display (StickAtBorder)
dev_set_color ('green')
dev_display (GoodSticks)
dev_set_color ('red')
dev_display (BadSticks)
String := 'Target length: ' + TargetLength$'.1f' + ' cm'
String[1] := 'Tolerance: -' + ToleranceLow$'.1f' + '/+' + ToleranceHigh$'.1f'
disp_message (WindowHandle, String, 'window', 12, 12, 'black', 'true')
for J := 0 to |IndicesGood| - 1 by 1
disp_message (WindowHandle, 'OK', 'image', 80, ColumnGood[J] - 10, 'green', 'false')
disp_message (WindowHandle, FishLength1Good[J]$'.1f' + 'cm', 'image', RowGood[J], ColumnGood[J] - 28, 'white', 'false')
endfor
for J := 0 to |IndicesBad| - 1 by 1
disp_message (WindowHandle, 'Not OK', 'image', 80, ColumnBad[J] - 30, 'red', 'false')
disp_message (WindowHandle, FishLength1Bad[J]$'.1f' + 'cm', 'image', RowBad[J], ColumnBad[J] - 28, 'white', 'false')
endfor
if (I != NumImages)
disp_continue_message (WindowHandle, 'black', 'true')
stop ()
endif
endfor
set_system ('store_empty_region', StoreEmptyRegion)

转载于:https://www.cnblogs.com/LongHuaiYu/p/5595177.html

你可能感兴趣的文章
344
查看>>
C - Jungle Roads
查看>>
HTML
查看>>
python之猜年纪
查看>>
Github个人主页不显示提交记录的问题
查看>>
java两个栈实现一个队列&&两个队列实现一个栈
查看>>
entityFramework 中decimal精度缺失问题
查看>>
获取webconfig配置文件内容
查看>>
C# 字符串替换第一次或者最后一次出现的匹配项
查看>>
Linux终端查看端口号command
查看>>
《攻城Online》开发前期:UML设计架构
查看>>
HBase简介及集群安装
查看>>
springboot部署到tomcat
查看>>
jquery-ajax之4:无刷新 select 数据源及事件绑定(2)
查看>>
(六)Hive的高级操作
查看>>
java并发阻塞队列
查看>>
poj 2449 Remmarguts' Date 求第k短路 Astar算法
查看>>
lightoj1063【求割点】
查看>>
C#是怎么获取窗口标题的
查看>>
LeetCode 24 Swap Nodes in Pairs
查看>>