Problem whith GetFrameImage

Posts: 5
Joined: Tue Oct 23, 2007 1:23 am

Problem whith GetFrameImage

Post by yermani » Tue Oct 23, 2007 2:01 am

hello everybody,
I'm trying to use the GetFrameImage methode. I don't understand the error risen. Can someone help me? thanks!

Here is the error:
([color:#FF0000]see red line in the code[/color])Access violation reading location 0x0000daf0

And here is the code:

//#include "stdafx.h"
#include "stdio.h"
#include "stdlib.h"
#include "optitrack.h"


INPCameraCollection *pCameraCollection;
INPCamera *pCamera;
INPCameraFrame *pFrame;

int main(int argc, char* argv[])
LONG count;
LONG misc;
LONG waittime;
LONG framerate;

BYTE *pBuffer;

int running = 1;
int toerrors = 0;

printf("Hello World!\n");

CoInitialize(NULL); // Startup Microsoft crap

CoCreateInstance(__uuidof(NPCameraCollection) , NULL, CLSCTX_ALL,__uuidof(INPCameraCollection), (void **) &pCameraCollection);
CoCreateInstance(__uuidof(NPCamera) , NULL, CLSCTX_ALL,__uuidof(INPCamera) , (void **) &pCamera);
CoCreateInstance(__uuidof(NPCameraFrame) , NULL, CLSCTX_ALL,__uuidof(INPCameraFrame) , (void **) &pFrame);

// find all the cameras:

printf("Nbr of cameras = %ld \n",count);

if (count Item(0, &pCamera);

printf("serial number = %ld \n", misc);

// Open camera:
printf("Camera->Open \n");

// do not suppresses empty camera frames
#if 0
voption.vt = VT_BOOL;
voption.boolVal = VARIANT_TRUE;
pCamera->SetOption(NP_OPTION_SEND_EMPTY_FRAMES, voption);
printf("Camera->SetOption \n");

// Frame rate:
printf("Frame Rate = %ld \n", framerate);

printf("Camera->Start \n");

waittime = 10; // value in milliseconds; 0 = don't wait; INFINITE = wait till data

running = 600; // run ~1 minute for waittime=10 ms

// frame width:
LONG pVal;
int width=(int)pVal;
printf("width:%d \n",pVal);

// frame height:
int height=(int)pVal;
printf("height:%d \n",pVal);

// Memory allocation
if (pBuffer==NULL){
printf("Echec Malloc \n");

// OpenCv Font
CvFont myFont;

// OpenCv image structure Initialisation
IplImage* frame = cvCreateImage(cvSize (width, height), IPL_DEPTH_8U, 1);
unsigned char *data =(unsigned char *)(frame->imageData);

// OpenCV window
cvNamedWindow("Acquisition", CV_WINDOW_AUTOSIZE);

CvPoint pt1, pt2;

// start acquisition
while(running--) {

// Get Frame:
hr=pCamera->GetFrame(waittime, &pFrame);

if (FAILED(hr)) {
fprintf(stderr,"ERROR:Camera->GetFrame %x \n", hr);

switch(hr) {
fprintf(stderr, "E_POINTER \n"); break;

fprintf(stderr, "NP_E_DEVICE_DISCONNECTED \n"); break;

fprintf(stderr, "NP_E_DEVICE_NOT_SUPPORTED \n"); break;

fprintf(stderr, "HRESULT_FROM_WIN32(ERROR_TIMEOUT)\n");

fprintf(stderr, "default \n"); break;

// render an image into a buffer
[color:#FF0000]pCamera->GetFrameImage(pFrame, width, height, 0, 8, &pBuffer[0]);[/color]


// Affectation on an OpenCV structrure
for (int i=0; iGetSafeHwnd();
//pCamera->GetFrame(DrawFrame(pFrame, hWnd); // essayer plutot d'utiliser les fen�tres d'OpenCV

}// End of acquisition_________________________________________________________________________

// Goodbye
printf("\n\n%d timeouts \n", toerrors);
CvPoint pt;
printf("\n Press key to quit!!\n");
// Attente:

// shut everything down

return 0;

Posts: 1139
Joined: Thu Jan 30, 2003 5:00 am
Location: Corvallis, Oregon

Re: Problem whith GetFrameImage

Post by Birch » Tue Oct 23, 2007 2:41 pm

Try adding a check for (pFrame != 0) before calling GetFrameImage, that should help verify that you have a valid frame to operate on.

Posts: 5
Joined: Tue Oct 23, 2007 1:23 am

Re: Problem whith GetFrameImage

Post by yermani » Mon Oct 29, 2007 8:35 am

Sorry, I just see your answer. Yes that is the mistake. Thanks for your help.

Posts: 20
Joined: Fri Nov 09, 2007 7:39 am

Re: Problem whith GetFrameImage

Post by symfonysid » Fri Nov 09, 2007 8:00 am


I work with yermani, and we're still having some unexpected problems with the GetFrameImage method. There are a number of cases where an access violation occurs in GetFrameImage although the pFrame and pCamera objects are fine. For instance, when the camera is plugged into a laptop and the laptop is not plugged into a power socket, then it's possible to create a pCamera and pFrame object without any problems (return code is S_OK and they are not null), but when these objects are used by calling GetFrameImage, there is an access violation error. Um... In this case one would expect that the function to create the pCamera object would return an error, and if not that, then GetFrameImage would return an error so that one could catch the problem and alert the program's user. But instead there is an access violation inside the method itself, and everything goes down... The same thing happens as well when the wait time is set to too small or too large a value. When it is set to 1 msec or 100 msecs, there is an access violation in the GetFrameImage method rather than this method returning an error. There are possibly some further cases where exceptions arise when using this method, but we haven't yet been able to localize their cause... With regards to the first problem, I was hoping that there might be a method we could call to check to see whether the camera was in a valid state. With regards to the second problem, I was hoping you might be able to explain why this is happening.

NaturalPoint Employee
NaturalPoint Employee
Posts: 520
Joined: Tue Jan 02, 2007 2:02 pm

Re: Problem whith GetFrameImage

Post by beckdo » Sun Nov 11, 2007 1:13 pm

Are you saying that when the camera is plugged into wall power the exception goes away?

Posts: 58
Joined: Tue Oct 23, 2007 2:09 pm

Re: Problem whith GetFrameImage

Post by hpcv » Mon Nov 12, 2007 6:32 am

I have had some issues myself regarding grounding. Basically, all cameras would go down if I touched the metal casing of one of the V100 cameras, and to get it back up a restart of the Point Cloud or Rigid Body tool was needed. I worked around this by keeping my hands off the cameras, but just so you know that grounding may be an issue here.

NaturalPoint Employee
NaturalPoint Employee
Posts: 1395
Joined: Mon Oct 14, 2002 5:00 am
Location: Corvallis, Oregon

Re: Problem whith GetFrameImage

Post by Jim » Mon Nov 12, 2007 2:55 pm


I have tried to isolate the grounding problem here, and have not been able to see what is happening. The cases are isolated from the board internals, and decoupled, the GND should go from the internal boards to the USB hub. I have seen it where I touched the case once and the LED display went away, but the camera was still there. With all other cameras in the field I haven't heard of any problems (hundreds), but it could be there in some situations. Just to let you know that I am aware of what you are saying. Thanks.

Posts: 20
Joined: Fri Nov 09, 2007 7:39 am

Re: Problem whith GetFrameImage

Post by symfonysid » Tue Nov 13, 2007 2:12 am


Well, although the grounding problem sounds interesting, it is actually a different problem than the one I mentioned. I only meant to say that when the camera is plugged into a laptop, and the laptop is not plugged into the wall, then the camera doesn't work properly. This is in and of itself not surprising, because of course the camera can't work if it's not getting enough power from the USB port. But what is surprising is that we don't notice this problem until we call GetFrameImage() when an exception is thrown internally in the method and everything goes down. I was hoping there was a way we could check for this condition beforehand so that we could give the user an error message.


Posts: 58
Joined: Tue Oct 23, 2007 2:09 pm

Re: Problem whith GetFrameImage

Post by hpcv » Tue Nov 13, 2007 2:21 am

You can ask Windows whether the laptop is plugged into the wall, I think. Not exactly what you ask for, but depending on your situation it might suffice.

NaturalPoint Employee
NaturalPoint Employee
Posts: 1395
Joined: Mon Oct 14, 2002 5:00 am
Location: Corvallis, Oregon

Re: Problem whith GetFrameImage

Post by Jim » Tue Nov 13, 2007 12:19 pm

Oh, thanks for the explanation. Never mind about that "other" grounding problem! :)

As you suggest, this does make sense, if you don't have enough power the cameras won't work to spec. We have found that you can't be sure what is happening on different computers USB ports, so we usually use our D-Link powered USB hubs, which work really well and are cheap. We also use a lot of Dell laptops and Shuttle computers and they are all fine.

For this issue I suspect that the camera is operating to some degree with the low power, but might be in an unstable condition. If powering the laptop fixes the issue, I suspect that the onboard USB is not providing 500ma as per USB spec.

You could try turning off the IR LEDs first, and then calling GetFrame and see if that makes a difference, just to isolate the power issue more. The IR LEDs take most of the power.

Post Reply