天天看點

Halcon把8位圖轉換為24位圖的方法

halcon源碼如下

*8位圖轉24位圖

*讀取8位圖

read_image (Image, 'D:/org_R1.jpg')

get_image_pointer1 (Image, Pointer, Type, Width, Height)

*生成24位圖

gen_image3 (ImageRGB, 'byte', Width, Height, Pointer, Pointer, Pointer)

C++源碼如下:

//圖像屬性
HObject ho_Image3;
HTuple hv_Pointer;
HTuple hv_Type;
HTuple hv_Width;
HTuple hv_Height;
//生成24位的圖像檔案
GetImagePointer1(ho_Image1, &hv_Pointer, &hv_Type, &hv_Width, &hv_Height);
GenImage3(&ho_Image3, "byte", hv_Width, hv_Height, hv_Pointer, hv_Pointer, hv_Pointer);      

C源碼如下:

void NewRGBImage(Hobject *new)
{
  unsigned char  red[768*525];
  unsigned char  green[768*525];
  unsigned char  blue[768*525];
  int            r,c;
  for (r=0; r<525; r++)
    for (c=0; c<768; c++)
    {
      red[r*768+c]   = c % 255;
      green[r*768+c] = (767 - c) % 255;
      blue[r*768+c]  = r % 255;
    }
    gen_image3(new,"byte",768,525,(Hlong)red,(long)green,(long)blue);
}
main()
{
  Hobject  rgb;
  open_window(0,0,768,525,0,"","",&WindowHandle);
  NewRGBImage(&rgb);
  disp_color(rgb,WindowHandle);
}      

繼續閱讀