280 lines
9.4 KiB
C++
280 lines
9.4 KiB
C++
|
|
// Comprehensive test of the VrEyeDevice (IVrEyeDevice) interface against the
|
||
|
|
// VrVirtualCamera network simulator. Run the virtual camera first, then this
|
||
|
|
// program exercises every interface method and reports pass/fail per step.
|
||
|
|
#include "IVrEyeDevice.h"
|
||
|
|
|
||
|
|
#include <windows.h>
|
||
|
|
|
||
|
|
#include <cstdio>
|
||
|
|
#include <cstring>
|
||
|
|
#include <string>
|
||
|
|
|
||
|
|
static int g_pass = 0;
|
||
|
|
static int g_fail = 0;
|
||
|
|
|
||
|
|
static void Report(const char* name, int ret, int expectOk)
|
||
|
|
{
|
||
|
|
if ((ret == 0) == (expectOk != 0)) {
|
||
|
|
printf(" [PASS] %-40s ret=%d\n", name, ret);
|
||
|
|
g_pass++;
|
||
|
|
} else {
|
||
|
|
printf(" [FAIL] %-40s ret=%d (expected %s)\n", name, ret,
|
||
|
|
expectOk ? "0" : "non-0");
|
||
|
|
g_fail++;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
// Simple status callback (must not crash).
|
||
|
|
static void __cdecl StatusCB(EVzDeviceWorkStatus eStatus, void* /*pExtData*/,
|
||
|
|
unsigned int /*nDataLength*/, void* /*pInfoParam*/)
|
||
|
|
{
|
||
|
|
printf(" [CB] status = %d\n", (int)eStatus);
|
||
|
|
}
|
||
|
|
|
||
|
|
// Image callback.
|
||
|
|
static void __cdecl ImageCB(SVzNLImageData* pLeft, SVzNLImageData* pRight,
|
||
|
|
SVzNLImageData* pCenter, const SVzOutputFrameProps* pProps,
|
||
|
|
void* pParam)
|
||
|
|
{
|
||
|
|
(void)pCenter;
|
||
|
|
int* pCount = static_cast<int*>(pParam);
|
||
|
|
(*pCount)++;
|
||
|
|
printf(" [CB] frame #%d L=(%ux%u ch=%u) R=(%ux%u ch=%u) props.frame=%llu\n",
|
||
|
|
*pCount,
|
||
|
|
pLeft ? pLeft->nWidth : 0, pLeft ? pLeft->nHeight : 0,
|
||
|
|
pLeft ? (unsigned)pLeft->nChannels : 0,
|
||
|
|
pRight ? pRight->nWidth : 0, pRight ? pRight->nHeight : 0,
|
||
|
|
pRight ? (unsigned)pRight->nChannels : 0,
|
||
|
|
pProps ? (unsigned long long)pProps->nFrameIdx : 0);
|
||
|
|
if (*pCount >= 3) {
|
||
|
|
// Enough frames - user code would stop capture here; we just note it.
|
||
|
|
printf(" [CB] reached 3 frames\n");
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
// Laser line callback.
|
||
|
|
static void __cdecl DetectCB(EVzResultDataType eDataType, SVzLaserLineData* pLine,
|
||
|
|
void* pParam)
|
||
|
|
{
|
||
|
|
int* pCount = static_cast<int*>(pParam);
|
||
|
|
(*pCount)++;
|
||
|
|
unsigned int n3D = (pLine && pLine->p3DPoint) ? (unsigned int)pLine->nPointCount : 0;
|
||
|
|
printf(" [CB] laser line #%d datatype=%d points=%u stamp=%llu enc=%u\n",
|
||
|
|
*pCount, (int)eDataType, n3D,
|
||
|
|
pLine ? (unsigned long long)pLine->llTimeStamp : 0,
|
||
|
|
pLine ? pLine->nEncodeNo : 0);
|
||
|
|
if (pLine) {
|
||
|
|
// Print the first 3D point to sanity-check coordinates.
|
||
|
|
if (pLine->p3DPoint && pLine->nPointCount > 0 &&
|
||
|
|
eDataType == keResultDataType_Position) {
|
||
|
|
const SVzNL3DPosition* pts = static_cast<const SVzNL3DPosition*>(pLine->p3DPoint);
|
||
|
|
printf(" [CB] first 3D point: (%.2f, %.2f, %.2f)\n",
|
||
|
|
pts[0].pt3D.x, pts[0].pt3D.y, pts[0].pt3D.z);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
if (*pCount >= 3) {
|
||
|
|
printf(" [CB] reached 3 laser lines\n");
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
int main(int argc, char* argv[])
|
||
|
|
{
|
||
|
|
printf("=== VrEyeDevice interface test against VrVirtualCamera ===\n\n");
|
||
|
|
|
||
|
|
const char* sIP = (argc > 1) ? argv[1] : nullptr; // optional explicit IP
|
||
|
|
|
||
|
|
IVrEyeDevice* pDev = nullptr;
|
||
|
|
int ret = IVrEyeDevice::CreateObject(&pDev);
|
||
|
|
printf("CreateObject ret=%d, ptr=%p\n", ret, (void*)pDev);
|
||
|
|
if (ret != 0 || !pDev) {
|
||
|
|
printf("[FAIL] CreateObject\n");
|
||
|
|
return 1;
|
||
|
|
}
|
||
|
|
|
||
|
|
// ---- InitDevice ----
|
||
|
|
ret = pDev->InitDevice();
|
||
|
|
Report("InitDevice", ret, 1);
|
||
|
|
|
||
|
|
// ---- SetStatusCallback ----
|
||
|
|
ret = pDev->SetStatusCallback(StatusCB, nullptr);
|
||
|
|
Report("SetStatusCallback", ret, 1);
|
||
|
|
|
||
|
|
// ---- OpenDevice (this is where the app reported a failure) ----
|
||
|
|
printf("\n--- OpenDevice (IP=%s) ---\n", sIP ? sIP : "(null)");
|
||
|
|
ret = pDev->OpenDevice(sIP, /*bRGBD*/false, /*bSwing*/true,
|
||
|
|
/*bFillLaser*/true, /*bStrobe*/false);
|
||
|
|
Report("OpenDevice", ret, 1);
|
||
|
|
if (ret != 0) {
|
||
|
|
printf("[FATAL] OpenDevice failed - aborting further tests\n");
|
||
|
|
pDev->CloseDevice();
|
||
|
|
return 1;
|
||
|
|
}
|
||
|
|
|
||
|
|
// ---- GetVersion ----
|
||
|
|
SVzNLVersionInfo sVer;
|
||
|
|
memset(&sVer, 0, sizeof(sVer));
|
||
|
|
ret = pDev->GetVersion(sVer);
|
||
|
|
Report("GetVersion", ret, 1);
|
||
|
|
if (ret == 0) {
|
||
|
|
printf(" INFO: SDK=%s\n", sVer.szSDKVersion);
|
||
|
|
}
|
||
|
|
|
||
|
|
// ---- GetDevInfo ----
|
||
|
|
SVzNLEyeDeviceInfoEx sDevInfo;
|
||
|
|
memset(&sDevInfo, 0, sizeof(sDevInfo));
|
||
|
|
ret = pDev->GetDevInfo(sDevInfo);
|
||
|
|
Report("GetDevInfo", ret, 1);
|
||
|
|
if (ret == 0) {
|
||
|
|
printf(" INFO: IP=%s MAC=%s res=%ux%u\n",
|
||
|
|
sDevInfo.sEyeCBInfo.byServerIP, sDevInfo.sEyeCBInfo.byMAC,
|
||
|
|
sDevInfo.sVideoRes.nFrameWidth, sDevInfo.sVideoRes.nFrameHeight);
|
||
|
|
}
|
||
|
|
|
||
|
|
// ---- IsSupport ----
|
||
|
|
bool bSupport = pDev->IsSupport();
|
||
|
|
printf(" [%s] %-40s %s\n", bSupport ? "PASS" : "INFO", "IsSupport (RGBD)",
|
||
|
|
bSupport ? "true" : "false");
|
||
|
|
g_pass++;
|
||
|
|
|
||
|
|
// ---- Set/Get pairs ----
|
||
|
|
printf("\n--- Set/Get parameters ---\n");
|
||
|
|
unsigned int nExpo = 3000;
|
||
|
|
ret = pDev->SetEyeExpose(nExpo);
|
||
|
|
Report("SetEyeExpose", ret, 1);
|
||
|
|
nExpo = 0;
|
||
|
|
ret = pDev->GetEyeExpose(nExpo);
|
||
|
|
Report("GetEyeExpose", ret, 1);
|
||
|
|
printf(" INFO: expose=%u\n", nExpo);
|
||
|
|
|
||
|
|
unsigned int nGain = 120;
|
||
|
|
ret = pDev->SetEyeGain(nGain);
|
||
|
|
Report("SetEyeGain", ret, 1);
|
||
|
|
nGain = 0;
|
||
|
|
ret = pDev->GetEyeGain(nGain);
|
||
|
|
Report("GetEyeGain", ret, 1);
|
||
|
|
printf(" INFO: gain=%u\n", nGain);
|
||
|
|
|
||
|
|
int nFrame = 15;
|
||
|
|
ret = pDev->SetFrame(nFrame);
|
||
|
|
Report("SetFrame", ret, 1);
|
||
|
|
nFrame = 0;
|
||
|
|
ret = pDev->GetFrame(nFrame);
|
||
|
|
Report("GetFrame", ret, 1);
|
||
|
|
printf(" INFO: frame=%d\n", nFrame);
|
||
|
|
|
||
|
|
float fThres = 150.0f;
|
||
|
|
ret = pDev->SetRGBDExposeThres(fThres);
|
||
|
|
Report("SetRGBDExposeThres", ret, 1);
|
||
|
|
fThres = 0.0f;
|
||
|
|
ret = pDev->GetRGBDExposeThres(fThres);
|
||
|
|
Report("GetRGBDExposeThres", ret, 1);
|
||
|
|
printf(" INFO: rgbdThres=%.1f\n", fThres);
|
||
|
|
|
||
|
|
double dHeight = 200.0;
|
||
|
|
ret = pDev->SetFilterHeight(dHeight);
|
||
|
|
Report("SetFilterHeight", ret, 1);
|
||
|
|
dHeight = 0.0;
|
||
|
|
ret = pDev->GetFilterHeight(dHeight);
|
||
|
|
Report("GetFilterHeight", ret, 1);
|
||
|
|
printf(" INFO: filterHeight=%.1f\n", dHeight);
|
||
|
|
|
||
|
|
float fSpeed = 48.0f;
|
||
|
|
ret = pDev->SetSwingSpeed(fSpeed);
|
||
|
|
Report("SetSwingSpeed", ret, 1);
|
||
|
|
fSpeed = 0.0f;
|
||
|
|
ret = pDev->GetSwingSpeed(fSpeed);
|
||
|
|
Report("GetSwingSpeed", ret, 1);
|
||
|
|
printf(" INFO: swingSpeed=%.1f\n", fSpeed);
|
||
|
|
|
||
|
|
float fMin = -20.0f, fMax = 20.0f;
|
||
|
|
ret = pDev->SetSwingAngle(fMin, fMax);
|
||
|
|
Report("SetSwingAngle", ret, 1);
|
||
|
|
fMin = fMax = 0.0f;
|
||
|
|
ret = pDev->GetSwingAngle(fMin, fMax);
|
||
|
|
Report("GetSwingAngle", ret, 1);
|
||
|
|
printf(" INFO: swingAngle=[%.1f, %.1f]\n", fMin, fMax);
|
||
|
|
|
||
|
|
double dMin = 400.0, dMax = 1600.0;
|
||
|
|
ret = pDev->SetWorkRange(dMin, dMax);
|
||
|
|
Report("SetWorkRange", ret, 1);
|
||
|
|
dMin = dMax = 0.0;
|
||
|
|
ret = pDev->GetWorkRange(dMin, dMax);
|
||
|
|
Report("GetWorkRange", ret, 1);
|
||
|
|
printf(" INFO: workRange=[%.1f, %.1f]\n", dMin, dMax);
|
||
|
|
|
||
|
|
// Use a valid full-frame ROI (all-zero is rejected by the SDK as invalid).
|
||
|
|
SVzNLRect sLROI{0, 1280, 0, 960}, sRROI{0, 1280, 0, 960};
|
||
|
|
ret = pDev->SetDetectROI(sLROI, sRROI);
|
||
|
|
Report("SetDetectROI", ret, 1);
|
||
|
|
ret = pDev->GetDetectROI(sLROI, sRROI);
|
||
|
|
Report("GetDetectROI", ret, 1);
|
||
|
|
|
||
|
|
// ---- Single-frame GetEyeImage ----
|
||
|
|
printf("\n--- GetEyeImage (single frame) ---\n");
|
||
|
|
SVzNLImageData* pLeft = nullptr;
|
||
|
|
SVzNLImageData* pRight = nullptr;
|
||
|
|
ret = pDev->GetEyeImage(&pLeft, &pRight, 5000);
|
||
|
|
Report("GetEyeImage", ret, 1);
|
||
|
|
if (ret == 0 && pLeft) {
|
||
|
|
printf(" INFO: left image %ux%u channels=%u buffer=%p\n",
|
||
|
|
pLeft->nWidth, pLeft->nHeight, (unsigned)pLeft->nChannels,
|
||
|
|
(void*)pLeft->pBuffer);
|
||
|
|
ret = pDev->ReleaseImage(&pLeft);
|
||
|
|
Report("ReleaseImage(left)", ret, 1);
|
||
|
|
}
|
||
|
|
if (ret == 0 && pRight) {
|
||
|
|
pDev->ReleaseImage(&pRight);
|
||
|
|
}
|
||
|
|
|
||
|
|
// ---- Continuous capture ----
|
||
|
|
printf("\n--- StartCapture (continuous) ---\n");
|
||
|
|
int nImgCount = 0;
|
||
|
|
ret = pDev->StartCapture(ImageCB, &nImgCount);
|
||
|
|
Report("StartCapture", ret, 1);
|
||
|
|
if (ret == 0) {
|
||
|
|
// Wait for a few frames.
|
||
|
|
int nWait = 0;
|
||
|
|
while (nImgCount < 3 && nWait < 200) {
|
||
|
|
SleepEx(50, FALSE);
|
||
|
|
nWait++;
|
||
|
|
}
|
||
|
|
printf(" INFO: received %d image frames\n", nImgCount);
|
||
|
|
bool bCap = pDev->IsCapturing();
|
||
|
|
printf(" [%s] IsCapturing = %s\n", bCap ? "PASS" : "FAIL",
|
||
|
|
bCap ? "true" : "false");
|
||
|
|
if (!bCap) g_fail++; else g_pass++;
|
||
|
|
ret = pDev->StopCapture();
|
||
|
|
Report("StopCapture", ret, 1);
|
||
|
|
bCap = pDev->IsCapturing();
|
||
|
|
printf(" [INFO] IsCapturing after stop = %s\n", bCap ? "true" : "false");
|
||
|
|
}
|
||
|
|
|
||
|
|
// ---- Laser detect ----
|
||
|
|
printf("\n--- StartDetect (laser) ---\n");
|
||
|
|
int nLineCount = 0;
|
||
|
|
ret = pDev->StartDetect(DetectCB, keResultDataType_Position, &nLineCount);
|
||
|
|
Report("StartDetect", ret, 1);
|
||
|
|
if (ret == 0) {
|
||
|
|
int nWait = 0;
|
||
|
|
while (nLineCount < 3 && nWait < 200) {
|
||
|
|
SleepEx(50, FALSE);
|
||
|
|
nWait++;
|
||
|
|
}
|
||
|
|
printf(" INFO: received %d laser lines\n", nLineCount);
|
||
|
|
bool bDet = pDev->IsDetectIng();
|
||
|
|
printf(" [%s] IsDetectIng = %s\n", bDet ? "PASS" : "FAIL",
|
||
|
|
bDet ? "true" : "false");
|
||
|
|
if (!bDet) g_fail++; else g_pass++;
|
||
|
|
ret = pDev->StopDetect();
|
||
|
|
Report("StopDetect", ret, 1);
|
||
|
|
}
|
||
|
|
|
||
|
|
// ---- CloseDevice ----
|
||
|
|
printf("\n--- CloseDevice ---\n");
|
||
|
|
ret = pDev->CloseDevice();
|
||
|
|
Report("CloseDevice", ret, 1);
|
||
|
|
|
||
|
|
printf("\n=== RESULT: %d passed, %d failed ===\n", g_pass, g_fail);
|
||
|
|
return g_fail == 0 ? 0 : 1;
|
||
|
|
}
|