B
Btb4198
Guest
so I have values coming from a camera 0-1023 so 10 bits. and I display this in a video. that part seems to be working.
but when I try to get the values back from the video, I run in a big problem.
my highest value is 1020, but my lowest value is 255 and not 0.
why ?
here is my code :
public double[,] imageToByteArray(Bitmap _image)
{
Bitmap b = new Bitmap(_image);
BitmapData bData = b.LockBits(new Rectangle(0, 0, _image.Width, _image.Height), ImageLockMode.ReadWrite, b.PixelFormat);
/* GetBitsPerPixel just does a switch on the PixelFormat and returns the number */
byte bitsPerPixel = GetBitsPerPixel(bData.PixelFormat);
/*the size of the image in bytes */
int size = bData.Stride * bData.Height;
/*Allocate buffer for image*/
byte[] data = new byte[size];
double[,] returndata = new double[_image.Height, _image.Width];
/*This overload copies data of /size/ into /data/ from location specified (/Scan0/)*/
System.Runtime.InteropServices.Marshal.Copy(bData.Scan0, data, 0, size);
int i = 0;
for (int y = 0; y < _image.Height; y++)
{
for (int x = 0; x < _image.Width; x++)
{
double magnitude = data + data[i + 1] + data[i + 2] + data[i +3]; // 1 / 3d * (data + data[i + 1] + data[i + 2]);
returndata[y, x] = magnitude;
i += bitsPerPixel / 8;
}
}
return returndata;
}
Continue reading...
but when I try to get the values back from the video, I run in a big problem.
my highest value is 1020, but my lowest value is 255 and not 0.
why ?
here is my code :
public double[,] imageToByteArray(Bitmap _image)
{
Bitmap b = new Bitmap(_image);
BitmapData bData = b.LockBits(new Rectangle(0, 0, _image.Width, _image.Height), ImageLockMode.ReadWrite, b.PixelFormat);
/* GetBitsPerPixel just does a switch on the PixelFormat and returns the number */
byte bitsPerPixel = GetBitsPerPixel(bData.PixelFormat);
/*the size of the image in bytes */
int size = bData.Stride * bData.Height;
/*Allocate buffer for image*/
byte[] data = new byte[size];
double[,] returndata = new double[_image.Height, _image.Width];
/*This overload copies data of /size/ into /data/ from location specified (/Scan0/)*/
System.Runtime.InteropServices.Marshal.Copy(bData.Scan0, data, 0, size);
int i = 0;
for (int y = 0; y < _image.Height; y++)
{
for (int x = 0; x < _image.Width; x++)
{
double magnitude = data + data[i + 1] + data[i + 2] + data[i +3]; // 1 / 3d * (data + data[i + 1] + data[i + 2]);
returndata[y, x] = magnitude;
i += bitsPerPixel / 8;
}
}
return returndata;
}
Continue reading...