Click here to Skip to main content
15,881,715 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
How to from Convert Byte Array to IplImage using OpenCv ?

Is it possible to do the conversion here from byte array to IplImage using Opencv ?
Posted
v3
Comments
nv3 18-Apr-13 3:11am    
Yes it's possible. How exactly pretty much depends on the structure of your image. How are the bytes arranged in your byte array:
- how many bytes belong to a single pixel
- in what order are the pixels contained in the byte array (left to right, right to left, bottom up, top down?)
- how much fill space is contained in every scan line (usually every scan line starts on 4, 8, or 32 byte boundary)
After you have answered those questions look into the OpenCV documentation and you'll find all you need to create an IplImage from that.

cvSetData(imageFrame,Buffer, Width*3);

Buffer-Byte array
Width*3 is the number of bytes in each row of IplImage (my case Width=640)
imageFrame is an IplImage*
 
Share this answer
 
Comments
nv3 18-Jul-13 11:59am    
I doubt that the author of the question will take another look, after 3 months. And besides, you describe a special case with 3 bytes per pixel and without slack at the row end. This might fit in your case, but is not generally usable.
if you are use then following function useful under C#

//bytes to image
public static Image<bgr,> ConvertByteToImage(byte[] bytes)
{
return new Image<bgr,>(new Bitmap(Image.FromStream(new MemoryStream(bytes))));
}

//image to byte
public static byte[] ConvertImageToByte(Image<bgr,> My_Image)
{
MemoryStream m1 = new MemoryStream();
new Bitmap(My_Image.ToBitmap()).Save(m1, System.Drawing.Imaging.ImageFormat.Jpeg);
byte[] header = new byte[] { 255, 216 };
header = m1.ToArray();
return (header);
}

above logic may use full.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900