pyromanci
10th May 2017, 20:45
I had a program i originally wrote in C#, but I need it to run on linux now. So I've been porting it to c++ to use the QT GUI. It's almost done say for 1 thing. I have a few biometeric libraries (fingerprint, palm, and facial) that are used for authentication.
I have those 3 working for the most part. One thing I do in the c# version is show the captured image from the biometeric readers. Problem is I really suck and Image processing and converting formats. Both the Palm and Fingerprint scanners return a raw 8bpp image (no headers). Where as the Facial recognition library is a Jpeg format.
In my c# version I convert the 8bpp images to jpegs using this function:
public byte[] CreateRawJpegFrom8BPP(byte[] bytes, int width, int height)
{
byte[] rgbBytes = new byte[bytes.Length * 3];
for (int i = 0; i <= bytes.Length - 1; i++)
{
rgbBytes[(i * 3)] = bytes[i];
rgbBytes[(i * 3) + 1] = bytes[i];
rgbBytes[(i * 3) + 2] = bytes[i];
}
Bitmap bmp = new Bitmap(width, height, PixelFormat.Format24bppRgb);
BitmapData data = bmp.LockBits(new Rectangle(0, 0, bmp.Width, bmp.Height), ImageLockMode.WriteOnly, PixelFormat.Format24bppRgb);
for (int i = 0; i <= bmp.Height - 1; i++)
{
long s = data.Scan0.ToInt64();
int l = data.Stride;
IntPtr p = new IntPtr(data.Scan0.ToInt64() + data.Stride * i);
System.Runtime.InteropServices.Marshal.Copy(rgbByt es, i * bmp.Width * 3, p, bmp.Width * 3);
}
bmp.UnlockBits(data);
System.IO.MemoryStream ms = new System.IO.MemoryStream();
bmp.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg);
byte[] byteImage = ms.ToArray();
ms.Close();
ms.Dispose();
return byteImage ;
}
Now I sure if I could get the Image data into a QImage I could figure out the rest.
I've tired:
/* For refences this is teh structure format.
typedef struct dpfpdd_image_info {
unsigned int size; /**< size of the structure */
unsigned char* image_data; /**< image data */
unsigned int image_size; /**< size of the image data */
unsigned int width; /**< width of the captured image */
unsigned int height; /**< height of the captured image */
unsigned int res; /**< resolution of the captured image */
unsigned int bpp; /**< pixel depth of the captured image */
} DPFPDD_IMAGE_INFO;
*/
QImage* img = new QImage(pImageInfo.width, pImageInfo.height, QImage::Format_Indexed8);
img->fromData(pImageInfo.image_data, pImageInfo.image_size);
I then try to save it off as a Bitmap to look at it, but i'm told it's not a proper bitmap file.
So i'm not sure if i am even close to the direction on loading this image data into a Qimage.
Any direction would be great. I've been searching around all day, but just have not had much of any luck.
I have those 3 working for the most part. One thing I do in the c# version is show the captured image from the biometeric readers. Problem is I really suck and Image processing and converting formats. Both the Palm and Fingerprint scanners return a raw 8bpp image (no headers). Where as the Facial recognition library is a Jpeg format.
In my c# version I convert the 8bpp images to jpegs using this function:
public byte[] CreateRawJpegFrom8BPP(byte[] bytes, int width, int height)
{
byte[] rgbBytes = new byte[bytes.Length * 3];
for (int i = 0; i <= bytes.Length - 1; i++)
{
rgbBytes[(i * 3)] = bytes[i];
rgbBytes[(i * 3) + 1] = bytes[i];
rgbBytes[(i * 3) + 2] = bytes[i];
}
Bitmap bmp = new Bitmap(width, height, PixelFormat.Format24bppRgb);
BitmapData data = bmp.LockBits(new Rectangle(0, 0, bmp.Width, bmp.Height), ImageLockMode.WriteOnly, PixelFormat.Format24bppRgb);
for (int i = 0; i <= bmp.Height - 1; i++)
{
long s = data.Scan0.ToInt64();
int l = data.Stride;
IntPtr p = new IntPtr(data.Scan0.ToInt64() + data.Stride * i);
System.Runtime.InteropServices.Marshal.Copy(rgbByt es, i * bmp.Width * 3, p, bmp.Width * 3);
}
bmp.UnlockBits(data);
System.IO.MemoryStream ms = new System.IO.MemoryStream();
bmp.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg);
byte[] byteImage = ms.ToArray();
ms.Close();
ms.Dispose();
return byteImage ;
}
Now I sure if I could get the Image data into a QImage I could figure out the rest.
I've tired:
/* For refences this is teh structure format.
typedef struct dpfpdd_image_info {
unsigned int size; /**< size of the structure */
unsigned char* image_data; /**< image data */
unsigned int image_size; /**< size of the image data */
unsigned int width; /**< width of the captured image */
unsigned int height; /**< height of the captured image */
unsigned int res; /**< resolution of the captured image */
unsigned int bpp; /**< pixel depth of the captured image */
} DPFPDD_IMAGE_INFO;
*/
QImage* img = new QImage(pImageInfo.width, pImageInfo.height, QImage::Format_Indexed8);
img->fromData(pImageInfo.image_data, pImageInfo.image_size);
I then try to save it off as a Bitmap to look at it, but i'm told it's not a proper bitmap file.
So i'm not sure if i am even close to the direction on loading this image data into a Qimage.
Any direction would be great. I've been searching around all day, but just have not had much of any luck.