如何理解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中可以直接简化了。

点赞呀兄弟们

猜你喜欢

转载自blog.csdn.net/weixin_42398658/article/details/104682791
今日推荐