padu
October 1, 2007, 20:02:25
Hello,
I'm trying to learn how to operate the classlib and for that I'm writing a very simple test application.
The application runs from the command prompt and shall initialize the device, grab a frame and pass it along to a image processing function that I will write latter on.
Here's the source code:
// PromptCapture.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include "PromptCapture.h"
#include "PersonTracker.h"
#include "tisudshl.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#endif
// The one and only application object
CWinApp theApp;
using namespace std;
int _tmain(int argc, TCHAR* argv[], TCHAR* envp[])
{
int nRetCode = 0;
// initialize MFC and print and error on failure
if (!AfxWinInit(::GetModuleHandle(NULL), NULL, ::GetCommandLine(), 0))
{
// TODO: change error code to suit your needs
_tprintf(_T("Fatal Error: MFC initialization failed\n"));
nRetCode = 1;
}
else
{
_tprintf(_T("\nPrompt Capture is a stepstone for the PersonFollowing Project\n"));
_tprintf(_T("SDSU - IMSL: for SPAWAR\n"));
_tprintf(_T("================================================== ===========\n\n"));
LARGE_INTEGER ticksPerSecond;
LARGE_INTEGER tick1, tick2; // A point in time
double totalTime;
// get the high resolution counter's accuracy
QueryPerformanceFrequency(&ticksPerSecond);
//initialize camera
printf("CAMERA INITIALIZATION\n");
QueryPerformanceCounter(&tick1);
if( ! DShowLib::InitLibrary( "------------" ) )
{
return FALSE;
}
DShowLib::Grabber grabber;
QueryPerformanceCounter(&tick2);
totalTime = (double(tick2.QuadPart - tick1.QuadPart) / ticksPerSecond.QuadPart);
if( !grabber.showDevicePage() || !grabber.isDevValid() )
{
return -1;
}
QueryPerformanceCounter(&tick1);
grabber.startLive(false);
if (grabber.isLive())
printf("Camera is live\n");
else
printf("Camera is not live\n");
QueryPerformanceCounter(&tick2);
totalTime += (double(tick2.QuadPart - tick1.QuadPart) / ticksPerSecond.QuadPart);
printf("Camera initialized in %f milliseconds\n\n", totalTime*1000);
//capture a frame
printf("FRAME GRABBING\n");
QueryPerformanceCounter(&tick1);
//capture frame here
// Snap one image and copy it into the MemBufferCollection.
grabber.snapImages(1);
DShowLib::Error e = grabber.getLastError();
if (e.isError())
{
// Display the error.
cout << "error\n";
printf(e.c_str());
return -1;
}
DShowLib::Grabber::tMemBufferPtr pBuff = grabber.getActiveMemBuffer();
pBuff->save("test.jpg");
QueryPerformanceCounter(&tick2);
totalTime = (double(tick2.QuadPart - tick1.QuadPart) / ticksPerSecond.QuadPart);
// Display real numbers
printf("Frame captured in %f milliseconds\n\n", totalTime*1000);
//calculate person position from captured frame
printf("PERSON TRACKING\n");
QueryPerformanceCounter(&tick1);
CPersonTracker* personTracker = new CPersonTracker();
int pos = personTracker->GetLastKnownPersonPosition(0);
QueryPerformanceCounter(&tick2);
totalTime = (double(tick2.QuadPart - tick1.QuadPart) / ticksPerSecond.QuadPart);
printf("Person centroid is %d,%d.\n", 0,0);
printf("Person bounding box is (%d,%d)-(%d,%d).\n", 0,0,0,0);
printf("Person tracked in %f milliseconds\n", totalTime*1000);
grabber.stopLive();
delete personTracker;
}
return nRetCode;
}
and here's the output of it:
Prompt Capture is a stepstone for the PersonFollowing Project
SDSU - IMSL: for SPAWAR
================================================== ======
CAMERA INITIALIZATION
Camera is live
Camera initialized in 74.672840 milliseconds
FRAME GRABBING
error
Unknown error
The error happens when I try to use "grabber.snapImages(1)".
Is there a precondition to it? At that point, the camera is initialized and live.
Thanks
Padu
I'm trying to learn how to operate the classlib and for that I'm writing a very simple test application.
The application runs from the command prompt and shall initialize the device, grab a frame and pass it along to a image processing function that I will write latter on.
Here's the source code:
// PromptCapture.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include "PromptCapture.h"
#include "PersonTracker.h"
#include "tisudshl.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#endif
// The one and only application object
CWinApp theApp;
using namespace std;
int _tmain(int argc, TCHAR* argv[], TCHAR* envp[])
{
int nRetCode = 0;
// initialize MFC and print and error on failure
if (!AfxWinInit(::GetModuleHandle(NULL), NULL, ::GetCommandLine(), 0))
{
// TODO: change error code to suit your needs
_tprintf(_T("Fatal Error: MFC initialization failed\n"));
nRetCode = 1;
}
else
{
_tprintf(_T("\nPrompt Capture is a stepstone for the PersonFollowing Project\n"));
_tprintf(_T("SDSU - IMSL: for SPAWAR\n"));
_tprintf(_T("================================================== ===========\n\n"));
LARGE_INTEGER ticksPerSecond;
LARGE_INTEGER tick1, tick2; // A point in time
double totalTime;
// get the high resolution counter's accuracy
QueryPerformanceFrequency(&ticksPerSecond);
//initialize camera
printf("CAMERA INITIALIZATION\n");
QueryPerformanceCounter(&tick1);
if( ! DShowLib::InitLibrary( "------------" ) )
{
return FALSE;
}
DShowLib::Grabber grabber;
QueryPerformanceCounter(&tick2);
totalTime = (double(tick2.QuadPart - tick1.QuadPart) / ticksPerSecond.QuadPart);
if( !grabber.showDevicePage() || !grabber.isDevValid() )
{
return -1;
}
QueryPerformanceCounter(&tick1);
grabber.startLive(false);
if (grabber.isLive())
printf("Camera is live\n");
else
printf("Camera is not live\n");
QueryPerformanceCounter(&tick2);
totalTime += (double(tick2.QuadPart - tick1.QuadPart) / ticksPerSecond.QuadPart);
printf("Camera initialized in %f milliseconds\n\n", totalTime*1000);
//capture a frame
printf("FRAME GRABBING\n");
QueryPerformanceCounter(&tick1);
//capture frame here
// Snap one image and copy it into the MemBufferCollection.
grabber.snapImages(1);
DShowLib::Error e = grabber.getLastError();
if (e.isError())
{
// Display the error.
cout << "error\n";
printf(e.c_str());
return -1;
}
DShowLib::Grabber::tMemBufferPtr pBuff = grabber.getActiveMemBuffer();
pBuff->save("test.jpg");
QueryPerformanceCounter(&tick2);
totalTime = (double(tick2.QuadPart - tick1.QuadPart) / ticksPerSecond.QuadPart);
// Display real numbers
printf("Frame captured in %f milliseconds\n\n", totalTime*1000);
//calculate person position from captured frame
printf("PERSON TRACKING\n");
QueryPerformanceCounter(&tick1);
CPersonTracker* personTracker = new CPersonTracker();
int pos = personTracker->GetLastKnownPersonPosition(0);
QueryPerformanceCounter(&tick2);
totalTime = (double(tick2.QuadPart - tick1.QuadPart) / ticksPerSecond.QuadPart);
printf("Person centroid is %d,%d.\n", 0,0);
printf("Person bounding box is (%d,%d)-(%d,%d).\n", 0,0,0,0);
printf("Person tracked in %f milliseconds\n", totalTime*1000);
grabber.stopLive();
delete personTracker;
}
return nRetCode;
}
and here's the output of it:
Prompt Capture is a stepstone for the PersonFollowing Project
SDSU - IMSL: for SPAWAR
================================================== ======
CAMERA INITIALIZATION
Camera is live
Camera initialized in 74.672840 milliseconds
FRAME GRABBING
error
Unknown error
The error happens when I try to use "grabber.snapImages(1)".
Is there a precondition to it? At that point, the camera is initialized and live.
Thanks
Padu