LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

Display and Store a 8bit greyscale bitmap aquired from a Keyence Camera

Hello.

 

I'm using a Keyence camera system to get images (8bit greyscale in uncompressed BMP format) from different objects.

 

After triggering the image capture I want to do several things with the image data:

- transfer it to the LabWindows/CVI PC (this is done with a serial USB connection to the camera system)

- display it to the user as a 8bit greyscale image

- pass the 8bit greyscale image into a third-party function that does some calculations with it (the third party software accepts a double array together with height and width as parameters, so I do have to convert the image data to double)

- save the image to disk

 

So far I've done this as a first try to get things working (I wanted to create the bitmap, copy it to the clipboard and then display it in Windows Paint):

 

 

int ProcessImage(void)
{
	int hwError = 0; // error code
	int bitmapID = 0; // bitmap ID
	char cvBitmap[2000000] = {0}; // bitmap data aquired from the camera
	int colorTable[256] = {0}; // color table for the bitmap
	
	hwError = CVCameraGetBitmap(&cvBitmap[0]); // get the bitmap data from the camera
	if(hwError != SUCCESS)
	{
		DebugPrintf("ProcessImage(): GetBitmap failed\n"); // error handling
		return FAULT;
	}
	
	for(int i=0; i<256; i++) // fill the ColorTable for the bitmap
	{
		colorTable[i] = i;
	}
	
	hwError = NewBitmap(1600, 8, 1600, 1200, colorTable, cvBitmap, NULL, &bitmapID); // create new bitmap
	
	hwError = ClipboardPutBitmap (int bitmapID); // copy bitmap data to clipboard
	
//	DiscardBitmap(bitmapID); // delete bitmap
	
	return hwError;
}

 

 

When i paste the image in Paint it just displays all black, so I think maybe it's something wrong with the color table?

I didn't manage to get a proper image, though. Maybe one of you can help me out there?

 

Thank you for your help.

 

Best regards,

Bernd

 

P.S. I'm using CVI 9.1

0 Kudos
Message 1 of 2
(4,034 Views)

Hi Bernd,

 

maybe this will help you:

 

#include <utility.h>
#include <ansi_c.h>
#include <userint.h>
#include <cvirte.h>

static int gHeight;
static int gWidth;
static int bmpID;
int pixelDepth, rowBytes, *colorTable = NULL;
unsigned char *bits = NULL, *mask = NULL;
static int colorSize, bitsSize, maskSize;

int main (int argc, char *argv[])
{
    if (InitCVIRTE (0, argv, 0) == 0)
        return -1;    /* out of memory */
    
    GetBitmapFromFile ("c:\\Penguins.bmp", &bmpID);
    
    GetBitmapInfo(bmpID, &colorSize, &bitsSize, &maskSize);

    colorSize=256;
    
        if (colorSize > 0)
            colorTable = (int *)calloc(colorSize, sizeof(int));
            bits = (unsigned char *)malloc(bitsSize);
        if (maskSize > 0)
            mask = (unsigned char *)malloc(maskSize);
    
    

        
    GetBitmapData(bmpID, &rowBytes, &pixelDepth, &gWidth, &gHeight, colorTable, bits, mask);
    
    for(int i=0; i<256; i++) // fill the ColorTable for the bitmap
    {
        colorTable[i] = 10000*i;
    }
    
    NewBitmap(rowBytes, 8, gWidth, gHeight, colorTable, bits, mask, &bmpID);  
    ClipboardPutBitmap (bmpID);
    DiscardBitmap(bmpID);
    return 0;
}

Regards
DianaS
0 Kudos
Message 2 of 2
(4,010 Views)