From 24b2f19aed21c9dd95f5cb4d6a655a5c877bcaaf Mon Sep 17 00:00:00 2001 From: Dan Nechita Date: Tue, 26 Sep 2023 12:35:25 +0300 Subject: [PATCH 1/2] sdk: Calculate dimensions of a processed frame based on .ini Signed-off-by: Dan Nechita --- sdk/src/cameras/itof-camera/camera_itof.cpp | 3 + sdk/src/cameras/itof-camera/mode_info.cpp | 64 +++++++++++++++++++ sdk/src/cameras/itof-camera/mode_info.h | 13 ++++ .../connections/target/adsd3500_sensor.cpp | 6 ++ 4 files changed, 86 insertions(+) diff --git a/sdk/src/cameras/itof-camera/camera_itof.cpp b/sdk/src/cameras/itof-camera/camera_itof.cpp index 9476c551c..f4c190b1d 100644 --- a/sdk/src/cameras/itof-camera/camera_itof.cpp +++ b/sdk/src/cameras/itof-camera/camera_itof.cpp @@ -1805,6 +1805,9 @@ void CameraItof::configureSensorFrameType() { std::string en = (it->second == "0") ? "1" : "0"; m_depthSensor->setControl("depthEnable", en); m_depthSensor->setControl("abAveraging", en); + m_depthSensor->setControl("partialDepthEnable", en); + ModeInfo::getInstance()->setSensorPixelParam("partialDepthEnable", + value); } else { LOG(WARNING) << "partialDepthEnable was not found in .ini file"; } diff --git a/sdk/src/cameras/itof-camera/mode_info.cpp b/sdk/src/cameras/itof-camera/mode_info.cpp index 8de08e48c..b8f0808ed 100644 --- a/sdk/src/cameras/itof-camera/mode_info.cpp +++ b/sdk/src/cameras/itof-camera/mode_info.cpp @@ -180,6 +180,7 @@ aditof::Status ModeInfo::setImagerTypeAndModeVersion(int type, int version) { m_sensorConfigBits.emplace("bitsInAb", ""); m_sensorConfigBits.emplace("bitsInConf", ""); m_sensorConfigBits.emplace("pixelFormat", ""); + m_sensorConfigBits.emplace("partialDepthEnable", ""); } return status; @@ -325,3 +326,66 @@ aditof::Status ModeInfo::setSensorPixelParam(const std::string &control, m_sensorConfigBits[control] = value; return aditof::Status::OK; }; + +aditof::Status +ModeInfo::getProcessedFramesProperties(const std::string &mode, uint16_t *width, + uint16_t *height, + size_t *frameTotalBytesCount) { + aditof::Status status; + uint8_t intMode; + status = convertCameraMode(mode, intMode); + if (status != aditof::Status::OK) { + LOG(ERROR) << "Invalid mode!"; + return status; + } + + int depthBytesPerPixel = sizeof(uint16_t); + int abBytesPerPixel = sizeof(uint16_t); + int confBytesPerPixel = sizeof(float); + int baseWidth = ModeInfo::getInstance()->getModeInfo(intMode).width; + int baseHeight = ModeInfo::getInstance()->getModeInfo(intMode).height; + int totalHeight = 0; + size_t totalBytes = 0; + + // TO DO: investigate how to not pass qnative throught depth compute. This + // way we can send confidence as uint8 per pixel instead of float + // if (m_sensorConfigBits["partialDepthEnable"] == "0") { + // confBytesPerPixel = sizeof(uint8_t); + // } + + int depthBits = std::stoi(m_sensorConfigBits["bitsInDepth"]); + if (depthBits > 0) { + totalHeight += baseHeight; + totalBytes += baseWidth * baseHeight * depthBytesPerPixel; + } + + int abBits = std::stoi(m_sensorConfigBits["bitsInAb"]); + if (abBits > 0) { + totalHeight += baseHeight; + totalBytes += baseWidth * baseHeight * abBytesPerPixel; + } + + int confBits = std::stoi(m_sensorConfigBits["bitsInConf"]); + if (confBits > 0) { + totalHeight += baseHeight; + totalBytes += baseWidth * baseHeight * confBytesPerPixel; + } + + // If depth, AB, conf are all 0, we probably are in mode "pcm-native" + if (depthBits == 0 && abBits == 0 && confBits == 0) { + totalHeight += baseHeight; + totalBytes += baseHeight * abBytesPerPixel; + } + + if (width) { + *width = baseWidth; + } + if (height) { + *height = totalHeight; + } + if (frameTotalBytesCount) { + *frameTotalBytesCount = totalBytes; + } + + return aditof::Status::OK; +} \ No newline at end of file diff --git a/sdk/src/cameras/itof-camera/mode_info.h b/sdk/src/cameras/itof-camera/mode_info.h index fd06b5ec0..bd57b8141 100644 --- a/sdk/src/cameras/itof-camera/mode_info.h +++ b/sdk/src/cameras/itof-camera/mode_info.h @@ -98,6 +98,19 @@ class ModeInfo { aditof::Status setSensorPixelParam(const std::string &control, const std::string &value); + /** + * Get the post depth compute frame width and height for the provided mode + * param[in] modes - the name of the mode (represented as a string) + * param[out] width - frame width in bytes + * param[out] height - frame height in bytes + * param[out] frameTotalBytesCount - the total number of bytes that the frame occupies + * @return aditof::Status + */ + aditof::Status getProcessedFramesProperties(const std::string &mode, + uint16_t *width, + uint16_t *height, + size_t *frameTotalBytesCount); + std::vector GetAvailableModes() { return m_availableModes; }; private: diff --git a/sdk/src/connections/target/adsd3500_sensor.cpp b/sdk/src/connections/target/adsd3500_sensor.cpp index 5342d356b..90c3b8b0e 100644 --- a/sdk/src/connections/target/adsd3500_sensor.cpp +++ b/sdk/src/connections/target/adsd3500_sensor.cpp @@ -150,6 +150,7 @@ Adsd3500Sensor::Adsd3500Sensor(const std::string &driverPath, m_controls.emplace("fps", "0"); m_controls.emplace("imagerType", ""); m_controls.emplace("inputFormat", ""); + m_controls.emplace("partialDepthEnable", ""); // Define the commands that correspond to the sensor controls m_implData->controlsCommands["abAveraging"] = 0x9819e5; @@ -877,6 +878,11 @@ aditof::Status Adsd3500Sensor::setControl(const std::string &control, ModeInfo::getInstance()->setSensorPixelParam("pixelFormat", value); return Status::OK; } + if (control == "partialDepthEnable") { + ModeInfo::getInstance()->setSensorPixelParam("partialDepthEnable", + value); + return Status::OK; + } // Send the command that sets the control value struct v4l2_control ctrl; From bc279996358906960dd87d8845b62390b8aebe57 Mon Sep 17 00:00:00 2001 From: Dan Nechita Date: Thu, 28 Sep 2023 12:56:59 +0300 Subject: [PATCH 2/2] sdk: Expose the size of a frame (generated by depth compute) via control Signed-off-by: Dan Nechita --- sdk/src/connections/target/adsd3500_sensor.cpp | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/sdk/src/connections/target/adsd3500_sensor.cpp b/sdk/src/connections/target/adsd3500_sensor.cpp index 90c3b8b0e..54635f145 100644 --- a/sdk/src/connections/target/adsd3500_sensor.cpp +++ b/sdk/src/connections/target/adsd3500_sensor.cpp @@ -151,6 +151,7 @@ Adsd3500Sensor::Adsd3500Sensor(const std::string &driverPath, m_controls.emplace("imagerType", ""); m_controls.emplace("inputFormat", ""); m_controls.emplace("partialDepthEnable", ""); + m_controls.emplace("processedFrameSize", ""); // Define the commands that correspond to the sensor controls m_implData->controlsCommands["abAveraging"] = 0x9819e5; @@ -703,6 +704,15 @@ Adsd3500Sensor::setFrameType(const aditof::DepthSensorFrameType &type) { } } + size_t processedFrameSize = 0; + status = ModeInfo::getInstance()->getProcessedFramesProperties( + type.type, nullptr, nullptr, &processedFrameSize); + if (status == Status::OK) { + setControl("processedFrameSize", std::to_string(processedFrameSize)); + } else { + LOG(ERROR) << "Failed to get the properties of a processed Frame"; + } + return status; } @@ -883,6 +893,9 @@ aditof::Status Adsd3500Sensor::setControl(const std::string &control, value); return Status::OK; } + if (control == "processedFrameSize") { + return Status::OK; + } // Send the command that sets the control value struct v4l2_control ctrl; @@ -915,6 +928,11 @@ aditof::Status Adsd3500Sensor::getControl(const std::string &control, return Status::OK; } + if (control == "processedFrameSize") { + value = m_controls.at("processedFrameSize"); + return Status::OK; + } + // Send the command that reads the control value struct v4l2_control ctrl; memset(&ctrl, 0, sizeof(ctrl));