Skip to content

Commit

Permalink
Merge pull request #10 from y-labo/bugfix_mutex_lock
Browse files Browse the repository at this point in the history
Fixed a bug in the exclusivity control for RGB & Depth images.
  • Loading branch information
marek-simonik authored Dec 25, 2020
2 parents 056c49c + 306343f commit 4519f9d
Showing 1 changed file with 13 additions and 9 deletions.
22 changes: 13 additions & 9 deletions src/DemoMain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,23 +62,27 @@ class Record3DDemoApp
while ( true )
{
// Wait for the callback thread to receive new frame and unlock this thread
mainThreadLock_.lock();

#ifdef HAS_OPENCV
cv::Mat rgb, depth;
{
std::lock_guard<std::recursive_mutex> lock(mainThreadLock_);
rgb = imgRGB_.clone();
depth = imgDepth_.clone();
}
// Postprocess images
cv::cvtColor( imgRGB_, imgRGB_, cv::COLOR_RGB2BGR );
cv::cvtColor( rgb, rgb, cv::COLOR_RGB2BGR );

// The TrueDepth camera is a selfie camera; we mirror the RGBD frame so it looks plausible.
bool areTrueDepthDataBeingStreamed = imgDepth_.rows == Record3D::Record3DStream::MAXIMUM_FRAME_HEIGHT && imgDepth_.cols == Record3D::Record3DStream::MAXIMUM_FRAME_WIDTH;
bool areTrueDepthDataBeingStreamed = depth.rows == Record3D::Record3DStream::MAXIMUM_FRAME_HEIGHT && depth.cols == Record3D::Record3DStream::MAXIMUM_FRAME_WIDTH;
if ( areTrueDepthDataBeingStreamed )
{
cv::flip( imgRGB_, imgRGB_, 1 );
cv::flip( imgDepth_, imgDepth_, 1 );
cv::flip( rgb, rgb, 1 );
cv::flip( depth, depth, 1 );
}

// Show images
cv::imshow( "RGB", imgRGB_ );
cv::imshow( "Depth", imgDepth_ );
cv::imshow( "RGB", rgb );
cv::imshow( "Depth", depth );
cv::waitKey( 1 );
#endif
}
Expand All @@ -103,6 +107,7 @@ class Record3DDemoApp
Record3D::IntrinsicMatrixCoeffs $K)
{
#ifdef HAS_OPENCV
std::lock_guard<std::recursive_mutex> lock(mainThreadLock_);
// When we switch between the TrueDepth and the LiDAR camera, the size frame size changes.
// Recreate the RGB and Depth images with fitting size.
if ( imgRGB_.rows != $frameHeight || imgRGB_.cols != $frameWidth
Expand All @@ -120,7 +125,6 @@ class Record3DDemoApp
memcpy( imgRGB_.data, $rgbFrame.data(), $frameWidth * $frameHeight * numRGBChannels * sizeof(uint8_t));
memcpy( imgDepth_.data, $depthFrame.data(), $frameWidth * $frameHeight * sizeof(float));
#endif
mainThreadLock_.unlock();
}

private:
Expand Down

0 comments on commit 4519f9d

Please sign in to comment.