From 52f818f35cd9fb1bb46bc0e259db2e6c0700c928 Mon Sep 17 00:00:00 2001 From: Nicolas Pope <nwpope@utu.fi> Date: Fri, 24 May 2019 14:48:19 +0300 Subject: [PATCH] Ray cast to mat image --- .../reconstruct/include/ftl/ray_cast_util.hpp | 2 +- applications/reconstruct/src/main.cpp | 21 ++++++++++--------- components/renderers/cpp/src/display.cpp | 1 + 3 files changed, 13 insertions(+), 11 deletions(-) diff --git a/applications/reconstruct/include/ftl/ray_cast_util.hpp b/applications/reconstruct/include/ftl/ray_cast_util.hpp index ecd82ea17..ed01c5e65 100644 --- a/applications/reconstruct/include/ftl/ray_cast_util.hpp +++ b/applications/reconstruct/include/ftl/ray_cast_util.hpp @@ -61,7 +61,7 @@ struct RayCastData { __host__ void download(float3 *points, uchar3 *colours, const RayCastParams& params) const { //printf("Download: %d,%d\n", params.m_width, params.m_height); - cudaSafeCall(cudaMemcpy(points, d_depth3, sizeof(float3) * params.m_width * params.m_height, cudaMemcpyDeviceToHost)); + //cudaSafeCall(cudaMemcpy(points, d_depth3, sizeof(float3) * params.m_width * params.m_height, cudaMemcpyDeviceToHost)); cudaSafeCall(cudaMemcpy(colours, d_colors, sizeof(uchar3) * params.m_width * params.m_height, cudaMemcpyDeviceToHost)); } diff --git a/applications/reconstruct/src/main.cpp b/applications/reconstruct/src/main.cpp index d715e19fa..dcbc47a46 100644 --- a/applications/reconstruct/src/main.cpp +++ b/applications/reconstruct/src/main.cpp @@ -396,18 +396,19 @@ static void run() { LOG(INFO) << "Scene created"; float3 *point_array = new float3[rayparams.m_width*rayparams.m_height]; - uchar3 *colour_array = new uchar3[rayparams.m_width*rayparams.m_height]; + //uchar3 *colour_array = new uchar3[rayparams.m_width*rayparams.m_height]; + cv::Mat colour_array(cv::Size(rayparams.m_width,rayparams.m_height), CV_8UC3); float bounce = 0.0; int bounce_dir = 1; - net.broadcast("grab"); // To sync cameras + //net.broadcast("grab"); // To sync cameras int active = inputs.size(); while (active > 0 && display_merged.active()) { active = 0; - + net.broadcast("grab"); // To sync cameras PointCloud<PointXYZRGB>::Ptr cloud(new PointCloud<PointXYZRGB>); @@ -462,7 +463,7 @@ static void run() { else bounce -= 0.02f; if (fabs(bounce) > 1.0f) bounce_dir = (bounce_dir > 0) ? -1 : 1; - Eigen::Affine3f transform(Eigen::Translation3f(bounce,0.0f,0.0f)); + Eigen::Affine3f transform(Eigen::Translation3f(-1.0f+bounce*0.3f,0.0f,bounce)); Eigen::Matrix4f viewPose = transform.matrix(); //viewPose = inputs[0].source->getPose(); @@ -471,11 +472,11 @@ static void run() { rays.render(scene.getHashData(), scene.getHashParams(), inputs[0].gpu, viewPose); LOG(INFO) << "Download points"; - rays.getRayCastData().download(point_array, colour_array, rayparams); + rays.getRayCastData().download(point_array, (uchar3*)colour_array.data, rayparams); int pc = 0; - LOG(INFO) << "Convert points..."; + /*LOG(INFO) << "Convert points..."; for (int i=0; i<rayparams.m_width*rayparams.m_height; i++) { if (point_array[i].x == MINF || point_array[i].z == 0.0f) continue; pcl::PointXYZRGB p(colour_array[i].z, colour_array[i].y, colour_array[i].x); @@ -487,14 +488,14 @@ static void run() { pc++; } - if (pc > 0) { - display_merged.render(cloud); + if (pc > 0) {*/ + display_merged.render(colour_array); display_merged.wait(1); - } + //} } delete [] point_array; - delete [] colour_array; + //delete [] colour_array; #endif // TODO non-PCL (?) } diff --git a/components/renderers/cpp/src/display.cpp b/components/renderers/cpp/src/display.cpp index a768c10e8..9e8e72cad 100644 --- a/components/renderers/cpp/src/display.cpp +++ b/components/renderers/cpp/src/display.cpp @@ -222,6 +222,7 @@ bool Display::render(pcl::PointCloud<pcl::PointXYZRGB>::ConstPtr pc) { #endif // HAVE_PCL bool Display::render(const cv::Mat &img, style_t s) { if (s == STYLE_NORMAL) { + cv::namedWindow("Image", cv::WINDOW_KEEPRATIO); cv::imshow("Image", img); } else if (s = STYLE_DISPARITY) { Mat idepth; -- GitLab