Code Monkey home page Code Monkey logo

rgbdplanedetection's Introduction

RGBDPlaneDetection

This code is an implementation of RGB-D plane detection and color-based plane refinement with MRF(graph-cut) optimization.

Example: input color and depth image of frame-000000 from BundleFusion dataset's copyroom (the depth image here is scaled by a factor 10 for rendering purpose):

Result planes without (left) and with (right) MRF-based optimization:

Reference

General pipeline:

@inproceedings{wang2018plane,
  title={Plane-Based Optimization of Geometry and Texture for RGB-D Reconstruction of Indoor Scenes},
  author={Wang, Chao and Guo, Xiaohu},
  booktitle={2018 International Conference on 3D Vision (3DV)},
  pages={533--541},
  year={2018},
  organization={IEEE}
}

and plane detection on a single RGB-D frame:

@inproceedings{feng2014fast,
  title={Fast plane extraction in organized point clouds using agglomerative hierarchical clustering},
  author={Feng, Chen and Taguchi, Yuichi and Kamat, Vineet R},
  booktitle={Robotics and Automation (ICRA), 2014 IEEE International Conference on},
  pages={6218--6225},
  year={2014},
  organization={IEEE}
}

Dependencies

  • OpenCV 3
  • Eigen 3
  • MRF 2.2 (already included)
  • Fast plane detection on a single depth image: PEAC (already included)

Usage

RGBDPlaneDetection <-o> color_image depth_image output_folder

-o (optional) is to run MRF-based optimization for plane refinement. For example:

RGBDPlaneDetection ../pic/frame-000000.color.jpg ../pic/frame-000000.depth.png ../pic 
RGBDPlaneDetection -o ../pic/frame-000000.color.jpg ../pic/frame-000000.depth.png ../pic 

Two scripts demo_win.sh and demo_linux_mac.sh are provided for reference to run the code on a RGB-D sequence with multiple images. Note to modify the corresponding paths.

Build

  • Windows: use Visual Studio to open sln file and compile and build the code. It is tested successfully in Visual Studio 2010 and 2013, and should work on all other Visual Studio platforms. Note to change your OpenCV and Eigen 3 paths if needed.

  • Linux or Mac OS: run build_linux_mac.sh to build the code.

Running time

Without MRF optimization, the execution program by Visual Studio 2010 or 2013 runs at about 25 FPS (including data I/O) on RGBD images with resolution 640x480 in a PC with 16GB RAM and intel i7 processor. With MRF optimization, the same code runs much slower at about 7 seconds per frame on the same data.

Input and Output

Input: color image and depth image.

Output:

  1. Plane segmentation image in PNG;
  2. Plane label file in TXT: the label index of the plane which each pixel belongs to, starting from 0 to N - 1 where N is the number of planes. If a pixel is not on any plane, then its label value is N.
  3. Plane data file in TXT. Each line represents one plane with format like this:
#plane_index(starting from 0 to #planes - 1) number_of_points_on_the_plane plane_color_in_png_image(r,g,b between [0,255]) plane_normal(1x3) plane_center(1x3) sx sy sz sxx syy szz sxy syz sxz

Here (sx sy sz) are average of sum of all 3D points (x, y, z) on the plane, (sxx syy szz sxy syz sxz) are the average of sum of x*x, y*y, z*z, x*y, y*z, z*z of all 3D points on the plane, respectively.

Note

  • Without MRF optimization, this code is simply the re-use of PEAC code.
  • Currently the code only works on BundleFusion or 3DLite depth data format (16UC1 image with depth value in millimeter). If you want to use other kinds of RGB-D data, you need to rewrite the part of reading color and depth images, reset the camera intrinsic parameters the scale factor for depth images in plane_detection.h.
  • NOTE for MRF crash in Windows: Sometimes MRF 2.2 source code crashes in Visual Studio in Windows due to some kind of memory leak problem, but this code works well in Linux and Mac OS. If you meet this problem, just have a try in Linux or Mac OS, or remove the MRF optimization option -o.

rgbdplanedetection's People

Contributors

chaowang15 avatar cwang15 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

rgbdplanedetection's Issues

Requirements for the images / error: vector subscript out of range

What are the requirements for the images? I am currently trying with my own images, but I get an error message: vector subscript out of range
The error comes from plane_detection.cpp line 226. new_pidx gets -1.

