This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

OPT8241-CDK-EVM display depth data using OPENGL with registerCallback

Hello,

I'm looking to understand how can I display in a window the depth data continuously.

I'm going to explain my problem:

In order to plot the data I have to refresh the window by using GLvoid IdleFunc(), to do that, I have to capture one depth frame and then plot in the glut display.

The display is only updated if the IDLE function ends, so I have to do for each frame a callback and plot the depth map. Doing it every time I call the callback but the problem is that the first 10 frames are not reliable, so for that reasion I have to wait 10 frame and then capture the frame with a REAL depth maps.

Is it possible to turn the camera in continuous capture and when I want I can get one of this frame?

I'm asking this question because if I make an continuous acquisition I have not this problem.

I included the Idle function:

GLvoid IdleFunc()

{

glClear(GL_COLOR_BUFFER_BIT);
glColor3f(1.0, 0.3, 1.0);
glBegin(GL_POINTS);
int counter = 0, mean = 0;
int cast_int_depth = 0;
depthCamera->registerCallback(DepthCamera::FRAME_DEPTH_FRAME, [&](DepthCamera &dc, const Frame &frame, DepthCamera::FrameType c) {
const DepthFrame *d_save = dynamic_cast<const DepthFrame *>(&frame); // callback used to obtain the depth frame
if (counter == frame_reject) // in order to have a good uncertainty we have to wait 10 frames
{
counter = frame_reject-1;
mean++;
auto width = d_save->size.width;
auto height = d_save->size.height;
pixel_counter = 0;
index = portion_frame.y_lower * width + portion_frame.x_left; // starting index to the x-z graph
for (auto jj = portion_frame.x_left; jj <= portion_frame.x_right; jj++, index++)
{
vect_X[pixel_counter] = jj + 1;
vect_amp[pixel_counter] = vect_amp[pixel_counter] + d_save->amplitude[index];
vect_Z[pixel_counter] = vect_Z[pixel_counter] + d_save->depth[index];
pixel_counter++;
}
index = 0;
for (auto col = 240; col > 0; col--) // scanning all the depth map
{
for (auto row = 0; row < 320; row++, index++)
{
vect_X_d[index] = row;
vect_Y_d[index] = col;
vect_amp_d[index] = vect_amp_d[index] + d_save->amplitude[index];
vect_Z_d[index] = vect_Z_d[index] + d_save->depth[index];
}
}
if (mean == frame_mean)
{
mean = 0;
dc.stop();
depthCamera->clearCallback(c);
}
}
counter++;
});
for (int swap_mat = 0; swap_mat < pixel_counter; swap_mat++)
{
vect_Z[swap_mat] = vect_Z[swap_mat] / frame_mean;
vect_amp[swap_mat] = vect_amp[swap_mat] / frame_mean;
if ((vect_amp[swap_mat] < threshold_amplitude) && (vect_Z[swap_mat] < threshold_depth))
vect_Z[swap_mat] = 8;
cast_int_depth = (vect_Z[swap_mat] * 100);
lut_color(cast_int_depth, R, G, B); // return the LUT depth color map
glColor3f(1, 1, 1);
glVertex3f(vect_X[swap_mat], vect_Z[swap_mat], 1);
if (row >= 10) // these two if are made to create dotted red line used to know the alarm threshold
{
row2++;
glColor3f(1, 0, 0);
glVertex3f(vect_X[swap_mat], threshold_obstacle, 1);
glColor3f(0, 0, 0);
glVertex3f(vect_X[swap_mat] + 330, (double)(240 - portion_frame.y_lower) / 24, 1);
glVertex3f(vect_X[swap_mat] + 330, (double)(239 - portion_frame.y_lower) / 24, 1); 
glVertex3f(vect_X[swap_mat] + 330, (double)(241 - portion_frame.y_lower) / 24, 1); 
}
if (row2 >= 10)
{
row = 0;
row2 = 0;
}
if (max_obstacle > vect_Z[swap_mat])
max_obstacle = vect_Z[swap_mat];
vect_Z[swap_mat] = 0; // re-initialize the Z vector to the new mean
vect_amp[swap_mat] = 0;
row++;
}
glEnd(); // gl_point end
glFlush();
glutSwapBuffers();
if (depthCamera->start())
{
depthCamera->wait();
}

}

can someone help me?

  • depthcamera->start() will start continuous capture.

    Your callback function should be quick and should only unload the frame if needed. You should update your callback function to skip the frames you don't care about and use a separate thread for rendering.