Skip to content
Open
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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ This tutorial explains the "sampleOpenCV" which shows how you can use [OpenCV](h
To run this sample you need to install a Royale binary version and additionaly the OpenCV library. This sample was tested with OpenCV version 4.6.0.

After installing everything, you can start CMake. There you have to set the OpenCV_DIR to your OpenCV installation (e.g. C:/projects/opencv-4.6.0/opencv/build)
and the royale_DIR to the share folder of your Royale binary installation (e.g. D:\Program Files\royale\4.23.0.1062\share) and click **Generate**.
and the royale_DIR to the share folder of your Royale binary installation (e.g. D:\Program Files\royale\5.4.0.2112\lib\cmake) and click **Generate**.

## Code explanation
In the beginning we declare a data listener and a camera device. We also declare the platform resources as this will call the CoInitializeEx function on Windows. Otherwise
Expand Down
15 changes: 9 additions & 6 deletions sampleOpenCV.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
* PARTICULAR PURPOSE.
*
\****************************************************************************/

#include <royale.hpp>
#include <iostream>
#include <mutex>
Expand Down Expand Up @@ -67,13 +66,17 @@ public :
float *grayRowPtr = grayImage.ptr<float> (y);
for (int x = 0; x < zImage.cols; x++, k++)
{
auto curPoint = data->points.at (k);
if (curPoint.depthConfidence > 0)
auto curX = data->getX(k);
auto curY = data->getY(k);
auto curZ = data->getZ(k);
auto curConf = data->getDepthConfidence(k);
auto curGray = data->getGrayValue(k);
if (curConf > 0)
{
// if the point is valid, map the pixel from 3D world
// coordinates to a 2D plane (this will distort the image)
zRowPtr[x] = adjustZValue (curPoint.z);
grayRowPtr[x] = static_cast<float> (curPoint.grayValue);
zRowPtr[x] = adjustZValue (curZ);
grayRowPtr[x] = static_cast<float> (curGray);
}
}
}
Expand Down Expand Up @@ -169,7 +172,7 @@ public :
// the max dist here is used as an example and can be modified
float adjustZValue (float zValue)
{
float clampedDist = std::min (2.5f, zValue);
float clampedDist = std::min<float> (2.5f, zValue);
float newZValue = clampedDist / 2.5f * 255.0f;
return newZValue;
}
Expand Down