My images are 1280x720 and I have adjusted the corresponding constants (plane_detection.h lines 25-30). But even if I scale my images to 640x480 before, I get the error.

In addition the plane image looks very strange.
1280x720 without adjusted constants: (no change, cloned 25.05.2020)
f_00000-plane

1280x720 with adjusted constants (similar to the image when scaled to 640x480):
f_00000-plane

The only change I made to adjust constants:

diff --git a/RGBDPlaneDetection/plane_detection.h b/RGBDPlaneDetection/plane_detection.h
index 8e1d876..b58ebf8 100644
--- a/RGBDPlaneDetection/plane_detection.h
+++ b/RGBDPlaneDetection/plane_detection.h
@@ -22,12 +22,12 @@ const float kInfVal = 1000000; // an infinite large value used in MRF optimizati

// Camera intrinsic parameters.
// All BundleFusion data uses the following parameters.
-const double kFx = 583;
-const double kFy = 583;
-const double kCx = 320;
-const double kCy = 240;
-const int kDepthWidth = 640;
-const int kDepthHeight = 480;
+const double kFx = 633.085;
+const double kFy = 633.085;
+const double kCx = 640.891;
+const double kCy = 356.606;
+const int kDepthWidth = 1280;
+const int kDepthHeight = 720;

#if defined(linux) || defined(APPLE)
#define _isnan(x) isnan(x)

At last the original pictures:
f_00000_color
f_00000_depth16
(Recorded in an simulation, based on the Stanford data set)

Explaining the plane normal representation

Hi,

I am just a bit confused about your representation of the plane normal. They are three numbers, representing a vector in 3d space (correct me if I am wrong). But how is this of use to me if I don't know how the world coordinate system is defined?

So my question is: how does this vector relate in space?

Small modifications required for linux

Hello,
First of all, thank you very much to share your code.
In order that your code runs in Ubuntu, I had to done two small modifications:
On one hand, I had to add the Makefile on the include/MRF2.2 that you can find in the following library link (http://vision.middlebury.edu/MRF/code/).
On the other hand, you wrote in the readme.txt file that the following command is required to use the package:

RGBDPlaneDetection <-o> color_image depth_image

however, the arguments required in the main.cpp are almost 4, where you need to add the output path, for example, I use the directory path:

RGBDPlaneDetection <-o> color_image depth_image .

Thanks again!

exception when running mrf->optimize

Hi,
I found the code always generates an exception when running mrf refinement.
Specifically, the exception is triggered in this function:
Graph::flowtype Graph::maxflow()
{
...
if (a_for->r_rev_cap)
}
where a_for is a NULL pointer.

Have you ever encountered this issue? Would you please give me some clue?

Thanks!

ps. I have set the cam. intrinsics correctly.

How does the ScaleFactor work?

Hi, I'm running the codes on my own datasets. I know that the variable kScaleFactor in plane_detection.h should be changed for different datasets. My question is how should I change this scale factor? It would be great if there is either a theoretical explaination or some empirical ways for tuning it.

Thanks!

How can I get the depth image into 16uc1 format?

Hi, I'm generating depth map images in .png from an Intel Realsense camera, but I can't seem to get the format to match the 16uc1 format. I originally had a uint8 format, did anybody else have issue getting the format correctly, or have advice how to ensure the data type is right? Is this a format that has to be created using C++ only? I was trying to do data streaming and processing using Python just to save the depth images, and then run the PlaneDetection code.

Thanks!

Eric

not clear how to run the program

Thank you for the repo. but it is not clear to me how to run/test your repo. The followings are what I have tried.

  1. Based on the description "Usage: RGBDPlaneDetection <-o> color_image depth_image output_folder". Both depth image and color image are needed for input. but only a color image is find in the pic/ folder.
  2. I have tested the program on one of my own image pairs, as shown in the attached files, but the result is confusing, see attached as well.

Thank you

Peter.

large numbers of image sequences

Hi,

I have noticed that when I'm processing image sequences with release mode, it crashes after a while, and the plane-data is incorrect (the segment result is right). I have tested it in windows 10 and ubuntu. It is correct with a single image, but it fails to deal with image sequences (I mean the plane-data, especially the pixel numbers of plane ). The debug mode can work with image sequences, but the speed is very slow and almost stop after 100 images. So I wonder it may be some memory bug. Would you please test with image sequences? I think 10 images is enough. By the way, I didn't use MRF.

Thank you!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.