機(jī)器視覺之halcon中的數(shù)據(jù)類型與語法結(jié)構(gòu)_第1頁
機(jī)器視覺之halcon中的數(shù)據(jù)類型與語法結(jié)構(gòu)_第2頁
機(jī)器視覺之halcon中的數(shù)據(jù)類型與語法結(jié)構(gòu)_第3頁
機(jī)器視覺之halcon中的數(shù)據(jù)類型與語法結(jié)構(gòu)_第4頁
機(jī)器視覺之halcon中的數(shù)據(jù)類型與語法結(jié)構(gòu)_第5頁
已閱讀5頁,還剩6頁未讀, 繼續(xù)免費(fèi)閱讀

下載本文檔

版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)

文檔簡(jiǎn)介

1、深圳稻草人自動(dòng)化培訓(xùn) 聯(lián)為智能教育halcon中的數(shù)據(jù)類型與語法結(jié)構(gòu)圖像預(yù)處理消除噪聲mean_image/binomial_filter抑制小斑點(diǎn)或細(xì)線median_image平滑圖像smooth_image平滑圖像的同時(shí)保存邊緣anisotropic_diffusion遍歷文件夾與文件選擇1)遍歷文件夾:list_files( : : Directory, Options : Files)Directory:目錄(文件夾路徑)Options:選項(xiàng)files指定搜索的格式為文件directories指定搜索的格式為文件夾recursive指定可以遍歷子文件夾下的文件follow_linksm

2、ax_depth 5指定遍歷的深度max_files 1000指定遍歷的最大文件數(shù)目Files:文件(文件的路徑)2)文件格式篩選tuple_regexp_select( : : Data, Expression : Selection)Data:被選擇的文件路徑數(shù)組Expression:文件格式的篩選規(guī)則/.轉(zhuǎn)義 .(bmp|JPG)篩選的文件格式ignore_case忽略大小寫Selection:選擇出的文件路徑數(shù)組示例: 1: * 遍歷文件夾D:/資料庫/Downloads 2: list_files (D:/資料庫/Downloads, files,follow_links, Imag

3、eFiles) 3: 4: * 篩選bmp或jpg格式的文件 5: tuple_regexp_select (ImageFiles, .(bmp|jpg)$,ignore_case, ImageFiles) 6: 7: * 依次讀取圖片 8: for Index := 0 to |ImageFiles| - 1 by 1 9: read_image (Image, ImageFilesIndex) 10: 11: endfor/(一)Halcon的語法結(jié)構(gòu)特點(diǎn)類似于Pascal 與 Visual Basic,大部分的語句是Halcon提供的算子,此外也包含了少部分的控制語句;不允許單獨(dú)聲明變量

4、;提供自動(dòng)的內(nèi)存管理(初始化、析構(gòu)及OverWrite),但句柄則需要顯示釋放;C+(算子模式)通過代碼導(dǎo)出,以C+為例,默認(rèn)導(dǎo)出為算子型的語法結(jié)構(gòu),而非面向?qū)ο蟮?;在此模式下,全部函?shù)聲明為全局類型,數(shù)據(jù)類型只需要用Hobject、HTuple兩類類型進(jìn)行聲明;C+(面向?qū)ο螅┛梢砸悦嫦驅(qū)ο蟮姆绞街貙懘a,也即利用類及類的成員函數(shù);在這種模式下,控制變量的類型仍未HTuple,而圖形數(shù)據(jù)可以由多種類型,如HImage等;其他語言(略)HImage 可以查看halcon中類相關(guān)的內(nèi)容(二)Halcon的數(shù)據(jù)類型兩類參數(shù):1、圖形參數(shù)Iconic(image, region, XLD)2、與控制

5、參數(shù)Control(string, integer, real, handle),在Halcon算子的參數(shù)中,依次為:輸入圖形參數(shù)、輸出圖形參數(shù)、輸入控制參數(shù)、輸出控制參數(shù);并且其輸入?yún)?shù)不會(huì)被算子改變。1、圖形參數(shù)Iconic:(1)Images在Halcon中,Image = Channel + Domain , 像素點(diǎn)存放在Channel矩陣中,根據(jù)ROI來描述Image。Image相關(guān)操作:輸入:從文件、從設(shè)備生成:外部圖像數(shù)據(jù)、空內(nèi)存區(qū)域;顯示:disp_image()圖像首通道灰度圖;disp_color() 彩色圖;disp_channel()某特定通道;disp_obj() 自

