hi,
with the samples code, I add a function as below
PsDepthRange depthRange = PsFarRange;
status = Ps2_SetDepthRange(deviceHandle, sessionIndex, depthRange);
the return status is -255
I want to know how can I modify the depthrange and if I need the depthrange(1-3 m),how can I set the parameter?
xxm
Ps2_SetDepthRange should be called after Ps2_StartStream.
Share your code, and I will do more check
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。
int main(int argc, char *argv[])
{
#ifdef DCAM_305
return 0;
#else
PsReturnStatus status;
uint32_t deviceIndex = 0;
uint32_t deviceCount = 0;
uint32_t slope = 1450;
uint32_t wdrSlope = 4400;
uint32_t wdrRange1Slope = 1450;
uint32_t wdrRange2Slope = 4400;
uint32_t wdrRange3Slope = 6000;
PsDepthRange depthRange = PsFarRange;
PsDataMode dataMode = PsDepthAndIR_30;
PsWDROutputMode wdrMode = { PsWDRTotalRange_Two, PsNearRange, 1, PsFarRange, 1, PsUnknown, 1 };
bool f_bWDRMode = false;
bool bWDRStyle = true;
status = Ps2_Initialize();
if (status != PsReturnStatus::PsRetOK)
{
cout << "PsInitialize failed!" << endl;
system("pause");
return -1;
}
GET:
status = Ps2_GetDeviceCount(&deviceCount);
if (status != PsReturnStatus::PsRetOK)
{
cout << "PsGetDeviceCount failed!" << endl;
#ifdef DCAM_800
this_thread::sleep_for(chrono::seconds(1));
goto GET;
#else
system("pause");
return -1;
#endif
}
cout << "Get device count: " << deviceCount << endl;
if (0 == deviceCount)
{
this_thread::sleep_for(chrono::seconds(1));
goto GET;
}
Ps2_SetHotPlugStatusCallback(HotPlugStateCallback);
PsDeviceInfo* pDeviceListInfo = new PsDeviceInfo[deviceCount];
status = Ps2_GetDeviceListInfo(pDeviceListInfo, deviceCount);
PsDeviceHandle deviceHandle = 0;
status = Ps2_OpenDevice(pDeviceListInfo->uri, &deviceHandle);
if (status != PsReturnStatus::PsRetOK)
{
cout << "OpenDevice failed!" << endl;
system("pause");
return -1;
}
uint32_t sessionIndex = 0;
status = Ps2_StartStream(deviceHandle, sessionIndex);
if (status != PsReturnStatus::PsRetOK)
{
cout << "StartStream failed!" << endl;
system("pause");
return -1;
}
PsCameraParameters cameraParameters;
status = Ps2_GetCameraParameters(deviceHandle, sessionIndex, PsDepthSensor, &cameraParameters);
cout << "Get PsGetCameraParameters status: " << status << endl;
cout << "Depth Camera Intinsic: " << endl;
cout << "Fx: " << cameraParameters.fx << endl;
cout << "Cx: " << cameraParameters.cx << endl;
cout << "Fy: " << cameraParameters.fy << endl;
cout << "Cy: " << cameraParameters.cy << endl;
cout << "Depth Distortion Coefficient: " << endl;
cout << "K1: " << cameraParameters.k1 << endl;
cout << "K2: " << cameraParameters.k2 << endl;
cout << "P1: " << cameraParameters.p1 << endl;
cout << "P2: " << cameraParameters.p2 << endl;
cout << "K3: " << cameraParameters.k3 << endl;
cout << "K4: " << cameraParameters.k4 << endl;
cout << "K5: " << cameraParameters.k5 << endl;
cout << "K6: " << cameraParameters.k6 << endl;
//Get MeasuringRange
PsMeasuringRange measuringrange = { 0 };
status = Ps2_GetDataMode(deviceHandle, sessionIndex, &dataMode);
if (status != PsReturnStatus::PsRetOK)
cout << "Ps2_GetDataMode failed!" << endl;
else
cout << "Get Ps2_GetDataMode : " << dataMode << endl;
if (dataMode == PsWDR_Depth)
{
f_bWDRMode = true;
status = Ps2_GetWDROutputMode(deviceHandle, sessionIndex, &wdrMode);
if (status != PsReturnStatus::PsRetOK)
cout << "Ps2_GetWDROutputMode failed!" << endl;
else
{
if (wdrMode.totalRange == PsWDRTotalRange_Two)
{
depthRange = wdrMode.range2;
status = Ps2_GetMeasuringRange(deviceHandle, sessionIndex, (PsDepthRange)wdrMode.range1, &measuringrange);
if (status != PsReturnStatus::PsRetOK)
cout << "Ps2_GetMeasuringRange failed!" << endl;
else
{
switch ((PsDepthRange)wdrMode.range1)
{
case PsNearRange:
case PsXNearRange:
case PsXXNearRange:
wdrRange1Slope = measuringrange.effectDepthMaxNear;
break;
case PsMidRange:
case PsXMidRange:
case PsXXMidRange:
wdrRange1Slope = measuringrange.effectDepthMaxMid;
break;
case PsFarRange:
case PsXFarRange:
case PsXXFarRange:
wdrRange1Slope = measuringrange.effectDepthMaxFar;
break;
default:
break;
}
cout << "wdrRange1Slope = " << wdrRange1Slope << endl;
}
status = Ps2_GetMeasuringRange(deviceHandle, sessionIndex, (PsDepthRange)wdrMode.range2, &measuringrange);
if (status != PsReturnStatus::PsRetOK)
cout << "Ps2_GetMeasuringRange failed!" << endl;
else
{
switch ((PsDepthRange)wdrMode.range2)
{
case PsNearRange:
case PsXNearRange:
case PsXXNearRange:
wdrRange2Slope = wdrSlope == measuringrange.effectDepthMaxNear;
break;
case PsMidRange:
case PsXMidRange:
case PsXXMidRange:
wdrRange2Slope = wdrSlope = measuringrange.effectDepthMaxMid;
break;
case PsFarRange:
case PsXFarRange:
case PsXXFarRange:
wdrRange2Slope = wdrSlope = measuringrange.effectDepthMaxFar;
break;
default:
break;
}
cout << "wdrSlope = wdrRange2Slope " << wdrSlope << endl;
}
}
else if (wdrMode.totalRange == PsWDRTotalRange_Three)
{
status = Ps2_GetMeasuringRange(deviceHandle, sessionIndex, (PsDepthRange)wdrMode.range1, &measuringrange);
if (status != PsReturnStatus::PsRetOK)
cout << "Ps2_GetMeasuringRange failed!" << endl;
else
{
switch ((PsDepthRange)wdrMode.range1)
{
case PsNearRange:
case PsXNearRange:
case PsXXNearRange:
wdrRange1Slope = measuringrange.effectDepthMaxNear;
break;
case PsMidRange:
case PsXMidRange:
case PsXXMidRange:
wdrRange1Slope = measuringrange.effectDepthMaxMid;
break;
case PsFarRange:
case PsXFarRange:
case PsXXFarRange:
wdrRange1Slope = measuringrange.effectDepthMaxFar;
break;
default:
break;
}
cout << "wdrRange1Slope = " << wdrRange1Slope << endl;
}
status = Ps2_GetMeasuringRange(deviceHandle, sessionIndex, (PsDepthRange)wdrMode.range2, &measuringrange);
if (status != PsReturnStatus::PsRetOK)
cout << "Ps2_GetMeasuringRange failed!" << endl;
else
{
switch ((PsDepthRange)wdrMode.range2)
{
case PsNearRange:
case PsXNearRange:
case PsXXNearRange:
wdrRange2Slope = measuringrange.effectDepthMaxNear;
break;
case PsMidRange:
case PsXMidRange:
case PsXXMidRange:
wdrRange2Slope = measuringrange.effectDepthMaxMid;
break;
case PsFarRange:
case PsXFarRange:
case PsXXFarRange:
wdrRange2Slope = measuringrange.effectDepthMaxFar;
break;
default:
break;
}
cout << "wdrRange2Slope = " << wdrSlope << endl;
}
status = Ps2_GetMeasuringRange(deviceHandle, sessionIndex, (PsDepthRange)wdrMode.range3, &measuringrange);
if (status != PsReturnStatus::PsRetOK)
cout << "Ps2_GetMeasuringRange failed!" << endl;
else
{
switch ((PsDepthRange)wdrMode.range3)
{
case PsNearRange:
case PsXNearRange:
case PsXXNearRange:
wdrRange3Slope = wdrSlope = measuringrange.effectDepthMaxNear;
break;
case PsMidRange:
case PsXMidRange:
case PsXXMidRange:
wdrRange3Slope = wdrSlope = measuringrange.effectDepthMaxMid;
break;
case PsFarRange:
case PsXFarRange:
case PsXXFarRange:
wdrRange3Slope = wdrSlope = measuringrange.effectDepthMaxFar;
break;
default:
break;
}
cout << "wdrSlope = wdrRange3Slope " << wdrSlope << endl;
}
}
}
}
else
{
status = Ps2_SetDepthRange(deviceHandle, sessionIndex, depthRange);
if (status != PsReturnStatus::PsRetOK)
cout << "Ps2_SetDepthRange failed!" << status <<endl;
else
cout << "Set Depth Range " << depthRange << endl;
status = Ps2_GetDepthRange(deviceHandle, sessionIndex, &depthRange);
if (status != PsReturnStatus::PsRetOK)
cout << "Ps2_GetDepthRange failed!" << endl;
else
cout << "Get Depth Range " << depthRange << endl;
status = Ps2_GetMeasuringRange(deviceHandle, sessionIndex, depthRange, &measuringrange);
if (status != PsReturnStatus::PsRetOK)
cout << "Ps2_GetMeasuringRange failed!" << endl;
else
{
switch (depthRange)
{
case PsNearRange:
case PsXNearRange:
case PsXXNearRange:
slope = measuringrange.effectDepthMaxNear;
break;
case PsMidRange:
case PsXMidRange:
case PsXXMidRange:
slope = measuringrange.effectDepthMaxMid;
break;
case PsFarRange:
case PsXFarRange:
case PsXXFarRange:
slope = measuringrange.effectDepthMaxFar;
break;
default:
break;
}
cout << "slope == " << slope << endl;
}
}
cv::Mat imageMat;
const string irImageWindow = "IR Image";
const string depthImageWindow = "Depth Image";
const string wdrDepthImageWindow = "WDR Depth Image";
const string wdrDepthRange1ImageWindow = "WDR Depth Range1 Image";
const string wdrDepthRange2ImageWindow = "WDR Depth Range2 Image";
const string wdrDepthRange3ImageWindow = "WDR Depth Range3 Image";
ofstream PointCloudWriter;
PsDepthVector3 DepthVector = { 0, 0, 0 };
PsVector3f WorldVector = { 0.0f };
bool f_bPointClound = false;
PsDepthRangeList rangelist = { 0 };
int len = sizeof(rangelist);
status = Ps2_GetProperty(deviceHandle, sessionIndex, PsPropertyDepthRangeList, &rangelist, &len);
if (status == PsReturnStatus::PsRetOK&&rangelist.count > 0)
{
cout << "Available Range List: ";
for (int i = 0; i < rangelist.count-1; i++)
{
cout << (int)rangelist.depthrangelist[i] <<",";
}
cout << (int)rangelist.depthrangelist[rangelist.count - 1] << endl;
}
#ifndef DCAM_800
//Enable the Depth and RGB synchronize feature
Ps2_SetSynchronizeEnabled(deviceHandle, sessionIndex, true);
//Set PixelFormat as PsPixelFormatBGR888 for opencv display
Ps2_SetColorPixelFormat(deviceHandle, sessionIndex, PsPixelFormatBGR888);
status = Ps2_GetCameraParameters(deviceHandle, sessionIndex, PsRgbSensor, &cameraParameters);
cout << "Get PsGetCameraParameters status: " << status << endl;
cout << "RGB Camera Intinsic: " << endl;
cout << "Fx: " << cameraParameters.fx << endl;
cout << "Cx: " << cameraParameters.cx << endl;
cout << "Fy: " << cameraParameters.fy << endl;
cout << "Cy: " << cameraParameters.cy << endl;
cout << "RGB Distortion Coefficient: " << endl;
cout << "K1: " << cameraParameters.k1 << endl;
cout << "K2: " << cameraParameters.k2 << endl;
cout << "K3: " << cameraParameters.k3 << endl;
cout << "P1: " << cameraParameters.p1 << endl;
cout << "P2: " << cameraParameters.p2 << endl;
PsCameraExtrinsicParameters CameraExtrinsicParameters;
status = Ps2_GetCameraExtrinsicParameters(deviceHandle, sessionIndex, &CameraExtrinsicParameters);
cout << "Get PsGetCameraExtrinsicParameters status: " << status << endl;
cout << "Camera rotation: " << endl;
cout << CameraExtrinsicParameters.rotation[0] << " "
<< CameraExtrinsicParameters.rotation[1] << " "
<< CameraExtrinsicParameters.rotation[2] << " "
<< CameraExtrinsicParameters.rotation[3] << " "
<< CameraExtrinsicParameters.rotation[4] << " "
<< CameraExtrinsicParameters.rotation[5] << " "
<< CameraExtrinsicParameters.rotation[6] << " "
<< CameraExtrinsicParameters.rotation[7] << " "
<< CameraExtrinsicParameters.rotation[8] << " "
<< endl;
cout << "Camera transfer: " << endl;
cout << CameraExtrinsicParameters.translation[0] << " "
<< CameraExtrinsicParameters.translation[1] << " "
<< CameraExtrinsicParameters.translation[2] << " " << endl;
const string rgbImageWindow = "RGB Image";
const string mappedDepthImageWindow = "MappedDepth Image";
const string mappedRgbImageWindow = "MappedRGB Image";
bool f_bMappedRGB = true;
bool f_bMappedDepth = true;
bool f_bSync = false;
#endif
cout << "\n--------------------------------------------------------------------" << endl;
cout << "--------------------------------------------------------------------" << endl;
cout << "Press following key to set corresponding feature:" << endl;
cout << "0/1/2...: Change depth range Near/Middle/Far..." << endl;
cout << "P/p: Save point cloud data into PointCloud.txt in current directory" << endl;
cout << "T/t: Change background filter threshold value" << endl;
#ifndef DCAM_800
cout << "S/s: Enable or disable the Depth and RGB synchronize feature " << endl;
cout << "M/m: Change data mode: input corresponding index in terminal:" << endl;
cout << " 0: Output Depth and RGB in 30 fps" << endl;
cout << " 1: Output IR and RGB in 30 fps" << endl;
cout << " 2: Output Depth and IR in 30 fps" << endl;
cout << " 3: Output Depth/IR frames alternatively in 15fps, and RGB in 30fps" << endl;
cout << " 4: Output WDR_Depth and RGB in 30 fps" << endl;
cout << "R/r: Change the RGB resolution: input corresponding index in terminal:" << endl;
cout << " 0: 19201080" << endl;
cout << " 1: 1280720" << endl;
cout << " 2: 640480" << endl;
cout << " 3: 640360" << endl;
cout << "Q/q: Enable or disable the mapped RGB in Depth space" << endl;
cout << "L/l: Enable or disable the mapped Depth in RGB space" << endl;
cout << "V/v: Enable or disable the WDR depth fusion feature " << endl;
#else
cout << "M/m: Change data mode: input corresponding index in terminal:" << endl;
cout << " 0: Output Depth in 30 fps" << endl;
cout << " 1: Output IR in 30 fps" << endl;
cout << " 2: Output Depth and IR in 30 fps" << endl;
cout << " 3: Output WDR_Depth in 30 fps" << endl;
#endif
cout << "Esc: Program quit " << endl;
cout << "--------------------------------------------------------------------" << endl;
cout << "--------------------------------------------------------------------\n" << endl;
int destroycount = 0;
for (;;)
{
if (destroycount > 0)
{
destroycount--;
cv::destroyAllWindows();
}
PsFrame depthFrame = { 0 };
PsFrame irFrame = { 0 };
PsFrame wdrDepthFrame = { 0 };
#ifndef DCAM_800
PsFrame rgbFrame = { 0 };
PsFrame mappedDepthFrame = { 0 };
PsFrame mappedRGBFrame = { 0 };
#endif
// Read one frame before call PsGetFrame
PsFrameReady frameReady = { 0 };
status = Ps2_ReadNextFrame(deviceHandle, sessionIndex, &frameReady);
#ifdef FPS
dofps = false;
#ifdef _WIN32
GetLocalTime(&sys);
long dwEnd = sys.wMilliseconds;
#else
struct timeb stTimeb;
ftime(&stTimeb);
long dwEnd = stTimeb.millitm;
#endif
long timedelay = dwEnd - delayT;
delayT = dwEnd;
if (timedelay < 0) {
timedelay += 1000;
}
tatoldelay_tof += timedelay;
#endif
if (status != PsRetOK)
{
goto KEY;
}
//Get depth frame, depth frame only output in following data mode
if (1 == frameReady.depth)
{
status = Ps2_GetFrame(deviceHandle, sessionIndex, PsDepthFrame, &depthFrame);
if (depthFrame.pFrameData != NULL)
{
#ifdef FPS
dofps = true;
countof_loop_tof++;
if (countof_loop_tof >= FPS_LEN)
{
fps_tof = 1000 * FPS_LEN / tatoldelay_tof;
//cout << fps_tof<<endl;
countof_loop_tof = 0;
tatoldelay_tof = 0;
}
#endif
if (f_bPointClound)
{
PointCloudWriter.open("PointCloud.txt");
PsFrame &srcFrame = depthFrame;
const int len = srcFrame.width * srcFrame.height;
PsVector3f* worldV = new PsVector3f[len];
Ps2_ConvertDepthFrameToWorldVector(deviceHandle, sessionIndex, srcFrame, worldV); //Convert Depth frame to World vectors.
for (int i = 0; i < len; i++)
{
if (worldV[i].z == 0 || worldV[i].z == 0xFFFF)
continue; //discard zero points
PointCloudWriter << worldV[i].x << "\t" << worldV[i].y << "\t" << worldV[i].z << std::endl;
}
delete[] worldV;
worldV = NULL;
std::cout << "Save point cloud successful in PointCloud.txt" << std::endl;
PointCloudWriter.close();
f_bPointClound = false;
}
//Display the Depth Image
if (f_bWDRMode&&dataMode == PsWDR_Depth)
{
if (depthFrame.depthRange == wdrMode.range1&&wdrMode.range1Count!=0)
{
Opencv_Depth(wdrRange1Slope, depthFrame.height, depthFrame.width, depthFrame.pFrameData, imageMat);
cv::imshow(wdrDepthRange1ImageWindow, imageMat);
}
else if (depthFrame.depthRange == wdrMode.range2&&wdrMode.range2Count != 0)
{
Opencv_Depth(wdrRange2Slope, depthFrame.height, depthFrame.width, depthFrame.pFrameData, imageMat);
cv::imshow(wdrDepthRange2ImageWindow, imageMat);
}
else if (depthFrame.depthRange == wdrMode.range3&&wdrMode.range3Count != 0)
{
Opencv_Depth(wdrRange3Slope, depthFrame.height, depthFrame.width, depthFrame.pFrameData, imageMat);
cv::imshow(wdrDepthRange3ImageWindow, imageMat);
}
}
else
{
Opencv_Depth(slope, depthFrame.height, depthFrame.width, depthFrame.pFrameData, imageMat);
cv::imshow(depthImageWindow, imageMat);
}
}
else
{
cout << "Ps2_GetFrame PsDepthFrame status:" << status << " pFrameData is NULL " << endl;
}
}
//Get IR frame, IR frame only output in following data mode
if (1 == frameReady.ir)
{
status = Ps2_GetFrame(deviceHandle, sessionIndex, PsIRFrame, &irFrame);
if (irFrame.pFrameData != NULL)
{
#ifdef FPS
if (!dofps)
{
countof_loop_tof++;
if (countof_loop_tof >= FPS_LEN)
{
fps_tof = 1000 * FPS_LEN / tatoldelay_tof;
//cout << fps_tof << endl;
countof_loop_tof = 0;
tatoldelay_tof = 0;
}
}
#endif
//Display the IR Image
imageMat = cv::Mat(irFrame.height, irFrame.width, CV_16UC1, irFrame.pFrameData);
// Convert 16bit IR pixel (max pixel value is 3840) to 8bit for display
imageMat.convertTo(imageMat, CV_8U, 255.0 / 3840);
#ifdef FPS
if (fps_tof != 0)
{
char fps[20];
#ifdef _WIN32
sprintf_s(fps, "FPS: %d", fps_tof);
#else
snprintf(fps, sizeof(fps), "FPS: %d", fps_tof);
#endif
putText(imageMat, fps, Point2d(10, 20), FONT_HERSHEY_DUPLEX, 0.5, Scalar(255, 255, 255));
}
#endif
cv::imshow(irImageWindow, imageMat);
}
else
{
cout << "Ps2_GetFrame PsIRFrame status:" << status << " pFrameData is NULL " << endl;
}
}
//Get WDR depth frame(fusion or alternatively, determined by Ps2_SetWDRStyle, default in fusion)
//WDR depth frame only output in PsWDR_Depth data mode
if (1 == frameReady.wdrDepth)
{
status = Ps2_GetFrame(deviceHandle, sessionIndex, PsWDRDepthFrame, &wdrDepthFrame);
if (wdrDepthFrame.pFrameData != NULL)
{
#ifdef FPS
if (!dofps)
{
countof_loop_tof++;
if (countof_loop_tof >= FPS_LEN)
{
fps_tof = 1000 * FPS_LEN / tatoldelay_tof;
//cout << fps_tof << endl;
countof_loop_tof = 0;
tatoldelay_tof = 0;
}
}
#endif
if (f_bPointClound)
{
PointCloudWriter.open("PointCloud.txt");
PsFrame &srcFrame = wdrDepthFrame ;
const int len = srcFrame.width * srcFrame.height;
PsVector3f* worldV = new PsVector3f[len];
Ps2_ConvertDepthFrameToWorldVector(deviceHandle, sessionIndex, srcFrame, worldV); //Convert Depth frame to World vectors.
for (int i = 0; i < len; i++)
{
if (worldV[i].z == 0 || worldV[i].z == 0xFFFF)
continue; //discard zero points
PointCloudWriter << worldV[i].x << "\t" << worldV[i].y << "\t" << worldV[i].z << std::endl;
}
delete[] worldV;
worldV = NULL;
std::cout << "Save point cloud successful in PointCloud.txt" << std::endl;
PointCloudWriter.close();
f_bPointClound = false;
}
//Display the WDR Depth Image
Opencv_Depth(wdrSlope, wdrDepthFrame.height, wdrDepthFrame.width, wdrDepthFrame.pFrameData, imageMat);
cv::imshow(wdrDepthImageWindow, imageMat);
}
else
{
cout << "Ps2_GetFrame PsWDRDepthFrame status:" << status << " pFrameData is NULL " << endl;
}
}
#ifndef DCAM_800
//Get RGB frame, RGB frame only output in following data mode
if (1 == frameReady.rgb)
{
status = Ps2_GetFrame(deviceHandle, sessionIndex, PsRGBFrame, &rgbFrame);
if (rgbFrame.pFrameData != NULL)
{
//Display the RGB Image
imageMat = cv::Mat(rgbFrame.height, rgbFrame.width, CV_8UC3, rgbFrame.pFrameData);
cv::imshow(rgbImageWindow, imageMat);
}
else
{
cout << "Ps2_GetFrame PsRGBFrame status:" << status << " pFrameData is NULL " << endl;
}
}
//Get mapped depth frame which is mapped to rgb camera space
//Mapped depth frame only output in following data mode
//And can only get when the feature is enabled through api Ps2_SetMapperEnabledRGBToDepth
//When the key "L/l" pressed, this feature enable or disable
if (1 == frameReady.mappedDepth)
{
status = Ps2_GetFrame(deviceHandle, sessionIndex, PsMappedDepthFrame, &mappedDepthFrame);
if (mappedDepthFrame.pFrameData != NULL)
{
//Display the MappedDepth Image
imageMat = cv::Mat(mappedDepthFrame.height, mappedDepthFrame.width, CV_16UC1, mappedDepthFrame.pFrameData);
cv::Mat mappedDepthMat;
imageMat.convertTo(mappedDepthMat, CV_8U, 255.0 / (f_bWDRMode ? wdrSlope : slope));
cv::applyColorMap(mappedDepthMat, mappedDepthMat, cv::COLORMAP_RAINBOW);
cv::imshow(mappedDepthImageWindow, mappedDepthMat);
}
else
{
cout << "Ps2_GetFrame PsMappedDepthFrame status:" << status << " pFrameData is NULL " << endl;
}
}
//Get mapped rgb frame which is mapped to depth camera space
//Mapped rgb frame only output in following data mode
//And can only get when the feature is enabled through api Ps2_SetMapperEnabledDepthToRGB
//When the key "Q/q" pressed, this feature enable or disable
if (1 == frameReady.mappedRGB)
{
status = Ps2_GetFrame(deviceHandle, sessionIndex, PsMappedRGBFrame, &mappedRGBFrame);
if (mappedRGBFrame.pFrameData != NULL)
{
//Display the MappedRGB Image
imageMat = cv::Mat(mappedRGBFrame.height, mappedRGBFrame.width, CV_8UC3, mappedRGBFrame.pFrameData);
cv::imshow(mappedRgbImageWindow, imageMat);
}
else
{
cout << "Ps2_GetFrame PsMappedRGBFrame status:" << status << " pFrameData is NULL " << endl;
}
}
#endif
KEY:
unsigned char key = waitKey(1);
imageMat.release();
if (key == 'M' || key == 'm')
{
#ifdef DCAM_800
cout << "Selection: 0:Depth_30; 1:Ir_30; 2:DepthAndIR_30; 3:WDR_Depth" << endl;
#else
cout << "Selection: 0:DepthAndRgb_30; 1:IrAndRgb_30; 2:DepthAndIR_30; 3:PsDepthAndIR_15_RGB_30; 4:WDR_Depth" << endl;
#endif
int index = -1;
cin >> index;
//clear buffer and cin flag. if not, cin will not get input anymore;
if (cin.fail())
{
std::cout << "Unexpected input\n";
cin.clear();
cin.ignore(1024, '\n');
continue;
}
else
{
cin.clear();
cin.ignore(1024, '\n');
}
PsDataMode t_datamode = PsDepthAndIR_30;
#ifdef DCAM_800
switch (index)
{
case 0:
t_datamode = PsDepth_30;
break;
case 1:
t_datamode = PsIR_30;
break;
case 2:
t_datamode = PsDepthAndIR_30;
break;
case 3:
t_datamode = PsWDR_Depth;
break;
default:
cout << "Unsupported data mode!" << endl;
continue;
}
#else
switch (index)
{
case 0:
t_datamode = PsDepthAndRGB_30;
break;
case 1:
t_datamode = PsIRAndRGB_30;
break;
case 2:
t_datamode = PsDepthAndIR_30;
break;
case 3:
t_datamode = PsDepthAndIR_15_RGB_30;
break;
case 4:
t_datamode = PsWDR_Depth;
break;
default:
cout << "Unsupported data mode!" << endl;
continue;
}
#endif
if (t_datamode == PsWDR_Depth)
{
Ps2_SetWDROutputMode(deviceHandle, sessionIndex, &wdrMode);
f_bWDRMode = true;
}
else
{
f_bWDRMode = false;
}
if (dataMode == PsWDR_Depth&&t_datamode != PsWDR_Depth)
{
status = Ps2_GetDepthRange(deviceHandle, sessionIndex, &depthRange);
cout << "Get depth range," << " depthRange: " << depthRange << endl;
if (status != PsRetOK)
{
cout << "Get depth range failed! " << endl;
}
else
{
status = Ps2_GetMeasuringRange(deviceHandle, sessionIndex, depthRange, &measuringrange);
if (status != PsReturnStatus::PsRetOK)
cout << "Ps2_GetMeasuringRange failed!" << endl;
else
{
switch (depthRange)
{
case PsNearRange:
case PsXNearRange:
case PsXXNearRange:
slope = measuringrange.effectDepthMaxNear;
break;
case PsMidRange:
case PsXMidRange:
case PsXXMidRange:
slope = measuringrange.effectDepthMaxMid;
break;
case PsFarRange:
case PsXFarRange:
case PsXXFarRange:
slope = measuringrange.effectDepthMaxFar;
break;
default:
break;
}
cout << "slope == " << slope << endl;
}
}
}
status = Ps2_SetDataMode(deviceHandle, sessionIndex, (PsDataMode)t_datamode);
if (status != PsRetOK)
{
cout << "Ps2_SetDataMode status" << status << endl;
}
else
{
dataMode = t_datamode;
}
destroycount = 3;
}
else if ((key == '0') || (key == '1') || (key == '2') || (key == '3') || (key == '4') || (key == '5') || (key == '6') || (key == '7') || (key == '8'))
{
switch (key)
{
case '0':
depthRange = PsNearRange;
slope = 1450;
break;
case '1':
depthRange = PsMidRange;
slope = 3000;
break;
case '2':
depthRange = PsFarRange;
slope = 4400;
break;
case '3':
depthRange = PsXNearRange;
slope = 4800;
break;
case '4':
depthRange = PsXMidRange;
slope = 5600;
break;
case '5':
depthRange = PsXFarRange;
slope = 7500;
break;
case '6':
depthRange = PsXXNearRange;
slope = 9600;
break;
case '7':
depthRange = PsXXMidRange;
slope = 11200;
break;
case '8':
depthRange = PsXXFarRange;
slope = 15000;
break;
default:
cout << "Unsupported Range!" << endl;
continue;
}
status = Ps2_SetDepthRange(deviceHandle, sessionIndex, depthRange);
if (depthRange == PsNearRange)
cout << "Set depth range to Near," << " status: " << status << endl;
else if (depthRange == PsMidRange)
cout << "Set depth range to Mid," << " status: " << status << endl;
else if (depthRange == PsFarRange)
cout << "Set depth range to Far," << " status: " << status << endl;
else if (depthRange == PsXNearRange)
cout << "Set depth range to XNearRange," << " status: " << status << endl;
else if (depthRange == PsXMidRange)
cout << "Set depth range to XMidRange," << " status: " << status << endl;
else if (depthRange == PsXFarRange)
cout << "Set depth range to XFarRange," << " status: " << status << endl;
else if (depthRange == PsXXNearRange)
cout << "Set depth range to XXNearRange," << " status: " << status << endl;
else if (depthRange == PsXXMidRange)
cout << "Set depth range to XXMidRange," << " status: " << status << endl;
else if (depthRange == PsXXFarRange)
cout << "Set depth range to XXFarRange," << " status: " << status << endl;
if (status != PsRetOK)
{
cout << "Set depth range failed! " << endl;
}
status = Ps2_GetDepthRange(deviceHandle, sessionIndex, &depthRange);
cout << "Get depth range," << " depthRange: " << depthRange << endl;
if (status != PsRetOK)
{
cout << "Get depth range failed! " << endl;
}
else
{
status = Ps2_GetMeasuringRange(deviceHandle, sessionIndex, depthRange, &measuringrange);
if (status != PsReturnStatus::PsRetOK)
cout << "Ps2_GetMeasuringRange failed!" << endl;
else
{
switch (depthRange)
{
case PsNearRange:
case PsXNearRange:
case PsXXNearRange:
slope = measuringrange.effectDepthMaxNear;
break;
case PsMidRange:
case PsXMidRange:
case PsXXMidRange:
slope = measuringrange.effectDepthMaxMid;
break;
case PsFarRange:
case PsXFarRange:
case PsXXFarRange:
slope = measuringrange.effectDepthMaxFar;
break;
default:
break;
}
cout << "slope == " << slope << endl;
}
}
}
else if (key == 'P' || key == 'p')
{
#ifdef DCAM_800
if (dataMode != PsIR_30)
{
f_bPointClound = true;
}
else
{
cout << "has no depth" << endl;
}
#else
if (dataMode != PsIRAndRGB_30)
{
f_bPointClound = true;
}
else
{
cout << "has no depth" << endl;
}
#endif
}
else if (key == 'T' || key == 't')
{
//Set background filter threshold
static uint16_t threshold = 0;
threshold += 10;
if (threshold > 100)
threshold = 0;
status = Ps2_SetThreshold(deviceHandle, sessionIndex, threshold);
if (PsRetOK == status)
{
cout << "Set background threshold value: " << threshold << endl;
}
else
{
cout << "Set background threshold error,check if the datamode is WDR mode" << endl;
}
}
else if (key == 'V' || key == 'v')
{
static bool bWDRStyle = true;
status = Ps2_SetWDRStyle(deviceHandle, sessionIndex, bWDRStyle ? PsWDR_ALTERNATION : PsWDR_FUSION);
if (PsRetOK == status)
{
cout << "WDR image output " << (bWDRStyle ? "alternatively in multi range." : "Fusion.") << endl;
bWDRStyle = !bWDRStyle;
}
else
{
cout << "Set WDR Style " << (bWDRStyle ? PsWDR_ALTERNATION : PsWDR_FUSION) << " satus : " << status << endl;
}
}
else if (key == 27) //ESC Pressed
{
break;
}
#ifndef DCAM_800
else if (key == 'S' || key == 's')
{
status = Ps2_SetSynchronizeEnabled(deviceHandle, sessionIndex, f_bSync);
if (status == PsRetOK)
{
cout << "Set Synchronize " << (f_bSync ? "Enabled." : "Disabled.") << endl;
f_bSync = !f_bSync;
}
}
else if (key == 'R' || key == 'r')
{
cout << "please select RGB resolution to set: 0:1080P; 1:720P; 2:480P; 3:360P" << endl;
int index = 0;
cin >> index;
if (cin.fail())
{
std::cout << "Unexpected input\n";
cin.clear();
cin.ignore(1024, '\n');
continue;
}
else
{
cin.clear();
cin.ignore(1024, '\n');
}
PsResolution resolution = PsRGB_Resolution_1920_1080;
switch (index)
{
case 1:
resolution = PsRGB_Resolution_1280_720;
break;
case 2:
resolution = PsRGB_Resolution_640_480;
break;
case 3:
resolution = PsRGB_Resolution_640_360;
break;
default:
break;
}
Ps2_SetRGBResolution(deviceHandle, sessionIndex, resolution);
}
else if (key == 'L' || key == 'l')
{
status = Ps2_SetMapperEnabledRGBToDepth(deviceHandle, sessionIndex, f_bMappedDepth);
if (status == PsRetOK)
{
cout << "Set Mapper RGBToDepth " << (f_bMappedDepth ? "Enabled." : "Disabled.") << endl;
f_bMappedDepth = !f_bMappedDepth;
}
}
else if (key == 'Q' || key == 'q')
{
status = Ps2_SetMapperEnabledDepthToRGB(deviceHandle, sessionIndex, f_bMappedRGB);
if (status == PsRetOK)
{
cout << "Set Mapper DepthToRGB " << (f_bMappedRGB ? "Enabled." : "Disabled.") << endl;
f_bMappedRGB = !f_bMappedRGB;
}
}
#endif
}
status = Ps2_CloseDevice(&deviceHandle);
cout << "CloseDevice status: " << status << endl;
status = Ps2_Shutdown();
cout << "Shutdown status: " << status << endl;
cv::destroyAllWindows();
#endif
return 0;
}
I have found the answer. the power is not enough.
Another question, how can use VS MFC with Vzense?when I include "Vzense_api2.h" and compile it will occur error as below:
include\dcam710\vzense_types_710.h(201): error C2371: 'IPAddr': redefinition; different basic types
1>c:\program files (x86)\windows kits\10\include\10.0.17763.0\um\ipexport.h(28): note: see declaration of 'IPAddr'.
If I don't use MFC, such as console,it works well.
xxm
登录 后才可以发表评论