Problem with method GetFrame in Visual C**
-
- Posts: 31
- Joined: Wed Jan 09, 2008 1:25 am
Problem with method GetFrame in Visual C**
Hello, I�m working with two OptiTrack Flex:V100 cameras developing a software in Microsoft Visual C++ 2005.
To capture the frames from the cameras I use the method GetFrame from the INPCamera Object and I store the result into a INPCameraFrame.I would like to use a value to the wait time different to zero in the method GetFrame but I have several problems with it:
- When I use the method with only one camera in the system and with a different value of zero for the wait time, there is not any problem.
- When I use the method with two cameras and zero for value in the wait time, there is not any problem.
- But when I used the method with a different value from zero in the wait time and two cameras I� ve got the next problem:
- while there�s nothing to capture the adquisition runs good,
- but when appears any to capture and then disappear, the software breaks with a memory violation.
I use the same INPCameraFrame for both cameras but when I end using it, I free it.
I have tried to use two diferent INPCameraFrame to avoid the problem but it doesn�t disappear. Could you send me any solution or the origin of the problem?
Thank�s,
To capture the frames from the cameras I use the method GetFrame from the INPCamera Object and I store the result into a INPCameraFrame.I would like to use a value to the wait time different to zero in the method GetFrame but I have several problems with it:
- When I use the method with only one camera in the system and with a different value of zero for the wait time, there is not any problem.
- When I use the method with two cameras and zero for value in the wait time, there is not any problem.
- But when I used the method with a different value from zero in the wait time and two cameras I� ve got the next problem:
- while there�s nothing to capture the adquisition runs good,
- but when appears any to capture and then disappear, the software breaks with a memory violation.
I use the same INPCameraFrame for both cameras but when I end using it, I free it.
I have tried to use two diferent INPCameraFrame to avoid the problem but it doesn�t disappear. Could you send me any solution or the origin of the problem?
Thank�s,
Re: Problem with method GetFrame in Visual C**
INPCameraFrames call Free() internally. Just call .Release()
-
- Posts: 31
- Joined: Wed Jan 09, 2008 1:25 am
Re: Problem with method GetFrame in Visual C**
hello again,
i've tried with no call Free(), but the problem doesn't dissapear.
Thanks again
i've tried with no call Free(), but the problem doesn't dissapear.
Thanks again
Re: Problem with method GetFrame in Visual C**
If you send your code over I'd be happy to take a look at it. You can limit it to the main camera loop also, if you'd like.
-
- Posts: 31
- Joined: Wed Jan 09, 2008 1:25 am
Re: Problem with method GetFrame in Visual C**
Excuse me for the delay, i've benn working on another tasks this time...
I've separated the code in two DLL.
In the first, I've got a class with the method:
for(m_iterCamera=m_listCamera.begin(); m_iterCamera!=m_listCamera.end(); ){
/// Store the Serial of the camera in use
(*m_iterCamera)->get_SerialNumber(&m_lSerial);
/// Declare the object to store the frame from the camera
CComPtr AuxFrame;
/// Store the last frame in the camera
m_hExecutionResult = (*m_iterCamera)->GetFrame(0,&(AuxFrame));
if(m_hExecutionResult==S_OK){
/// Variable to store the number of objects in a frame
LONG lNumberObjects = 0;
/// Look for the number of objects in the frame
if((AuxFrame)) m_hExecutionResult = (AuxFrame)->get_Count(&lNumberObjects);
/// If there are any object, look for its coordenates and store them into the received vector
if(lNumberObjects>0){
/// Variable used like a counter when searching for the position of the objects
int c;
for(c=0;c spObject;
/// Store the Object
(AuxFrame)->Item(c, &spObject);
/// The Object to store the values from the camera Object
CapturedPoint* auxPoint;
auxPoint = (CapturedPoint*)malloc(sizeof(CapturedPoint));
/// Store the values from the Camera Object
auxPoint->Serial = m_lSerial;
CComVariant CComAux;
m_hExecutionResult = spObject->get_X(&CComAux);
auxPoint->CorX = CComAux.dblVal;
m_hExecutionResult = spObject->get_Y(&CComAux);
auxPoint->CorY = CComAux.dblVal;
m_hExecutionResult = spObject->get_Area(&CComAux);
auxPoint->Superficie = CComAux.dblVal;
/// Add the point to the received vector
PointCollection->push_back(auxPoint);
spObject.Release();
spObject =0;
}
}
}
/// Free the last frame
AuxFrame=NULL;
AuxFrame.Release();
m_iterCamera++;
}
I've got stored the cameras stored in a vector of INPCamera, so I called them by an iterator. I've tried not using the vector but the problem is the same.
This method is imported on another DLL an called with a bucle in a thread. Before this way, I tried the method asking directky (not by another method or DLL) and the error is the same.
Thanks a lot
Eduardo Valtuille
I've separated the code in two DLL.
In the first, I've got a class with the method:
for(m_iterCamera=m_listCamera.begin(); m_iterCamera!=m_listCamera.end(); ){
/// Store the Serial of the camera in use
(*m_iterCamera)->get_SerialNumber(&m_lSerial);
/// Declare the object to store the frame from the camera
CComPtr AuxFrame;
/// Store the last frame in the camera
m_hExecutionResult = (*m_iterCamera)->GetFrame(0,&(AuxFrame));
if(m_hExecutionResult==S_OK){
/// Variable to store the number of objects in a frame
LONG lNumberObjects = 0;
/// Look for the number of objects in the frame
if((AuxFrame)) m_hExecutionResult = (AuxFrame)->get_Count(&lNumberObjects);
/// If there are any object, look for its coordenates and store them into the received vector
if(lNumberObjects>0){
/// Variable used like a counter when searching for the position of the objects
int c;
for(c=0;c spObject;
/// Store the Object
(AuxFrame)->Item(c, &spObject);
/// The Object to store the values from the camera Object
CapturedPoint* auxPoint;
auxPoint = (CapturedPoint*)malloc(sizeof(CapturedPoint));
/// Store the values from the Camera Object
auxPoint->Serial = m_lSerial;
CComVariant CComAux;
m_hExecutionResult = spObject->get_X(&CComAux);
auxPoint->CorX = CComAux.dblVal;
m_hExecutionResult = spObject->get_Y(&CComAux);
auxPoint->CorY = CComAux.dblVal;
m_hExecutionResult = spObject->get_Area(&CComAux);
auxPoint->Superficie = CComAux.dblVal;
/// Add the point to the received vector
PointCollection->push_back(auxPoint);
spObject.Release();
spObject =0;
}
}
}
/// Free the last frame
AuxFrame=NULL;
AuxFrame.Release();
m_iterCamera++;
}
I've got stored the cameras stored in a vector of INPCamera, so I called them by an iterator. I've tried not using the vector but the problem is the same.
This method is imported on another DLL an called with a bucle in a thread. Before this way, I tried the method asking directky (not by another method or DLL) and the error is the same.
Thanks a lot
Eduardo Valtuille
Re: Problem with method GetFrame in Visual C**
change this line:
if(m_hExecutionResult==S_OK){
to this:
if(AuxFrame!=NULL){
That will solve your problem. The reason is that the GetFrame() call will succeed even if there is no frame available. In which case you need to check to see if AuxFrame is NULL (which means there was no available frame). In your case you check to see if the GetFrame() call was successful then you process to try and read objects from a NULL object.
Let me know if you have more questions.
if(m_hExecutionResult==S_OK){
to this:
if(AuxFrame!=NULL){
That will solve your problem. The reason is that the GetFrame() call will succeed even if there is no frame available. In which case you need to check to see if AuxFrame is NULL (which means there was no available frame). In your case you check to see if the GetFrame() call was successful then you process to try and read objects from a NULL object.
Let me know if you have more questions.
-
- Posts: 31
- Joined: Wed Jan 09, 2008 1:25 am
Re: Problem with method GetFrame in Visual C**
Hello again!
Using AuxFrame!=NULL doesn't resolve the problem because the most of the time there's nothing to capture so the most of the frames are NULL by this reason. Is there any other solution that you know?
Thanks again...
Using AuxFrame!=NULL doesn't resolve the problem because the most of the time there's nothing to capture so the most of the frames are NULL by this reason. Is there any other solution that you know?
Thanks again...
Re: Problem with method GetFrame in Visual C**
The typical problems to accessing the cameras tend to be centered around properly creating/deleting COM objects or using NULL COM objects. Two more issues in the code above are:
/// Free the last frame
AuxFrame=NULL;
AuxFrame.Release();
This will crash immediately because you're callig a method of a NULL object. The second problem with this is that you're doing this regardless of whether a frame was successfully returned from GetFrame() or not. You only want to call .Release() after using a valid frame.
If you want to send over your code I will help you get it working properly.
/// Free the last frame
AuxFrame=NULL;
AuxFrame.Release();
This will crash immediately because you're callig a method of a NULL object. The second problem with this is that you're doing this regardless of whether a frame was successfully returned from GetFrame() or not. You only want to call .Release() after using a valid frame.
If you want to send over your code I will help you get it working properly.
-
- Posts: 31
- Joined: Wed Jan 09, 2008 1:25 am
Re: Problem with method GetFrame in Visual C**
Here is the code of all the mehod that ask for the frame in the cameras:
/********************************************************************************
/**
* CaptureImage of the CAdquisitionOptiTrackV100DLL Class
* @author Eduardo Valtuille Fernandez
* @date 16/11/2007
* @version 1.0
* This method receive a pointer to a vector. Call the most recently frame on every camera, search on them
the objects and store on the received vector all the points located.
*/
int CAdquisitionOptiTrackV100DLL::CaptureImage(std::vector *PointCollection){
/// Iterator to call every camera in the system
std::vector>::iterator m_iterCamera;
for(m_iterCamera=m_listCamera.begin(); m_iterCamera!=m_listCamera.end(); ){
/// Store the Serial of the camera in use
(*m_iterCamera)->get_SerialNumber(&m_lSerial);
/// Declare the object to store the frame from the camera
CComPtr AuxFrame;
/// Store the last frame in the camera
m_hExecutionResult = (*m_iterCamera)->GetFrame(0,&(AuxFrame));
if(m_hExecutionResult==S_OK){
/// Variable to store the number of objects in a frame
LONG lNumberObjects = 0;
/// Look for the number of objects in the frame
if((AuxFrame)) m_hExecutionResult = (AuxFrame)->get_Count(&lNumberObjects);
/// If there are any object, look for its coordenates and store them into the received vector
if(lNumberObjects>0){
/// Variable used like a counter when searching for the position of the objects
int c;
for(c=0;c spObject;
/// Store the Object
(AuxFrame)->Item(c, &spObject);
/// The Object to store the values from the camera Object
CapturedPoint* auxPoint;
auxPoint = (CapturedPoint*)malloc(sizeof(CapturedPoint));
/// Store the values from the Camera Object
auxPoint->Serial = m_lSerial;
CComVariant CComAux;
m_hExecutionResult = spObject->get_X(&CComAux);
auxPoint->CorX = CComAux.dblVal;
m_hExecutionResult = spObject->get_Y(&CComAux);
auxPoint->CorY = CComAux.dblVal;
m_hExecutionResult = spObject->get_Area(&CComAux);
auxPoint->Superficie = CComAux.dblVal;
/// Add the point to the received vector
PointCollection->push_back(auxPoint);
spObject = NULL;
}
}
}
/// Free the last frame
if(AuxFrame!=NULL) AuxFrame->Free();
AuxFrame=NULL;
AuxFrame.Release();
m_iterCamera++;
}
return 0;
}
This method is part of a DLL and is called from a bucle in another DLL.
/********************************************************************************
/**
* CaptureImage of the CAdquisitionOptiTrackV100DLL Class
* @author Eduardo Valtuille Fernandez
* @date 16/11/2007
* @version 1.0
* This method receive a pointer to a vector. Call the most recently frame on every camera, search on them
the objects and store on the received vector all the points located.
*/
int CAdquisitionOptiTrackV100DLL::CaptureImage(std::vector *PointCollection){
/// Iterator to call every camera in the system
std::vector>::iterator m_iterCamera;
for(m_iterCamera=m_listCamera.begin(); m_iterCamera!=m_listCamera.end(); ){
/// Store the Serial of the camera in use
(*m_iterCamera)->get_SerialNumber(&m_lSerial);
/// Declare the object to store the frame from the camera
CComPtr AuxFrame;
/// Store the last frame in the camera
m_hExecutionResult = (*m_iterCamera)->GetFrame(0,&(AuxFrame));
if(m_hExecutionResult==S_OK){
/// Variable to store the number of objects in a frame
LONG lNumberObjects = 0;
/// Look for the number of objects in the frame
if((AuxFrame)) m_hExecutionResult = (AuxFrame)->get_Count(&lNumberObjects);
/// If there are any object, look for its coordenates and store them into the received vector
if(lNumberObjects>0){
/// Variable used like a counter when searching for the position of the objects
int c;
for(c=0;c spObject;
/// Store the Object
(AuxFrame)->Item(c, &spObject);
/// The Object to store the values from the camera Object
CapturedPoint* auxPoint;
auxPoint = (CapturedPoint*)malloc(sizeof(CapturedPoint));
/// Store the values from the Camera Object
auxPoint->Serial = m_lSerial;
CComVariant CComAux;
m_hExecutionResult = spObject->get_X(&CComAux);
auxPoint->CorX = CComAux.dblVal;
m_hExecutionResult = spObject->get_Y(&CComAux);
auxPoint->CorY = CComAux.dblVal;
m_hExecutionResult = spObject->get_Area(&CComAux);
auxPoint->Superficie = CComAux.dblVal;
/// Add the point to the received vector
PointCollection->push_back(auxPoint);
spObject = NULL;
}
}
}
/// Free the last frame
if(AuxFrame!=NULL) AuxFrame->Free();
AuxFrame=NULL;
AuxFrame.Release();
m_iterCamera++;
}
return 0;
}
This method is part of a DLL and is called from a bucle in another DLL.
Re: Problem with method GetFrame in Visual C**
change this:
/// Free the last frame
if(AuxFrame!=NULL) AuxFrame->Free();
AuxFrame=NULL;
AuxFrame.Release();
to this:
if(AuxFrame)
{
AuxFrame.Release();
AuxFrame = NULL;
}
/// Free the last frame
if(AuxFrame!=NULL) AuxFrame->Free();
AuxFrame=NULL;
AuxFrame.Release();
to this:
if(AuxFrame)
{
AuxFrame.Release();
AuxFrame = NULL;
}