#include <iostream>
int main(
int argc,
char** argv)
{
"{help h ? | | help message}"
"{dw | | depth width }"
"{dh | | depth height }"
"{df | | depth fps }"
"{cw | | color width }"
"{ch | | color height }"
"{cf | | depth fps }"
);
if (parser.has("help"))
{
parser.printMessage();
return 0;
}
std::vector<int> params;
if (parser.has("dw"))
{
params.push_back(CAP_PROP_OBSENSOR_DEPTH_WIDTH);
params.push_back(parser.get<int>("dw"));
}
if (parser.has("dh"))
{
params.push_back(CAP_PROP_OBSENSOR_DEPTH_HEIGHT);
params.push_back(parser.get<int>("dh"));
}
if (parser.has("df"))
{
params.push_back(CAP_PROP_OBSENSOR_DEPTH_FPS);
params.push_back(parser.get<int>("df"));
}
if (parser.has("cw"))
{
params.push_back(CAP_PROP_FRAME_WIDTH);
params.push_back(parser.get<
int>(
"cw"));
}
if (parser.has("ch"))
{
params.push_back(CAP_PROP_FRAME_HEIGHT);
params.push_back(parser.get<
int>(
"ch"));
}
if (parser.has("cf"))
{
params.push_back(CAP_PROP_FPS);
params.push_back(parser.get<
int>(
"cf"));
}
obsensorCapture.
open(0, CAP_OBSENSOR);
else
obsensorCapture.
open(0, CAP_OBSENSOR, params);
std::cerr << "Failed to open obsensor capture! Index out of range or no response from device";
return -1;
}
double fx = obsensorCapture.
get(CAP_PROP_OBSENSOR_INTRINSIC_FX);
double fy = obsensorCapture.
get(CAP_PROP_OBSENSOR_INTRINSIC_FY);
double cx = obsensorCapture.
get(CAP_PROP_OBSENSOR_INTRINSIC_CX);
double cy = obsensorCapture.
get(CAP_PROP_OBSENSOR_INTRINSIC_CY);
double k1 = obsensorCapture.
get(CAP_PROP_OBSENSOR_COLOR_DISTORTION_K1);
double k2 = obsensorCapture.
get(CAP_PROP_OBSENSOR_COLOR_DISTORTION_K2);
double k3 = obsensorCapture.
get(CAP_PROP_OBSENSOR_COLOR_DISTORTION_K3);
double k4 = obsensorCapture.
get(CAP_PROP_OBSENSOR_COLOR_DISTORTION_K4);
double k5 = obsensorCapture.
get(CAP_PROP_OBSENSOR_COLOR_DISTORTION_K5);
double k6 = obsensorCapture.
get(CAP_PROP_OBSENSOR_COLOR_DISTORTION_K6);
double p1 = obsensorCapture.
get(CAP_PROP_OBSENSOR_COLOR_DISTORTION_P1);
double p2 = obsensorCapture.
get(CAP_PROP_OBSENSOR_COLOR_DISTORTION_P1);
std::cout << "obsensor camera intrinsic params: fx=" << fx << ", fy=" << fy << ", cx=" << cx << ", cy=" << cy << std::endl;
std::cout << "obsensor camera distortion params: k,p=" << k1 << ", " << k2 << ", " << k3 << ", "
<< k4 << ", " << k5 << ", " << k6 << ", "
<< p1 << ", " << p2 << std::endl;
const double minVal = 300;
const double maxVal = 5000;
while (true)
{
if (obsensorCapture.
grab())
{
if (obsensorCapture.
retrieve(image, CAP_OBSENSOR_BGR_IMAGE))
{
}
if (obsensorCapture.
retrieve(depthMap, CAP_OBSENSOR_DEPTH_MAP))
{
depthMap.
convertTo(adjDepthMap,
CV_8U, 255.0 / (maxVal - minVal), -minVal * 255.0 / (maxVal - minVal));
}
static const float alpha = 0.6f;
{
depthMap.
convertTo(adjDepthMap,
CV_8U, 255.0 / (maxVal - minVal), -minVal * 255.0 / (maxVal - minVal));
for (
int i = 0; i < image.
rows; i++)
{
for (
int j = 0; j < image.
cols; j++)
{
uint8_t depthValue = 255 - adjDepthMap.
at<uint8_t>(i, j);
if (depthValue != 0 && depthValue != 255)
{
outRgb[0] = (uint8_t)(outRgb[0] * (1.0f - alpha) + depthValue * alpha);
outRgb[1] = (uint8_t)(outRgb[1] * (1.0f - alpha) + depthValue * alpha);
outRgb[2] = (uint8_t)(outRgb[2] * (1.0f - alpha) + depthValue * alpha);
}
}
}
imshow(
"DepthToColor", image);
}
}
break;
}
return 0;
}
Designed for command line parsing.
Definition utility.hpp:915
Comma-separated Matrix Initializer.
Definition mat.hpp:964
_Tp & at(int i0=0)
Returns a reference to the specified array element.
int cols
Definition mat.hpp:2488
bool empty() const
Returns true if the array has no elements.
int rows
the number of rows and columns or (-1, -1) when the matrix has more than 2 dimensions
Definition mat.hpp:2488
void convertTo(OutputArray m, int rtype, double alpha=1, double beta=0) const
Converts an array to another data type with optional scaling.
void release()
Decrements the reference counter and deallocates the matrix if needed.
Template class for specifying the size of an image or rectangle.
Definition types.hpp:338
Template class for short numerical vectors, a partial case of Matx.
Definition matx.hpp:379
virtual bool open(const String &filename, int apiPreference=CAP_ANY)
Opens a video file or a capturing device or an IP video stream for video capturing.
virtual bool retrieve(OutputArray image, int flag=0)
Decodes and returns the grabbed video frame.
virtual bool isOpened() const
Returns true if video capturing has been initialized already.
virtual double get(int propId) const
Returns the specified VideoCapture property.
virtual bool grab()
Grabs the next frame from video file or capturing device.
#define CV_8U
Definition interface.h:54
PyParams params(const std::string &tag, const std::string &model, const std::string &weights, const std::string &device)