6、動(dòng)判別類別;縮放:set_part() 設(shè)置顯示區(qū)域;set_part_style() 設(shè)置顯示參數(shù);說明: Multiple channels /多通道圖像,可以是灰度圖像或RGB圖像 Arbitrary region of interest /ROI區(qū)域圖像 Multiple pixel types(byte, (u)int1/2/4,real, complex, direction, cyclic, vector_field)byte, uint2 /灰度圖像的標(biāo)準(zhǔn)編碼int1, int2 /Difference of two images or derivates with integ

7、er precision(?)int4 /兩幅灰度圖的頻譜direction /圖片邊緣的梯度方向real /邊緣提取及特定灰度值的輪廓complex /圖片頻率分布cyclic /Assigning one gray value to each color(?)vector_field /連續(xù)圖形的光學(xué)流分布(2)Regions以行列坐標(biāo)形式儲(chǔ)存,有廣泛的應(yīng)用,特點(diǎn)是高效,可利用同態(tài)算子。比如用閾值對(duì)圖像分割的結(jié)果,其他系統(tǒng)中稱為BOLB,AREA等。(3)ExtendedLineDescription (XLD)圖像均用像素點(diǎn)保存,而像素點(diǎn)是整型的,不連續(xù)的,Halcon做了拓展,定義了亞

8、像素(subpixel)的描述幾何輪廓的對(duì)象:xld,主要用在亞像素測(cè)量的背景下,可用于如提取邊緣、構(gòu)建輪廓等等,xld在模板匹配、圖形校準(zhǔn)等多方面有重要的用途。說明:Subpixel accurate line and edge detection(亞像素精度的線和邊緣檢測(cè))Generic point list based data structure(依據(jù)數(shù)據(jù)結(jié)構(gòu)產(chǎn)生點(diǎn)的表)Handling of contours, polygons, lines, parallels, etc.(對(duì)輪廓,多邊形,線等進(jìn)行操作)2、控制參數(shù)Control:String類型變量由單引號(hào)括起來;此外還有一些特

9、殊字符;Boolean型變量包括 true ( = 1 )、 false ( = 0 ) ;不為零的整數(shù)將被認(rèn)為true;但絕大多數(shù)的Halcon函數(shù)接受字符串型的表達(dá):truefalse,而非邏輯型表達(dá);此外,Halcon支持的類型還包括圖形元組、控制變量元組及句柄:元組的概念,使得可以用一個(gè)變量傳遞數(shù)個(gè)對(duì)象,可以由重載后的函數(shù)來進(jìn)行處理;圖形元組的下標(biāo)從1開始,控制變量元組下標(biāo)從0開始;句柄則可以用來描述窗體、文件等等,句柄不能是常量。(三)Halcon的基本語句1、標(biāo)準(zhǔn)賦值 assign(Input, Result) /編輯形式,永遠(yuǎn)都是輸入在前,輸出在后 1: assign(sin(x

10、) + cos(y), u) Result := Input /代碼形式 1: u := sin(x) + cos(y) /與之前的assign(sin(x) + cos(y), u)是等價(jià)的2、元組插入賦值 insert(Tuple, NewValue, Index, Tuple) /編輯形式 1: Tuple := 1,2,3,4,5,6,7,8,9 2: insert(Tuple,0,3,Tuple)顯示結(jié)果為:1, 2, 3,0, 5, 6, 7, 8, 9 TupleIndex := NewValue /代碼形式 1: Tuple := 1,2,3,4,5,6,7,8,9 2: Tu

11、ple3:=0顯示結(jié)果為:1, 2, 3,0, 5, 6, 7, 8, 9例程: 1: read_image (Mreut, mreut) /讀入圖像 2: threshold (Mreut, Region, 190, 255) /閾值化,輸出閾值在190-255的Regions 3: Areas := /定義數(shù)組Areas 4: for Radius := 1 to 50 by 1 /循環(huán) 5: dilation_circle (Region, RegionDilation, Radius) /利用半徑為Radius的圓對(duì)Region進(jìn)行膨脹運(yùn)算,輸出 6: /RegionDilation,

12、輸出形式仍然為Region。 7: area_center (RegionDilation, Area, Row, Column) /輸出區(qū)域的面積和中心像素坐標(biāo) 8: AreasRadius-1 := Area /對(duì)數(shù)組Areas的第Radius-1個(gè)元素進(jìn)行賦值 9: endfor3、基本數(shù)組操作極其對(duì)應(yīng)的算子數(shù)組操作說明對(duì)應(yīng)的算子t := t1,t2t1,t2連接成新的數(shù)組tuple_concati := |t|得到數(shù)組長(zhǎng)度tuple_lengthv := ti選取第i個(gè)元素0= i |t|tuple_selectt := ti1:i2選取i1到i2的元素tuple_select_ran

