fix: follow official calib roi capture sequence
This commit is contained in:
parent
756bd1d64a
commit
8935bd24cd
@ -121,9 +121,7 @@ class FullFrameRoiRestoreGuard
|
||||
public:
|
||||
FullFrameRoiRestoreGuard(VZNLHANDLE deviceHandle,
|
||||
const SVzNLROIRect& initialLeftROI,
|
||||
const SVzNLROIRect& initialRightROI,
|
||||
unsigned int frameWidth,
|
||||
unsigned int frameHeight)
|
||||
const SVzNLROIRect& initialRightROI)
|
||||
: m_guardDeviceHandle(deviceHandle),
|
||||
m_initialLeftROI(initialLeftROI),
|
||||
m_initialRightROI(initialRightROI)
|
||||
@ -149,19 +147,33 @@ public:
|
||||
}
|
||||
m_restoreRequired = true;
|
||||
|
||||
SVzVideoResolution resolution{};
|
||||
ret = VzNL_GetResolution(m_guardDeviceHandle, &resolution);
|
||||
if (ret != 0 || resolution.nFrameWidth == 0 || resolution.nFrameHeight == 0) {
|
||||
char errorMsg[256] = {0};
|
||||
VzNL_GetErrorInfo(ret, errorMsg);
|
||||
LOG_ERROR("[VizumCamera] Cannot read full-frame resolution after enabling CalibROI: {} "
|
||||
"(error code: {}), size={}x{}",
|
||||
errorMsg, ret, resolution.nFrameWidth, resolution.nFrameHeight);
|
||||
RestoreNow();
|
||||
return;
|
||||
}
|
||||
m_frameWidth = resolution.nFrameWidth;
|
||||
m_frameHeight = resolution.nFrameHeight;
|
||||
|
||||
SVzNLROIRect fullLeftROI{};
|
||||
fullLeftROI.right = frameWidth;
|
||||
fullLeftROI.bottom = frameHeight;
|
||||
fullLeftROI.right = m_frameWidth;
|
||||
fullLeftROI.bottom = m_frameHeight;
|
||||
SVzNLROIRect fullRightROI{};
|
||||
fullRightROI.right = frameWidth;
|
||||
fullRightROI.bottom = frameHeight;
|
||||
fullRightROI.right = m_frameWidth;
|
||||
fullRightROI.bottom = m_frameHeight;
|
||||
ret = VzNL_ConfigDetectROI(m_guardDeviceHandle, &fullLeftROI, &fullRightROI);
|
||||
if (ret != 0) {
|
||||
char errorMsg[256] = {0};
|
||||
VzNL_GetErrorInfo(ret, errorMsg);
|
||||
LOG_ERROR("[VizumCamera] Cannot configure full-frame detection ROI: {} "
|
||||
"(error code: {}), requested=[0, {}, 0, {}]",
|
||||
errorMsg, ret, frameWidth, frameHeight);
|
||||
errorMsg, ret, m_frameWidth, m_frameHeight);
|
||||
RestoreNow();
|
||||
return;
|
||||
}
|
||||
@ -170,7 +182,7 @@ public:
|
||||
LOG_INFO("[VizumCamera] Temporary full-frame ROI configured through SDK: "
|
||||
"left/right=[0, {}, 0, {}]; initial left=[{}, {}, {}, {}], "
|
||||
"right=[{}, {}, {}, {}]",
|
||||
frameWidth, frameHeight,
|
||||
m_frameWidth, m_frameHeight,
|
||||
m_initialLeftROI.left, m_initialLeftROI.right,
|
||||
m_initialLeftROI.top, m_initialLeftROI.bottom,
|
||||
m_initialRightROI.left, m_initialRightROI.right,
|
||||
@ -182,6 +194,16 @@ public:
|
||||
return m_ready;
|
||||
}
|
||||
|
||||
unsigned int FrameWidth() const
|
||||
{
|
||||
return m_frameWidth;
|
||||
}
|
||||
|
||||
unsigned int FrameHeight() const
|
||||
{
|
||||
return m_frameHeight;
|
||||
}
|
||||
|
||||
bool RestoreNow()
|
||||
{
|
||||
if (m_restoreAttempted && m_restoreSucceeded)
|
||||
@ -252,6 +274,8 @@ private:
|
||||
SVzNLROIRect m_initialLeftROI{};
|
||||
SVzNLROIRect m_initialRightROI{};
|
||||
VzBool m_previousCalibRoi = VzFalse;
|
||||
unsigned int m_frameWidth = 0;
|
||||
unsigned int m_frameHeight = 0;
|
||||
bool m_restoreRequired = false;
|
||||
bool m_ready = false;
|
||||
bool m_restoreAttempted = false;
|
||||
@ -1100,13 +1124,25 @@ bool VizumCamera::CaptureFullFrameLeftImage(SLImage& image,
|
||||
return false;
|
||||
}
|
||||
|
||||
// Official SDK sample sequence starts by disabling CalibROI before
|
||||
// reading the ROI that will be restored after the full-frame capture.
|
||||
int ret = VzNL_EnableCalibROI(m_deviceHandle, VzFalse);
|
||||
if (ret != 0) {
|
||||
char errorMsg[256] = {0};
|
||||
VzNL_GetErrorInfo(ret, errorMsg);
|
||||
LOG_ERROR("[VizumCamera] Official full-frame transaction cannot disable CalibROI "
|
||||
"before reading initial ROI: {} (error code: {})", errorMsg, ret);
|
||||
return false;
|
||||
}
|
||||
LOG_INFO("[VizumCamera] Official full-frame transaction baseline applied: CalibROI=false");
|
||||
|
||||
const SVzNLROIRect expectedLeftROI{initialLeftROI.left, initialLeftROI.right,
|
||||
initialLeftROI.top, initialLeftROI.bottom};
|
||||
const SVzNLROIRect expectedRightROI{initialRightROI.left, initialRightROI.right,
|
||||
initialRightROI.top, initialRightROI.bottom};
|
||||
SVzNLROIRect currentLeftROI{};
|
||||
SVzNLROIRect currentRightROI{};
|
||||
int ret = VzNL_GetConfigDetectROI(m_deviceHandle, ¤tLeftROI, ¤tRightROI);
|
||||
ret = VzNL_GetConfigDetectROI(m_deviceHandle, ¤tLeftROI, ¤tRightROI);
|
||||
if (ret != 0) {
|
||||
char errorMsg[256] = {0};
|
||||
VzNL_GetErrorInfo(ret, errorMsg);
|
||||
@ -1115,17 +1151,6 @@ bool VizumCamera::CaptureFullFrameLeftImage(SLImage& image,
|
||||
return false;
|
||||
}
|
||||
|
||||
SVzVideoResolution resolution{};
|
||||
ret = VzNL_GetResolution(m_deviceHandle, &resolution);
|
||||
if (ret != 0 || resolution.nFrameWidth == 0 || resolution.nFrameHeight == 0) {
|
||||
char errorMsg[256] = {0};
|
||||
VzNL_GetErrorInfo(ret, errorMsg);
|
||||
LOG_ERROR("[VizumCamera] Full-frame capture cannot read a valid resolution: {} "
|
||||
"(error code: {}), size={}x{}",
|
||||
errorMsg, ret, resolution.nFrameWidth, resolution.nFrameHeight);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!SameSdkRoi(currentLeftROI, expectedLeftROI)
|
||||
|| !SameSdkRoi(currentRightROI, expectedRightROI)) {
|
||||
LOG_ERROR("[VizumCamera] Current ROI differs from the connection-time point-cloud ROI; "
|
||||
@ -1139,9 +1164,14 @@ bool VizumCamera::CaptureFullFrameLeftImage(SLImage& image,
|
||||
expectedLeftROI.top, expectedLeftROI.bottom,
|
||||
expectedRightROI.left, expectedRightROI.right,
|
||||
expectedRightROI.top, expectedRightROI.bottom);
|
||||
FullFrameRoiRestoreGuard recoveryGuard(m_deviceHandle, expectedLeftROI, expectedRightROI,
|
||||
resolution.nFrameWidth, resolution.nFrameHeight);
|
||||
const bool recoverySucceeded = recoveryGuard.RestoreNow();
|
||||
ret = VzNL_ConfigDetectROI(m_deviceHandle, &expectedLeftROI, &expectedRightROI);
|
||||
const bool recoverySucceeded = ret == 0;
|
||||
if (!recoverySucceeded) {
|
||||
char errorMsg[256] = {0};
|
||||
VzNL_GetErrorInfo(ret, errorMsg);
|
||||
LOG_ERROR("[VizumCamera] Failed to restore expected ROI while CalibROI=false: {} "
|
||||
"(error code: {})", errorMsg, ret);
|
||||
}
|
||||
ret = VzNL_GetConfigDetectROI(m_deviceHandle, ¤tLeftROI, ¤tRightROI);
|
||||
cameraStateRestored = recoverySucceeded && ret == 0
|
||||
&& SameSdkRoi(currentLeftROI, expectedLeftROI)
|
||||
@ -1149,8 +1179,7 @@ bool VizumCamera::CaptureFullFrameLeftImage(SLImage& image,
|
||||
return false;
|
||||
}
|
||||
|
||||
FullFrameRoiRestoreGuard roiGuard(m_deviceHandle, expectedLeftROI, expectedRightROI,
|
||||
resolution.nFrameWidth, resolution.nFrameHeight);
|
||||
FullFrameRoiRestoreGuard roiGuard(m_deviceHandle, expectedLeftROI, expectedRightROI);
|
||||
if (!roiGuard.IsReady()) {
|
||||
const bool restoreSucceeded = roiGuard.RestoreNow();
|
||||
ret = VzNL_GetConfigDetectROI(m_deviceHandle, ¤tLeftROI, ¤tRightROI);
|
||||
@ -1159,14 +1188,16 @@ bool VizumCamera::CaptureFullFrameLeftImage(SLImage& image,
|
||||
&& SameSdkRoi(currentRightROI, expectedRightROI);
|
||||
return false;
|
||||
}
|
||||
const unsigned int frameWidth = roiGuard.FrameWidth();
|
||||
const unsigned int frameHeight = roiGuard.FrameHeight();
|
||||
|
||||
SVzNLROIRect configuredLeftROI{};
|
||||
SVzNLROIRect configuredRightROI{};
|
||||
ret = VzNL_GetConfigDetectROI(m_deviceHandle, &configuredLeftROI, &configuredRightROI);
|
||||
const auto isFullFrameRoi = [&resolution](const SVzNLROIRect& roi) {
|
||||
const auto isFullFrameRoi = [frameWidth, frameHeight](const SVzNLROIRect& roi) {
|
||||
return roi.left == 0 && roi.top == 0
|
||||
&& roi.right == resolution.nFrameWidth
|
||||
&& roi.bottom == resolution.nFrameHeight;
|
||||
&& roi.right == static_cast<int>(frameWidth)
|
||||
&& roi.bottom == static_cast<int>(frameHeight);
|
||||
};
|
||||
if (ret != 0 || !isFullFrameRoi(configuredLeftROI) || !isFullFrameRoi(configuredRightROI)) {
|
||||
char errorMsg[256] = {0};
|
||||
@ -1179,7 +1210,7 @@ bool VizumCamera::CaptureFullFrameLeftImage(SLImage& image,
|
||||
configuredLeftROI.top, configuredLeftROI.bottom,
|
||||
configuredRightROI.left, configuredRightROI.right,
|
||||
configuredRightROI.top, configuredRightROI.bottom,
|
||||
resolution.nFrameWidth, resolution.nFrameHeight);
|
||||
frameWidth, frameHeight);
|
||||
const bool restoreSucceeded = roiGuard.RestoreNow();
|
||||
ret = VzNL_GetConfigDetectROI(m_deviceHandle, ¤tLeftROI, ¤tRightROI);
|
||||
cameraStateRestored = restoreSucceeded && ret == 0
|
||||
@ -1189,7 +1220,7 @@ bool VizumCamera::CaptureFullFrameLeftImage(SLImage& image,
|
||||
}
|
||||
LOG_INFO("[VizumCamera] SDK full-frame ROI readback verified before 2D capture: "
|
||||
"left/right=[0, {}, 0, {}]",
|
||||
resolution.nFrameWidth, resolution.nFrameHeight);
|
||||
frameWidth, frameHeight);
|
||||
|
||||
SVzNLImageData* leftImage = nullptr;
|
||||
SVzNLImageData* rightImage = nullptr;
|
||||
@ -1214,13 +1245,13 @@ bool VizumCamera::CaptureFullFrameLeftImage(SLImage& image,
|
||||
|
||||
const bool validFullFrame = converted && !image.empty()
|
||||
&& image.originX == 0 && image.originY == 0
|
||||
&& image.width == resolution.nFrameWidth
|
||||
&& image.height == resolution.nFrameHeight;
|
||||
&& image.width == frameWidth
|
||||
&& image.height == frameHeight;
|
||||
if (converted && !validFullFrame) {
|
||||
LOG_ERROR("[VizumCamera] Configured full-frame image contract failed: "
|
||||
"image={}x{} origin=({}, {}), expected={}x{} origin=(0, 0)",
|
||||
image.width, image.height, image.originX, image.originY,
|
||||
resolution.nFrameWidth, resolution.nFrameHeight);
|
||||
frameWidth, frameHeight);
|
||||
}
|
||||
|
||||
const bool initialRoiRestored = roiGuard.RestoreNow();
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user