|
@@ -1,13 +1,18 @@
|
|
|
#include "orb_camera_impl.h"
|
|
#include "orb_camera_impl.h"
|
|
|
#include "core/image_utility.hpp"
|
|
#include "core/image_utility.hpp"
|
|
|
|
|
+#include "core/image_utility_v2.h"
|
|
|
#include "core/object_manager.h"
|
|
#include "core/object_manager.h"
|
|
|
#include "core/utility.hpp"
|
|
#include "core/utility.hpp"
|
|
|
|
|
|
|
|
#include <boost/asio/post.hpp>
|
|
#include <boost/asio/post.hpp>
|
|
|
|
|
|
|
|
|
|
+#include <opencv2/calib3d.hpp>
|
|
|
#include <opencv2/imgcodecs.hpp>
|
|
#include <opencv2/imgcodecs.hpp>
|
|
|
#include <opencv2/imgproc.hpp>
|
|
#include <opencv2/imgproc.hpp>
|
|
|
|
|
|
|
|
|
|
+#include <glm/glm.hpp>
|
|
|
|
|
+#include <glm/gtc/type_ptr.hpp>
|
|
|
|
|
+
|
|
|
using boost::asio::post;
|
|
using boost::asio::post;
|
|
|
|
|
|
|
|
namespace orb_camera_impl {
|
|
namespace orb_camera_impl {
|
|
@@ -102,6 +107,8 @@ orb_camera::impl *orb_camera::impl::create(orb_camera::create_config conf) {
|
|
|
ret->c_pf_list = ret->pipe->getStreamProfileList(OB_SENSOR_COLOR);
|
|
ret->c_pf_list = ret->pipe->getStreamProfileList(OB_SENSOR_COLOR);
|
|
|
ret->d_pf_list = ret->pipe->getStreamProfileList(OB_SENSOR_DEPTH);
|
|
ret->d_pf_list = ret->pipe->getStreamProfileList(OB_SENSOR_DEPTH);
|
|
|
|
|
|
|
|
|
|
+ ret->remap_name = conf.remap_name;
|
|
|
|
|
+
|
|
|
return ret;
|
|
return ret;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -109,6 +116,8 @@ orb_camera::impl::~impl() {
|
|
|
if (is_capturing) {
|
|
if (is_capturing) {
|
|
|
stop();
|
|
stop();
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+ aux_thread->join();
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
orb_camera::vi_list_ptr orb_camera::impl::create_video_info_list(const pf_list_type &pf_list) {
|
|
orb_camera::vi_list_ptr orb_camera::impl::create_video_info_list(const pf_list_type &pf_list) {
|
|
@@ -155,6 +164,44 @@ orb_camera::vi_list_ptr orb_camera::impl::query_d2c_info(uint32_t c_conf_index)
|
|
|
return create_video_info_list(d_pf);
|
|
return create_video_info_list(d_pf);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+void orb_camera::impl::generate_undistort_map() { // TODO: accelerate with CUDA
|
|
|
|
|
+ if (remap_name == invalid_obj_name) return;
|
|
|
|
|
+
|
|
|
|
|
+ auto cam_params = pipe->getCameraParam();
|
|
|
|
|
+// assert(cam_params.rgbIntrinsic == cam_params.depthIntrinsic);
|
|
|
|
|
+// assert(cam_params.rgbDistortion == cam_params.depthDistortion);
|
|
|
|
|
+ auto cam_in = cam_params.rgbIntrinsic;
|
|
|
|
|
+ // @formatter:off
|
|
|
|
|
+ cv::Mat cam_mat_cv = (cv::Mat_<float>(3, 3) <<
|
|
|
|
|
+ cam_in.fx, 0.f, cam_in.cx,
|
|
|
|
|
+ 0, cam_in.fy, cam_in.cy,
|
|
|
|
|
+ 0, 0, 1);
|
|
|
|
|
+ // @formatter:on
|
|
|
|
|
+
|
|
|
|
|
+ auto cam_dist = cam_params.rgbDistortion;
|
|
|
|
|
+ // @formatter:off
|
|
|
|
|
+ cv::Mat dist_cv = (cv::Mat_<float>(8, 1) <<
|
|
|
|
|
+ cam_dist.k1, cam_dist.k2, cam_dist.p1, cam_dist.p2,
|
|
|
|
|
+ cam_dist.k3, cam_dist.k4, cam_dist.k5, cam_dist.k6);
|
|
|
|
|
+ // @formatter:on
|
|
|
|
|
+
|
|
|
|
|
+ auto img_size = cv::Size(cam_in.width, cam_in.height);
|
|
|
|
|
+ auto points_size = cv::Size(img_size.area(), 1);
|
|
|
|
|
+ auto points_mat = cv::Mat(points_size, CV_32FC2);
|
|
|
|
|
+ for (auto iy = 0; iy < cam_in.height; ++iy)
|
|
|
|
|
+ for (auto ix = 0; ix < cam_in.width; ++ix) {
|
|
|
|
|
+ auto id = iy * cam_in.width + ix;
|
|
|
|
|
+ points_mat.at<cv::Vec2f>(id) = cv::Vec2f(ix, iy);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ auto undistort_img = create_image(img_size, CV_32FC2);
|
|
|
|
|
+ auto data = undistort_img->memory(MEM_HOST).start_ptr();
|
|
|
|
|
+ auto undistort_mat = cv::Mat(points_size, CV_32FC2, data);
|
|
|
|
|
+ cv::undistortPoints(points_mat, undistort_mat, cam_mat_cv, dist_cv);
|
|
|
|
|
+ undistort_img->host_modified();
|
|
|
|
|
+ OBJ_SAVE(remap_name, undistort_img);
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
bool orb_camera::impl::start(start_config conf) {
|
|
bool orb_camera::impl::start(start_config conf) {
|
|
|
assert(!is_capturing);
|
|
assert(!is_capturing);
|
|
|
auto ob_conf = std::make_shared<ob::Config>();
|
|
auto ob_conf = std::make_shared<ob::Config>();
|
|
@@ -190,12 +237,17 @@ bool orb_camera::impl::start(start_config conf) {
|
|
|
// Example says that the filter depends on the started pipeline.
|
|
// Example says that the filter depends on the started pipeline.
|
|
|
if (conf.pc.enable) {
|
|
if (conf.pc.enable) {
|
|
|
pc_filter = std::make_shared<ob::PointCloudFilter>();
|
|
pc_filter = std::make_shared<ob::PointCloudFilter>();
|
|
|
|
|
+ auto params = pipe->getCameraParam();
|
|
|
pc_filter->setCameraParam(pipe->getCameraParam());
|
|
pc_filter->setCameraParam(pipe->getCameraParam());
|
|
|
pc_filter->setCreatePointFormat(OB_FORMAT_RGB_POINT);
|
|
pc_filter->setCreatePointFormat(OB_FORMAT_RGB_POINT);
|
|
|
pc_filter->setCallBack([this](auto frame) { pc_callback(frame); });
|
|
pc_filter->setCallBack([this](auto frame) { pc_callback(frame); });
|
|
|
pc_name = conf.pc.name;
|
|
pc_name = conf.pc.name;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ // open a new thread to do the time-consuming calculation work
|
|
|
|
|
+ aux_thread = std::make_unique<std::thread>(
|
|
|
|
|
+ [this] { generate_undistort_map(); });
|
|
|
|
|
+
|
|
|
return true;
|
|
return true;
|
|
|
}
|
|
}
|
|
|
|
|
|