HALCON基础知识
HALCON
1.?語(yǔ)法范式?Syntax?Style?
1.1.?基本格式
1.1.1.?算子格式
算子(輸入圖像參數(shù):輸出圖像參數(shù):輸入控制參數(shù):輸出控制參數(shù))
其中四個(gè)參數(shù)任意一個(gè)可以為空
e.g.1.threshold(Image?:?Region?:?MinGray,?MaxGray?:?)?
**?threshold算子,1?Image?Para?input?:?Image?;?2?Image?Para?output?:Region?;?
**3?Control?Para?input?:?MinGray?,??MaxGray?4?Control?Para?output?:無(wú)
2.get_image_pointer1(Image?:?:?:?Pointer,?Type,?Width,?Height)?
**?threshold算子,1?Image?Para?input?:?Image?;?2?Image?Para?output?:無(wú);?
**??3?Control?Para?input?:?無(wú)?4?Control?Para?output?:?Pointer,?Type,?Width,?Height
1.1.2.?程序結(jié)構(gòu)
HDEV即HALCON?Develop,相當(dāng)于VC中sln,solution。dev下面有很多窗口。
l?dev_update_pc
Switches?the?update?of?the?PC?during?program?execution?on?or?off.
l?dev_update_time
Switch?time?measurement?for?operators?on?or?off.
l?dev_update_var
Switches?the?update?of?the?variable?window?during?program?execution?on?or?off.
l?dev_update_window
Switches?the?automatic?output?of?iconic?output?objects?into?the?graphics?window?during?program?execution?on?or?off.?
1.1.3.?符號(hào)
這里主要列出一些和C/C++含義不同的符號(hào),以及HALCON中一些重要符號(hào)。
| 編號(hào) | 符號(hào) | 符號(hào)含義 |
| 1 | * | 注釋符號(hào) |
| 2 | := | 賦值符號(hào),和C中不同 |
| 3 | = | 邏輯符號(hào),判斷相等,相對(duì)于C中的’==’ |
| 4 | \ | 轉(zhuǎn)義符號(hào),至少可以在用于換行的轉(zhuǎn)義,’\+Enter’就可以續(xù)行了 |
| 5 | $ | 變量指示符號(hào),e.g.?+Distance$'.3'表示將變量Distance寫(xiě)成3個(gè)字長(zhǎng)的字符串形式 |
| 6 | F1 | Help文檔,直接看算子 |
| 7 | F2 | 回滾到程序頭 |
| 8 | F3/F4 | 激活/注銷(xiāo)此行代碼 |
| 9 | F5 | 運(yùn)行程序 |
| 10 | F6 | 單步執(zhí)行 |
| 11 | F10 | 設(shè)置斷點(diǎn) |
1.2.?讀寫(xiě)文件I/O
1.2.1.??控制變量的I/O
HACLON的輸入,輸出寫(xiě)法相當(dāng)靈活。下面三個(gè)列子分別是常量字符串,格式化的浮點(diǎn)數(shù),和一個(gè)tuple的輸出
*字符串和單個(gè)浮點(diǎn)數(shù)的輸出,甚至不需要fnew_line來(lái)寫(xiě)下一行,直接用\n,在一般的文本編輯器里就能有比較好的格式。?注意不用寫(xiě)百分號(hào)'%d''d','?3d'表示始終為3位輸出,'10.3f'表示始終為10位輸出,其中小數(shù)位占3位
fwrite_string(FileHandle,'\tR1\tx1\ty1\tR2\tx2\ty2\td1\td2\td3\n')
fwrite_string(FileHandle,?'\n'+i$'d'+'?'+R1$'10.3f'+x1$'10.3f'+y1$'10.3f'+\
???????????????????R2$'10.3f'+x2$'10.3f'+y2$'10.3f'+\
??????????????????d1$'10.3f'+d2$'10.3f'+d3$'10.3f')
*在同一行中輸出按'7.3f'的格式輸出UpRows的所有元素,元素之間有個(gè)空格
fnew_line(FileHandle)
fwrite_string(FileHandle,UpRows$'7.3f'+'?')?/
1.2.2.??圖像變量的I/O
Path:=?'I:/Work/ritz/Piece/data/data_0528/'
read_image?(Image,?Path+'hgtest1__'+i$'d')
dump_window?(WindowHandle,?'png',?'C:/Documents?and?Settings/Administrator/桌面/sadaharu2_gray.png')
write_image?(Amp,?'png',?0?,?'C:/Documents?and?Settings/Administrator/桌面/sadaharu2_canny2.png')
write_region(Margin,'C:/Documents?and?Settings/Administrator/桌面/sadaharu2_canny3.tif')?
1.3.?圖像或形狀的生成與顯示
這條主要是為了區(qū)分三個(gè)系列的函數(shù),gen_?,?draw_?和?disp_
l?gen_??gen系列跨度很大,一般屬于Creation范疇,生成的可以是圖像image,匹配模板model,區(qū)域region,輪廓Contour,亞像素級(jí)輪廓Contour?XLD,濾波器filter,HALCON內(nèi)部描述文件descr(如標(biāo)定板的表述caltab10mm.descr)等。下面展示的是一些容易混淆的gen_circle等,都是生成區(qū)域,屬于Table?of?Contents/Regions/Creation:
gen_circle
Create?a?circle.
gen_ellipse
Create?an?ellipse.
gen_rectangle2
Create?a?rectangle?of?any?orientation.
以畫(huà)圓為例,含有Row,Col,R,且這些都是輸入量:
gen_circle(?:?Circle?:?Row,?Column,?Radius?:?)?
l?draw_?屬于Table?of?Contents/Graphics/Drawing和我們平常理解的不同,這里的draw是指交互式地在窗口上畫(huà)圖,而不是直接按參數(shù)畫(huà)圖
draw_circle
Interactive?drawing?of?a?circle.
draw_ellipse
Interactive?drawing?of?an?ellipse.
draw_line
Draw?a?line.
以畫(huà)圓為例,雖然也有Row,Col,R,但這些都是輸出量:
draw_circle(?:?:?WindowHandle?:?Row,?Column,?Radius)?
l?disp_?屬于Table?of?Contents/Graphics/Output
disp_arc
Displays?circular?arcs?in?a?window.輸出顯示一段弧
disp_arrow
Displays?arrows?in?a?window.輸出顯示一個(gè)箭頭
disp_circle
Displays?circles?in?a?window.
disp_cross
Displays?crosses?in?a?window.
以畫(huà)弧為例,雖然也有CRow,CCol,而且這些都是輸入的控制參數(shù):
disp_arc(?:?:?WindowHandle,?CenterRow,?CenterCol,?Angle,?BeginRow,?BeginCol?:?)?
2.?數(shù)據(jù)結(jié)構(gòu)?Data?Structure
2.1.?Tuple元組
HALCON中的元組是一個(gè)涵蓋范圍很廣的數(shù)據(jù)結(jié)構(gòu),可以表示各種整形浮點(diǎn),也可以表示字符串。
2.1.1.?tuple的函數(shù)
① Tuple的長(zhǎng)度
tuple_length(?:?:?Tuple?:?Length)?
e.g.tuple_length(?RowsEdges,?LengthEdge),還有一種更簡(jiǎn)單的方法,
② Tuple按index取元素
tuple_select(?:?:?Tuple,?Index?:?Selected)?
e.g.tuple_select(?RowsEdges,?0,RowSelectedPoint)
tuple_select_range(?:?:?Tuple,?Leftindex,?Rightindex?:?Selected)?
?Select?several?elements?of?a?tuple?between?the?left?index?and?the?right?index.
③ Tuple的初始化,包含分配內(nèi)存需要的長(zhǎng)度以及初始值
tuple_gen_const
gen_tuple_const(NumHoles,0)
2.1.2.?tuple的操作符
tuple的操作除了調(diào)用函數(shù),還可以直接訪問(wèn)元素,或者使用操作符
① Tuple的長(zhǎng)度
Length:=?|Tuple|
e.g.LengthEdge1?:=?|RowsEdges|?
② Tuple按index取元素
e.g.RowSelectedPoint?:=?RowsEdges[0]
2.2.?常見(jiàn)圖像變量數(shù)據(jù)結(jié)構(gòu)及相互轉(zhuǎn)換:
Image,Region,?Contour?,XLD,幾何圖形
2.2.1.?Image??Region
① Image??Region
?threshold(Image?:?Region?:?MinGray,?MaxGray?:?)
Bin_threshold,char_threshold,dual_threshold,dyn_threshold,fast_threshold,hysteresis_threshold,threshold_sub_pix
var_threshold?Threshold?an?image?by?local?mean?and?standard?deviation?analysis
watersheds_threshold—?Extract?watershed?basins?from?an?image?using?a?threshold.
② Image??Region
reduce_domain(Image,?Region?:?ImageReduced?:?:?)?
Reduce?the?domain?of?an?image.提取ROI中的圖像部分
region_to_bin(Region?:?BinImage?:?ForegroundGray,?BackgroundGray,?Width,?Height?:?)?
Convert?a?region?into?a?binary?byte-image。將區(qū)域轉(zhuǎn)化為二值圖
region_to_label(Region?:?ImageLabel?:?Type,?Width,?Height?:?)?Convert?regions?to?a?label?image.
region_to_mean(Regions,?Image?:?ImageMean?:?:?)?
?Paint?regions?with?their?average?gray?value.??結(jié)合原圖Image將區(qū)域內(nèi)所有像素點(diǎn)轉(zhuǎn)換為它的中值。
2.2.2.?Region??Contour?
① Region??Contour?
?
gen_circle_contour_xld
Create?XLD?contours?corresponding?to?circles?or?circular?arcs.
gen_contour_nurbs_xld
Transforms?a?NURBS?curve?into?an?XLD?contour.
gen_contour_polygon_rounded_xld
Generate?a?XLD?contour?with?rounded?corners?from?a?polygon?(given?as?tuples).
gen_contour_polygon_xld
Generate?an?XLD?contour?from?a?polygon?(given?as?tuples).
gen_contour_region_xld
Generate?XLD?contours?from?regions.
gen_contours_skeleton_xld
Convert?a?skeleton?into?XLD?contours.
gen_cross_contour_xld
Generate?one?XLD?contour?in?the?shape?of?a?cross?for?each?input?point.
gen_ellipse_contour_xld
Creation?of?an?XLD?contour?corresponding?to?an?elliptic?arc.
gen_nurbs_interp
Create?control?data?of?a?NURBS?curve?that?interpolates?given?points.
gen_parallels_xld
Extract?parallel?XLD?polygons.
gen_polygons_xld
Approximate?XLD?contours?by?polygons.
gen_rectangle2_contour_xld
Create?an?XLD?contour?in?the?shape?of?a?rectangle.
mod_parallels_xld
Extract?parallel?XLD?polygons?enclosing?a?homogeneous?area.
?
3.?函數(shù)理解?Understanding?the?Basic?but?Essential?Functions
3.1.?edges_sub_pix
edges_sub_pix?(Image,?Edges,?'canny',?0.9,?20,?40)
edges_sub_pix(Image?:?Edges?:?Filter,?Alpha,?Low,?High?:?)?
主要介紹Canny邊緣檢測(cè),同hysteresis_threshold,Canny邊緣檢測(cè)時(shí)不是單個(gè)閾值,而是有個(gè)“遲滯效應(yīng)”設(shè)置了雙閾值。
hysteresis_threshold?performs?a?hysteresis?threshold?operation?(introduced?by?Canny)?on?an?image.?All?points?in?the?input?image?Image?having?a?gray?value?larger?than?or?equal?to?High?are?immediately?accepted?(“secure”?points).?Conversely,?all?points?with?gray?values?less?than?Low?are?immediately?rejected.?“Potential”?points?with?gray?values?between?both?thresholds?are?accepted?if?they?are?connected?to?“secure”?points?by?a?path?of?“potential”?points?having?a?length?of?at?most?MaxLength?points.?This?means?that?“secure”?points?influence?their?surroundings?(hysteresis).
4.?經(jīng)驗(yàn)談?Special?Tips
4.1.?多使用help?文檔中的Content?Table:有問(wèn)題何不往上翻一級(jí)
“不是路上真面目,只緣身在此山中”。解決一個(gè)問(wèn)題,就和了解一個(gè)山峰所有真正的登山路一樣,當(dāng)我們?cè)谏窖袝r(shí),自然是很難了解這條路是否能直通山頂?shù)?#xff0c;而當(dāng)我們處在一個(gè)比這座峰更高的一個(gè)位置時(shí),很自然就可以觀察或者自己構(gòu)造出一條比較好的登山路。這就是看往上一級(jí),才看Content?Table的作用,在這樣一個(gè)更高的視野我們就可以找到在這個(gè)范圍內(nèi)的其他的路,也許剛好可以登上這座峰。如:
Table?of?Contents/Filter/smooth_image,
eliminate_min_max?:?Smooth?an?image?in?the?spatial?domain?to?suppress?noise.
?
?
轉(zhuǎn)載于:https://www.cnblogs.com/ouxiaogu/p/3319600.html
總結(jié)
以上是生活随笔為你收集整理的HALCON基础知识的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: Project: Individual
- 下一篇: 特殊的字符数组