Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sdk: Calculate dimensions of a processed frame based on .ini #429

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
24 changes: 24 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,8 @@ Adsd3500Sensor::Adsd3500Sensor(const std::string &driverPath,
m_controls.emplace("fps", "0");
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;
Expand Down Expand Up @@ -702,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;
}

Expand Down Expand Up @@ -877,6 +888,14 @@ 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;
}
if (control == "processedFrameSize") {
return Status::OK;
}

// Send the command that sets the control value
struct v4l2_control ctrl;
Expand Down Expand Up @@ -909,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));
Expand Down