13、get := subset(t,i)選取數(shù)組t中的第i個(gè)元素tuple_selectt := remove(t,i)去除數(shù)組t中的第i個(gè)元素tuple_removei := find(t1,t2)找到t2數(shù)組在t1數(shù)組中出現(xiàn)位置索引(or -1 if no match)tuple_findt := uniq(t)在t數(shù)組中把連續(xù)相同的值只保留一個(gè)tuple_uniq4、創(chuàng)建數(shù)組(1)gen_tuple_const函數(shù) 1: tuple_old := gen_tuple_const(100,666) /創(chuàng)建一個(gè)具有100個(gè)元素的,每個(gè)元素都為666的數(shù)組 2: tuple_new := gen_

14、tuple_const(|tuple_old|,4711) /創(chuàng)建一個(gè)和原來數(shù)據(jù)長(zhǎng)度一樣的,每個(gè)元素為4711的數(shù)組上面的函數(shù)也可以通過如下表達(dá)式實(shí)現(xiàn):tuple_new := (tuple_old * 0) + 4711(2)當(dāng)數(shù)組中的元素不同時(shí),需要用循環(huán)語句對(duì)數(shù)組中的每一個(gè)元素賦值例如: 1: tuple := /創(chuàng)建空數(shù)組 2: for i := 1 to 100 by 1 /建立步長(zhǎng)為1的循環(huán) 3: tuple := tuple,i*i /將i方的值賦給數(shù)組的第i個(gè)元素 4: endfor /循環(huán)結(jié)束算術(shù)運(yùn)算 a / a division a % a rest of the inte

15、ger division a * a multiplication v + v addition and concatenation of strings a - a subtraction -a negation位運(yùn)算 lsh(i,i) left shift rsh(i,i) right shift i band i bit-wise and i bor i bit-wise or i bxor i bit-wise xor bnot i bit-wise complement字符串操作 v$s conversion to string /字符串的格式化,有很豐富的參數(shù) v + v conc

16、atenation of strings and addition strchr(s,s) search character in string strstr(s,s) search substring strrchr(s,s) search character in string (reverse) strrstr(s,s) search substring (reverse) strlen(s) length of string si selection of one character si:i selection of substring split(s,s) splitting to

17、 substrings比較操作符 t t greater than t = t greater or equal t = t equal t # t not equal邏輯操作符 lnot l negation l and l logical and l or l logical or l xor l logical xor數(shù)學(xué)函數(shù) sin(a) sine of a cos(a) cosine of a tan(a) tangent of a asin(a) arc sine of a in the interval -p/2, p/ 2, a -1, 1 acos(a) arc cosine

18、 a in the interval -p/2, p/2, a -1, 1 atan(a) arc tangent a in the interval -p/2, p/2, a -1, 1 atan2(a,b) arc tangent a/b in the interval -p, p sinh(a) hyperbolic sine of a cosh(a) hyperbolic cosine of a tanh(a) hyperbolic tangent of a exp(a) exponential function log(a) natural logarithm, a 0 log10(

19、a) decade logarithm, a 0 pow(a1,a2) power ldexp(a1,a2) a1 pow(2,a2)其他操作(統(tǒng)計(jì)、隨機(jī)數(shù)、符號(hào)函數(shù)等) min(t) minimum value of the tuple max(t) maximum value of the tuple min2(t1,t2) element-wise minimum of two tuples max2(t1,t2) element-wise maximum of two tuples find(t1,t2) indices of all occurrences of t1 within

20、t2 rand(i) create random values from 0.1 (number specified by i) sgn(a) element-wise sign of a tuple sum(t) sum of all elements or string concatenation cumul(t) cumulative histogram of a tuple mean(a) mean value deviation(a) standard deviation sqrt(a) square root of a deg(a) convert radians to degre

21、es rad(a) convert degrees to radians real(a) convert integer to real int(a) convert a real to integer round(a) convert real to integer number(v) convert string to a number is_number(v) test if value is a number abs(a) absolute value of a (integer or real) fabs(a) absolute value of a (always real) ce

22、il(a) smallest integer value not smaller than a floor(a) largest integer value not greater than a fmod(a1,a2) fractional part of a1/a2, with the same sign as a1 sort(t) sorting in increasing order uniq(t) eliminate duplicates of neighboring values(typically used in combination with sort) sort_index(

23、t) return index instead of values median(t) Median value of a tuple (numbers) select_rank(t,v) Select the element (number) with the given rank inverse(t) reverse the order of the values subset(t1,t2) selection from t1 by indices in t2 remove(t1,t2) Remove of values with the given indices environment

