Measurement Studio for .NET Languages

cancel
Showing results for 
Search instead for 
Did you mean: 

How to get the RGB pointer value of VisionImage in C# .NET

Highlighted

In Visual studio, I use C# to convert VisionImage into Himage (halcon). I can use Genimage1 method to generate grayscale image, but if I want to use Genimage3 method to generate color image, RGB pointer is required. How can I get RGB value or pointer of color image from VisionImage? Or is there any way to convert a color VisionImage into a color Himage? Thank you!

 

Here is the code for black and white image conversion:

 

VisionImage vimage = new VisionImage();//Suppose vimage is a grayscale image

private HImage himage = null;

 

//

public HImage VImageToHImage(VisionImage vimage)
{
himage = new HImage();
PixelValue2D p2D;
p2D = vimage.ImageToArray();

Byte[] imagedata = null;

imagedata = ByteArrToByte(p2D.U8, vimage.Height, vimage.Width);

 

System.Runtime.InteropServices.GCHandle thObject = System.Runtime.InteropServices.GCHandle.Alloc(imagedata, System.Runtime.InteropServices.GCHandleType.Pinned);

 

IntPtr tpObject = thObject.AddrOfPinnedObject();

himage.GenImage1("byte", vimage.Width, vimage.Height, tpObject);

return himage;

}

 

 

public static byte[] ByteArrToByte(Byte[,] b, int nNum1, int nNum2)
{
List<byte> list = new List<byte>();
for (int i = 0; i < nNum1; i++)
{
for (int j = 0; j < nNum2; j++)
list.Add(b[i, j]);
}
byte[] newB = list.ToArray();
return newB;
}

0 Kudos
Message 1 of 1
(80 Views)