BYTE类型转换Hobject类型

在与halcon的混编中,有时会用到数据类型转换。

例如在相机采集与后期的图像处理中,一般需要将采集到的BYTE类型数据转化成halcon中对应的Hobject类型方可处理。

在halcon11中提供了一个函数及其例程:

1 void NewImage(Hobject *new)
2 {
3   unsigned char  image[768*525];
4   int            r,c;
5   for (r=0; r<525; r++)
6     for (c=0; c<768; c++)
7       image[r*768+c] = c % 255;
8   gen_image1(new,"byte",768,525,(Hlong)image);
9 }

其中,gen_image1()在halcon11中的函数名称改为GenImage1();

对于彩色图像halcon提供了gen_image3()/GenImage3();

 1 void NewRGBImage(Hobject *new)
 2 {
 3   unsigned char  red[768*525];
 4   unsigned char  green[768*525];
 5   unsigned char  blue[768*525];
 6   int            r,c;
 7   for (r=0; r<525; r++)
 8     for (c=0; c<768; c++)
 9     {
10       red[r*768+c]   = c % 255;
11       green[r*768+c] = (767 - c) % 255;
12       blue[r*768+c]  = r % 255;
13     }
14     gen_image3(new,"byte",768,525,(Hlong)red,(long)green,(long)blue);
15 }
16 
17 main()
18 {
19   Hobject  rgb;
20   open_window(0,0,768,525,0,"","",&WindowHandle);
21   NewRGBImage(&rgb);
22   disp_color(rgb,WindowHandle);
23   clear_obj(rgb);
24 }

 

另,halcon还提供了带有存储管理的函数GenImage1Extern()

void NewImage(Hobject *new)
{
  unsigned char  *image;
  int            r,c;
  image = malloc(640*480);
  for (r=0; r<480; r++)
    for (c=0; c<640; c++)
      image[r*640+c] = c % 255;
  gen_image1_extern(new,"byte",640,480,(Hlong)image,(long)free);
}

和GenImage3Extern()

 1 void NewImage(Hobject *new)
 2 {
 3   unsigned char  *image_red;
 4   unsigned char  *image_green;
 5   unsigned char  *image_blue;
 6   int            r,c;
 7   image_red = malloc(640*480);
 8   image_green = malloc(640*480);
 9   image_blue = malloc(640*480);
10   for (r=0; r<480; r++)
11     for (c=0; c<640; c++)
12     {
13       image_red[r*640+c] = c % 255;
14       image_green[r*640+c] = (c+64) % 255;
15       image_blue[r*640+c] = (c+128) % 255;
16     }
17   gen_image3_extern(new,"byte",640,480,(Hlong)image_red,(long)image_green,(long)image_blue,(long)free);
18 }


 

posted @ 2015-01-08 10:17  yangxin4894  阅读(5939)  评论(0编辑  收藏  举报