Last active
December 16, 2015 05:19
-
-
Save elliotwoods/5383487 to your computer and use it in GitHub Desktop.
ximea sample with fps display
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// xiSample.cpp : hacked to show fps meter | |
// | |
#include "stdafx.h" | |
#include <ctime> | |
#ifdef __APPLE__ | |
#include <m3api/xiApi.h> | |
#include <m3api/xiExt.h> | |
#else | |
#include "xiApi.h" | |
#include "xiExt.h" | |
#endif | |
#define HandleResult(res,place) if (res!=XI_OK) {printf("Error after %s (%d)",place,res);goto finish;} | |
#include <CoreServices/CoreServices.h> | |
float GetTime() | |
{ | |
Nanoseconds time = AbsoluteToNanoseconds(UpTime()); | |
return float( * (uint64_t*) & time ) / float(1e9); | |
} | |
int _tmain(int argc, _TCHAR* argv[]) | |
{ | |
// image buffer | |
XI_IMG image; | |
image.size = sizeof(XI_IMG); | |
image.bp = NULL; | |
image.bp_size = 0; | |
// Sample for XIMEA API V2.10 | |
HANDLE xiH = NULL; | |
XI_RETURN stat = XI_OK; | |
// Get number of camera devices | |
DWORD dwNumberOfDevices = 0; | |
stat = xiGetNumberDevices(&dwNumberOfDevices); | |
HandleResult(stat,"xiGetNumberDevices (no camera found)"); | |
if (!dwNumberOfDevices) | |
{ | |
printf("No camera found\n"); | |
goto finish; | |
} | |
// Retrieving a handle to the camera device | |
stat = xiOpenDevice(0, &xiH); | |
HandleResult(stat,"xiOpenDevice"); | |
// Setting "exposure" parameter (10ms=10000us) | |
stat = xiSetParamInt(xiH, XI_PRM_EXPOSURE, 2000); | |
HandleResult(stat,"xiSetParam (exposure set)"); | |
xiStartAcquisition(xiH); | |
HandleResult(stat,"xiStartAcquisition"); | |
#define EXPECTED_IMAGES 1000 | |
for (int images=0;images < EXPECTED_IMAGES;images++) | |
{ | |
// getting image from camera | |
stat = xiGetImage(xiH, 5000, &image); | |
HandleResult(stat,"xiGetImage"); | |
printf("Image %d (%dx%d) received from camera\n", images, (int)image.width, (int)image.height); | |
float thisFrame = GetTime(); | |
static float lastFrame = thisFrame; | |
float interval = thisFrame - lastFrame; | |
lastFrame = thisFrame; | |
float fps = 1.0f / interval; | |
printf("interval = %.2fms \tfps = %.2f\n", interval * 1000.0f, fps); | |
} | |
printf("time resolution = %.3fms\n", 1000.0f / float(CLOCKS_PER_SEC)); | |
finish: | |
// Close device | |
if (xiH) | |
xiCloseDevice(xiH); | |
printf("Done\n"); | |
#ifdef WIN32 | |
Sleep(2000); | |
#endif | |
return 0; | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment