Skip to content

Commit

Permalink
revert code which takes N frames parameter from config file.
Browse files Browse the repository at this point in the history
fix deprojection issue
set the depth tensor size to be as the ROI size.
  • Loading branch information
gilpazintel committed Feb 13, 2025
1 parent b5691ac commit 71e3ead
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 24 deletions.
4 changes: 0 additions & 4 deletions common/device-model.h
Original file line number Diff line number Diff line change
Expand Up @@ -91,10 +91,6 @@ namespace rs2

namespace configurations
{
namespace DQT
{
static const char* temporal_noise_num_images{ "DQT.temporal_noise_num_images" };
}
namespace record
{
static const char* file_save_mode{ "record.file_save_mode" };
Expand Down
8 changes: 6 additions & 2 deletions tools/depth-quality/depth-metrics.h
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@ namespace rs2
std::mutex m;

std::vector<rs2::float3> roi_pixels;
std::vector<rs2::float3> roi_deprojected_points;

//#pragma omp parallel for - TODO optimization envisaged
for (int y = roi.min_y; y < roi.max_y; ++y)
Expand All @@ -175,18 +176,21 @@ namespace rs2
{
// units is float
float pixel[2] = { float(x), float(y) };
float point[3];
auto distance = depth_raw * units;
rs2_deproject_pixel_to_point(point, intrin, pixel, distance);

std::lock_guard<std::mutex> lock(m);
roi_pixels.push_back({ pixel[0], pixel[1], distance });
roi_deprojected_points.push_back({ point[0], point[1], point[2] });
}
}

if (roi_pixels.size() < 3) { // Not enough pixels in RoI to fit a plane
if (roi_deprojected_points.size() < 3) { // Not enough pixels in RoI to fit a plane
return result;
}

plane p = plane_from_points(roi_pixels);
plane p = plane_from_points(roi_deprojected_points);

if (p == plane{ 0, 0, 0, 0 }) { // The points in RoI don't span a valid plane
return result;
Expand Down
23 changes: 5 additions & 18 deletions tools/depth-quality/rs-depth-quality.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -197,32 +197,19 @@ int main(int argc, const char * argv[]) try
}

// Calculate Temporal Noise
// Temporal Noise is calculated as the median of the standard deviation of the depth values
// across a set of N frames.
// The standard deviation is calculated for each pixel across the N frames.
// The median of the standard deviations is the Temporal Noise.
// The Temporal Noise is calculated in mm.
int num_images = 40;
if (rs2::config_file::instance().contains(rs2::configurations::DQT::temporal_noise_num_images))
{
num_images = rs2::config_file::instance().get(rs2::configurations::DQT::temporal_noise_num_images);
}
else
{
rs2::config_file::instance().set(rs2::configurations::DQT::temporal_noise_num_images, num_images);
}
const int num_images = 40;

static std::deque<std::vector<rs2::float3>> depth_images; // FIFO buffer for depth images

// Add the current depth image to the FIFO buffer
depth_images.push_back(points);
if (depth_images.size() > num_images) {
if (depth_images.size() >= num_images) {

//start calculate only once we accumulate 'num_images'
depth_images.pop_front();

// Create Depth_Tensor
std::vector<std::vector<std::vector<float>>> depth_tensor(roi.max_x, std::vector<std::vector<float>>(roi.max_y, std::vector<float>(depth_images.size(), 0.0f)));
std::vector<std::vector<std::vector<float>>> depth_tensor(roi.max_x - roi.min_x, std::vector<std::vector<float>>(roi.max_y - roi.min_y, std::vector<float>(depth_images.size(), 0.0f)));

// Fill Depth_Tensor with depth images
for (size_t n = 0; n < depth_images.size(); ++n) {
Expand All @@ -236,8 +223,8 @@ int main(int argc, const char * argv[]) try
}

// Remove all zeros from Depth_Tensor
for (int y = 0; y < roi.max_y; ++y) {
for (int x = 0; x < roi.max_x; ++x) {
for (int y = 0; y < roi.max_y - roi.min_y; ++y) {
for (int x = 0; x < roi.max_x - roi.min_x; ++x) {
depth_tensor[x][y].erase(std::remove(depth_tensor[x][y].begin(), depth_tensor[x][y].end(), 0.0f), depth_tensor[x][y].end());
}
}
Expand Down

0 comments on commit 71e3ead

Please sign in to comment.