如何理解halcon 算子get_grayval 、set_grayval 逐行讀取和逐行寫入

gen_image_const (Image, 'uint2', ProfileWidth, NumProfiles)
* 
* Create the reference object by collecting the measured profiles in a sheet-of-light model
* 通過在一個光照模型中收集測量的輪廓來創建參考對象
for Index := 0 to NumProfiles - 1 by 1
    * Add the next profile to the sheet of light model
    read_image (ImageModel, 'sheet_of_light/metal_part_1_disparity_line_' + Index$'03d')
    set_profile_sheet_of_light (ImageModel, SheetOfLightModelID, [])
    * Visualize accumulated profiles
    get_grayval (ImageModel, gen_tuple_const(ProfileWidth,0), [0:ProfileWidth - 1], Grayval)
    set_grayval (Image, gen_tuple_const(ProfileWidth,Index), [0:ProfileWidth - 1], Grayval)
    if (Index % 5 == 0)
        dev_display (Image)
    endif
    Message := 'Measure reference object'
    Message[1] := 'Add profile ' + (Index + 1) + '/' + NumProfiles
    disp_message (WindowHandle, Message, 'window', 12, 12, 'black', 'true')
endfor

不知道大家對這個是否理解,我剛開始愣是沒理解他是如何讀取一行,又是如何讀取一列的,看的暈暈的,其實這個是我們的慣性思維導致看不懂的,下面解釋:

get_grayval(Image : : Row, Column : Grayval)

這裏大家需要清楚的是,他是通過每個像素點進行讀取的,該函數是每次給一個行和列,那麼就會對應一個像素點,此時就可以得到灰度值,那麼如何一次讀取一行呢?其實很簡單寫一個for循環就好了啊,如下:

row = 0;
for i := 0 to NumProfiles - 1 by 1
    get_grayval(image,row ,i)
   

可以看到每次都會讀取第一行的下一列的內容,那麼這樣寫太麻煩了,有沒有簡單的方法呢?答案是肯定的,halcon有一個元組的使用如下:

gen_tuple_const(10,0),意思就是生成10個元素的數組,這個數組的值都爲0;

那麼gen_tuple_const(ProfileWidth,0)這個也就理解了,其實就是生成ProfileWidth多的0,而ProfileWidth就是圖片的寬度啊,讀取一行的就需要這麼多次的一個一個的讀取,因此

get_grayval (ImageModel, gen_tuple_const(ProfileWidth,0), [0:ProfileWidth - 1], Grayval)

的意思就是每次都讀取第0行的一列,總共需要讀多少列呢,需要讀取[0:ProfileWidth - 1]=[0,1,2,3,4,5,,,,,,ProfileWidth - 1]

因此

gen_tuple_const(ProfileWidth,0) = [0,0,0,0,,,,,,,0]總共ProfileWidth個0

[0:ProfileWidth - 1]=[0,1,2,3,4,5,,,,,,ProfileWidth - 1]總這些列,因此每次都是讀第0行第i列,i=0,1,2,3,,,ProfileWidth - 1

 

同理寫入也是同一個道理,本來需要寫一個for循環的,但是halcon中可以直接簡化了。

 

點贊呀兄弟們

 

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章