Click here to Skip to main content
15,892,575 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi everyone, here I have a problem which is very urgent and I couldn't resolve during the past three days. It can be simplified as below:
typedef struct _tagBufferStatus
{
      long BufferCount;
      byte** Buffer;
       ...
}StructBufferStatus;
        int nIndex = 0;
        byte *pIn;
        BITMAPFILEHEADER bmfHdr;
        BITMAPINFOHEADER bmiHdr;
        LPBITMAPIINFO lpbmi;
	StructCurrentImageSize structCurImg = MS_GetCurrentImageSize(g_CameraID,&status);
	int cxWidth  = structCurImg.ImageWidthFromCamera;
	int cyHeight = structCurImg.ImageHeightFromCamera;
	DWORD memSize = cxWidth*cyHeight;
	byte *pOut= new byte[memSize];
	ZeroMemory(pOut,memSize);
	LPBITMAPINFO lpbmi;
	DWORD BitmapInfoSize;
	MS_CreateDIBHeader(g_CameraID,&lpbmi,&BitmapInfoSize,&status);
	DWORD dwSize = lpbmi->bmiHeader.biSizeImage;
	static StructBufferStatus  structBufStatus = MS_GetBufferStatus(g_CameraID,&status);
	StructCaptureStatus structCapStatus = MS_GetCaptureStatus(g_CameraID,&status);
	nIndex = structBufStatus.LastValidFrame;
	byte **pTemp = structBufStatus.ImageBuffers;
	pIn = pTemp[nIndex];
	MS_GetGrayscaleImage(g_CameraID,pIn,pOut,&status);
        
        bmfHdr.bfOffBits   = sizeof(BITMAPFILEHEADER) + sizeof(BITMAPINFOHEADER) + 256*sizeof(RGBQUAD);
	bmfHdr.bfReserved1 =0;
	bmfHdr.bfReserved2 =0;
	bmfHdr.bfSize = memSize +sizeof(BITMAPFILEHEADER) + sizeof(BITMAPINFOHEADER) + 256*sizeof(RGBQUAD);
	bmfHdr.bfType = 0x4d42;
        memcpy(&bmiHdr,lpbmi,sizeof(BITMAPINFOHEADER));
        SavetoBMP(bmfHdr,bmiHdr,pOut);

In this case, function StructImageBuffer GetImageBuffer(long CameraID) is provided for the purpose of retrieving a pointer to a series of image buffer. As each image buffer is represented by a pointer,we need a pointer pointer to get the starting address of image buffer series.
use functionGetImage(long CameraID,byte *pSrc,byte *pDst) to store an image data in pDst, where pSrc points to one of the image buffer in the image buffer series.

here,the problem is : the two functions is provdied by DLL,and ImageBuffer is reserved by DLL,and I can't copy data from Buffer to pDst. Is there anyone who has encountered the same problem and is kindly enough to give me a hand? All the thanks!
Posted
Updated 21-Feb-13 1:41am
v6
Comments
Albert Holguin 19-Feb-13 21:57pm    
What's the error you're encountering? ...state it specifically... Also, do you have the source for GetImage()?
louisejackie 19-Feb-13 23:29pm    
Thanks a lot for your kind reply Albert. GetImage() and GetImageBuffer() are provided in DLL,which is protected by Vendor of the vedio card.There is no problem in Debug and running, but when I tried to save the data in pDst to a BMP file,it turned out the saved bmp file is total black, which means the value in pDst is zero.
Albert Holguin 20-Feb-13 0:39am    
Does the function return anything? Is there any way to determine whether it failed based on the return? Are you sure you're supposed to allocate the dst buffer and not just pass a pointer to a pointer and let the function allocate it himself? ...have you tried initializing the destionation buffer to something (say all ones or all zeros) to see if the call is doing anything with the buffer?
louisejackie 20-Feb-13 2:45am    
well,as is in ImageProcessing, when you read a bmp file into a block of memory,say *pData, allocted manually, you cannot get the value in the block when debuging.it appear to be a mess,but the data is there.
Here lies the same problem.I can't check the value in pDst while Debuging. Can you tell me how?
Albert Holguin 20-Feb-13 12:42pm    
You're gonna have to learn to use your debugger effectively. Your initial statement about memory allocated manually doesn't make any sense.

There are several things that look weird here, besides the fact that you consistently left out the "r" in "struct". The code you showed would not even compile.

Take a look into the documentation of your library vendor and see whether GetImageBuffer really returns a StructImageBuffer! This structure can have a considerable size and it is unlikely that someone passes that as a result value.

If GetImageBuffer really returns a StructImageBuffer, why would one need a GetImage function? You could simply access the image by retrieving the buffer pointer from the StructImageBuffer.

