#include <RVC/RVC.h>
#include <iostream>
#include <opencv2/calib3d.hpp>
#include "IO/FileIO.h"
#include "IO/SavePointMap.h"
const float distortion[5],
RVC::ROI &roi) {
const int width = sz.width, height = sz.height, image_size = width * height;
std::vector<cv::Point2f> pts(width * height);
cv::Point2f *pts_ptr = pts.data();
for (
size_t r = roi.
y; r < roi.
y + height; r++) {
for (
size_t c = roi.
x; c < roi.
x + width; c++, pts_ptr++) {
pts_ptr->x = c;
pts_ptr->y = r;
}
}
const float distortion_cv[5] = {distortion[0], distortion[1], distortion[3], distortion[4], distortion[2]};
std::vector<cv::Point2f> undistorted_pts;
cv::undistortPoints(pts, undistorted_pts, cv::Mat(3, 3, CV_32FC1, const_cast<float *>(intrinsicMatrix)),
cv::Mat(1, 5, CV_32FC1, const_cast<float *>(distortion_cv)));
pts_ptr = undistorted_pts.data();
for (size_t i = 0; i < image_size; i++, pts_ptr++, pm_ptr += 3, z++) {
pm_ptr[0] = pts_ptr->x * z[0];
pm_ptr[1] = pts_ptr->y * z[0];
pm_ptr[2] = z[0];
}
return pm;
}
bool rtf;
rtf = sz0.width == sz1.width && sz0.height == sz1.height;
maxDiff = -1;
if (!rtf) {
return rtf;
}
const int data_size = sz0.width * sz0.height * 3;
double sub_abs;
bool data0_is_valid, data1_is_valid;
for (size_t i = 0; i < data_size && rtf; i++) {
data0_is_valid = data_ptr0[i] == data_ptr0[i];
data1_is_valid = data_ptr1[i] == data_ptr1[i];
if (data0_is_valid != data1_is_valid) {
rtf = false;
} else if (data0_is_valid) {
sub_abs = fabs(data_ptr0[i] - data_ptr1[i]);
if (sub_abs > maxDiff) {
maxDiff = sub_abs;
}
}
}
rtf = rtf && maxDiff < tol;
return rtf;
}
int main(int argc, char *argv[]) {
size_t actual_size = 0;
SystemListDevices(devices, 10, &actual_size, RVC::SystemListDeviceType::All);
if (actual_size == 0) {
std::cout << "Can not find any USB RVC Camera!" << std::endl;
return -1;
}
if(devices[0].IsFirmwareMatch() == false){
std::cout << "device firmware mismatch, Please use RVCManager to upgrade the firmware" << std::endl;
return -1;
}
std::cout << "Failed to open camera! Please check whether the camera is connected and make sure it is not occupied and supports X1." << std::endl;
return 1;
}
RVC::X1::CustomTransformOptions::CoordinateSelect::CoordinateSelect_Disabled;
const std::string save_directory = "./Data/";
MakeDirectories(save_directory);
if (x1.
Capture(cap_opts) ==
true) {
std::string pm_addr = save_directory + "test.ply";
std::cout << "save point map to file: " << pm_addr << std::endl;
pm.
Save(pm_addr.c_str(), RVC::PointMapUnit::Meter,
true);
float intrinsic_matrix[9], distortion[5];
RVC::PointMap convert_pm = ConvertDepthMapToPointMap(dp, intrinsic_matrix, distortion, cap_opts.
roi);
double max_diff;
bool rtf = IsPointMapEqual(pm, convert_pm, max_diff, 1.0e-6);
printf("pointmap is %s, max_diff (mm): %f\n", rtf ? "equal" : "not equal", max_diff * 1000);
} else {
std::cout << "RVC Camera capture failed!" << std::endl;
}
return 0;
}