Skip to content

Commit

Permalink
sdk: Calculate dimensions of a processed frame based on .ini
Browse files Browse the repository at this point in the history
Signed-off-by: Dan Nechita <[email protected]>
  • Loading branch information
dNechita committed Oct 4, 2023
1 parent 7f437de commit 24b2f19
Show file tree
Hide file tree
Showing 4 changed files with 86 additions and 0 deletions.
3 changes: 3 additions & 0 deletions sdk/src/cameras/itof-camera/camera_itof.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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";
}
Expand Down
64 changes: 64 additions & 0 deletions sdk/src/cameras/itof-camera/mode_info.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
13 changes: 13 additions & 0 deletions sdk/src/cameras/itof-camera/mode_info.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<std::string> GetAvailableModes() { return m_availableModes; };

private:
Expand Down
6 changes: 6 additions & 0 deletions sdk/src/connections/target/adsd3500_sensor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 24b2f19

Please sign in to comment.