The GetImage function takes the CameraId as first argument. That doesn't make sense if the image data already reside in the buffer pointed to by pSrc.

I think that you have misinterpreted the vendor's description of the two functions and it is hard to guess what they really do.

Btw.: The values in an image buffer do normally not look like "a mess", but are simply the pixel data of the image. Look at them in your debugger as hex or int values and they should make sense.
 
Share this answer
 
Comments
louisejackie 20-Feb-13 5:39am    
Sorry for my bad spelling.Great thanks to nv3.I cannot upload an image to show you my debug situation. Allow me to try to put it like this:
char *filename ="lena.bmp";
byte *pSrc = new byte[cxWidth*cyHeight];
pSrc = ReadImage(filename);
when Debuging,at watch window, pSrc's address is shown,after which follows a trail of messy code,something like japanese character.
As to the two function, CameraID is the resource they can access ,and GetImageBuffer() returns a struct,not the actual memory.so it won't be very large.
nv3 20-Feb-13 5:56am    
Can you copy paste the part of the vendor's DLL .h file that contains the relevant definitions? For example the exact definitions of GetImageBuffer and GetImage and the structs they use. Perhaps we can make sense of that.

In your above example you are creating a memory leak. You first allocate a buffer with new, then you reassign pSrc with the result of ReadImage, which obviously allocates its own buffer.

So, understanding the exact interface of those library routines is essential and I think your problem is that your idea of how they work is not entirely correct.
louisejackie 20-Feb-13 6:17am    
Alright,here is the vendor's DDL version of the two function.

MS_CAMERACONTROL_API const StructBufferStatus MS_GetBufferStatus ( long CameraID, int * pStatus =

NULL);
Returns:
a struct containing the current values of the status

Parameters:
CameraID: This is the unique Camera ID value of the camera you want to apply this function to.
This must be the same value that was returned by MS_InitializeCameraID() when you initialized this

camera.

pStatus: Returns the status code of the operation. See Status Codes for more information.
This parameter is optional. If it is not passed, then the status will not be returned.


MS_CAMERACONTROL_API int MS_GetGrayscaleImage ( long CameraID, unsigned char * pIn,
unsigned char * pOut, int * pStatus = NULL )

This function will leave the image in 8-bit grayscale format, but will remove the bayer pattern noise

from the image, and store the result in a user-created buffer.
The original image in StructBufferStatus::ImageBuffers will not be affected by this process.
This function is meant to be used when StructColorSettings::DisplayMode is set to c_ColorModeGrayscale


Attention:
You must manually allocate the buffer pOut before you call this function, and free this buffer when

you are finished using it.
The size of this buffer must be StructCurrentImageSize.ImageWidthFromCamera *

StructCurrentImageSize.ImageHeightFromCamera * 1, because each pixel will be 8 bits.


Returns:
the value of *pStatus

Parameters:
CameraID This is the unique Camera ID value of the camera you want to apply this function to.
This must be the same value that was returned by MS_InitializeCameraID() when you initialized this

camera.

pIn: This is the pointer to the image buffer to process.
This should be set to either a frame from the StructBufferStatus::ImageBuffers, or the pImage pointer

passed to one of the callback functions.

pOut: This is the pointer to the processed image.

pStatus: Returns the status code of the operation. See Status Codes for more information.
This parameter is optional. If it is not passed, then the status will not be returned.
Albert Holguin 20-Feb-13 12:47pm    
There's a status that is returned... why aren't you checking it?
nv3 20-Feb-13 17:12pm    
Ok, I assume that MS_GetGrayScaleImage is the function that you were referring to as GetImage in your original post, correct?

The first thing I would do is to look at what is returned via pOut. We are expecting an array of w * h bytes that represent the pixel values. Look at the first 100 pixels in your debugger or print them via print to stdout, each byte with format "%3d". Something like:

for (int i = 0; i < 100; ++i)
printf ("%3d, ", pOut[i]);
printf ("\n");

Does that look like pixel values of normal image? If you receive 100 zeros that means, either the first scan line of the image is black, or the function call failed for some reason.

The next step is to look at the function SaveToBmp (byte* pOut). What bothers me is that SaveToBmp has no information about the width, height, and pixel size of your image. How can it create a valid BMP file with just receiving a buffer pointer; it doesn't even know the length of that buffer. Have you written that function or is it part of the camera vendor's library? Anyhow, it looks very weird.
Are you getting valid values in the pDst before saving as BMP file while you debug?
 
Share this answer
 
Comments
louisejackie 20-Feb-13 3:56am    
Values in pDst seem to be a mess, as they are binary data.Do you have any suggestion on how to check data value of a BMP file when Debuginig ?
Albert Holguin 20-Feb-13 12:45pm    
You have to know whether that binary data makes sense. It's up to you to figure out what makes sense (look at the BMP standards).

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