24、(s) value of an environment variable ord(a) ASCII number of a character chr(a) convert an ASCII number to a character ords(s) ASCII number of a tuple of strings chrt(i) convert a tuple of integers into a string(四)HDevelop language(結(jié)構(gòu)語句)1) if . endif / if . else . endif / if . elseif . else . endif2)

25、 for . endfor3) while . endwhile4) repeat . until(循環(huán)體至少被執(zhí)行一次,直到滿足條件時(shí)退出。等同于C語言的do.while語句)此外,也有關(guān)鍵字 break、continue、return、exit、stop 用來控制語句的執(zhí)行;stop:終止后面的循環(huán),點(diǎn)擊Step Over or Run button繼續(xù)。exit:終止Hdevelop程序段。(五)異常處理異常處理:try . catch . endtry:異常算子處理句柄throw:允許處理用戶定義的意外情況。用MFC寫的,我在捕獲異常提時(shí)候,都需要在前面使用HException:Ins

26、tallHHandler(&CPPExpDefaultExceptionHandler);才能全try.catch(HException &except). 生效在VC中其實(shí)是靠不住的。例如下面的代碼:1. try2. 3. BYTE*pch;4. pch=(BYTE*)00001234;/ 給予一個(gè)非法地址5.6. *pch=6;/ 對(duì)非法地址賦值,會(huì)造成Access Violation 異常7. 8. /.是捕捉任意類型的異常.9. catch(.)10. 11. AfxMessageBox(catched);12. 這段代碼在debug下沒有問題,異常會(huì)被捕獲,會(huì)彈出”catched”的

27、消息框。但在Release方式下如果選擇了編譯器代碼優(yōu)化選項(xiàng),則 VC編譯器會(huì)去搜索try塊中的代碼, 如果沒有找到throw代碼,他就會(huì)認(rèn)為try catch結(jié)構(gòu)是多余的, 給優(yōu)化掉。這樣造成在Release模式下,上述代碼中的異常不能被捕獲,從而迫使程序彈出錯(cuò)誤提示框退出。那么能否在release代碼優(yōu)化狀態(tài)下捕獲這個(gè)異常呢, 答案是有的。 就是_try, _except結(jié)構(gòu),上述代碼如果改成如下代碼異常即可捕獲。1. _try2. 3. BYTE*pch;4. pch=(BYTE*)00001234;/ 給予一個(gè)非法地址5.6. *pch=6;/ 對(duì)非法地址賦值,會(huì)造成Access Vi

28、olation 異常7. 8. _except(EXCEPTION_EXECUTE_HANDLER)9. 10. AfxMessageBox(catched);11. 但是用_try, _except塊還有問題, 就是這個(gè)不是C+標(biāo)準(zhǔn), 而是Windows平臺(tái)特有的擴(kuò)展。而且如果在使用過程中涉及局部對(duì)象析構(gòu)函數(shù)的調(diào)用,則會(huì)出現(xiàn)C2712的編譯錯(cuò)誤。 那么還有沒有別的辦法呢?當(dāng)然有, 就是仍然使用C+標(biāo)準(zhǔn)的trycatch(.), 但在編譯命令行中加入/EHa的參數(shù)。這樣VC編譯器不會(huì)把try catch模塊給優(yōu)化掉了。(6)單攝像機(jī)標(biāo)定In the reference manual,opera

29、tor signatures are visualized in the following way:operator ( iconic input : iconic output : control input : control output )在HALCON所有算子中,變量皆是如上格式,即:圖像輸入:圖像輸出:控制輸入:控制輸出。其中四個(gè)參數(shù)任意一個(gè)可以為空??刂戚斎肟梢允亲兞俊⒊A?、表達(dá)式;控制輸出以及圖像輸入和輸出必須是變量。1.caltab_points:從標(biāo)定板中讀取marks中心坐標(biāo),該坐標(biāo)值是標(biāo)定板坐標(biāo)系統(tǒng)里的坐標(biāo)值,該坐標(biāo)系統(tǒng)以標(biāo)定板為參照,向右為X正,下為Y正,垂直標(biāo)定板向下為Z正。該算子控制輸出為標(biāo)定板中心3D坐標(biāo)。2.create_calib_data:創(chuàng)建Halcon標(biāo)定數(shù)據(jù)模型。輸出一個(gè)輸出數(shù)據(jù)模型句柄。3.set_calib_data_cam_param:設(shè)定相機(jī)標(biāo)定數(shù)據(jù)模型中設(shè)置相機(jī)參數(shù)的原始值和類型。設(shè)置索引,類型,以及相機(jī)的原

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。

評(píng)論

0/150

提交評(píng)論