Skip to content

Commit

Permalink
add input image correctness checks
Browse files Browse the repository at this point in the history
  • Loading branch information
valgur committed Mar 21, 2020
1 parent 7c3d94c commit dd546b4
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 6 deletions.
6 changes: 3 additions & 3 deletions include/surface_normal.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ struct CameraIntrinsics {
float cy;
};

cv::Mat3f normals_from_depth(const cv::Mat &depth, CameraIntrinsics intrinsics, int window_size,
float max_rel_depth_diff);
cv::Mat3f normals_from_depth(const cv::Mat1f &depth, CameraIntrinsics intrinsics,
int window_size = 15, float max_rel_depth_diff = 0.1);

cv::Mat3b normals_to_rgb(const cv::Mat3f &normals);

cv::Mat1f get_surrounding_points(const cv::Mat &depth, int i, int j, CameraIntrinsics intrinsics,
cv::Mat1f get_surrounding_points(const cv::Mat1f &depth, int i, int j, CameraIntrinsics intrinsics,
size_t window_size, float max_rel_depth_diff);

cv::Vec3f fit_plane(const cv::Mat &points);
9 changes: 8 additions & 1 deletion src/python.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,14 @@ void normals_from_depth_wrapper(const std::string &depth_in_path, const std::str
intrinsics.f = std::get<0>(intrinsics_tuple);
intrinsics.cx = std::get<1>(intrinsics_tuple);
intrinsics.cy = std::get<2>(intrinsics_tuple);
cv::Mat depth = cv::imread(depth_in_path, cv::IMREAD_ANYDEPTH | cv::IMREAD_GRAYSCALE);
cv::Mat depth = cv::imread(depth_in_path, cv::IMREAD_UNCHANGED);
if (depth.size().area() == 0) {
throw std::runtime_error("Empty image");
}
if (depth.channels() != 1) {
throw std::runtime_error("Not a single-channel depth image. Image has " +
std::to_string(depth.channels()) + " channels.");
}
depth.convertTo(depth, CV_32F);
cv::Mat3f normals = normals_from_depth(depth, intrinsics, window_size, max_rel_depth_diff);
cv::Mat3b normals_rgb = normals_to_rgb(normals);
Expand Down
4 changes: 2 additions & 2 deletions src/surface_normal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
using namespace cv;

// Returns a Nx3 matrix of 3D points surrounding the i,j pixel within the window_size window.
Mat1f get_surrounding_points(const Mat &depth, int i, int j, CameraIntrinsics intrinsics,
Mat1f get_surrounding_points(const Mat1f &depth, int i, int j, CameraIntrinsics intrinsics,
size_t window_size, float max_rel_depth_diff) {
float f_inv = 1.f / intrinsics.f;
float cx = intrinsics.cx;
Expand Down Expand Up @@ -58,7 +58,7 @@ Vec3f fit_plane(const Mat &points) {
return normal;
}

Mat3f normals_from_depth(const Mat &depth, CameraIntrinsics intrinsics, int window_size,
Mat3f normals_from_depth(const Mat1f &depth, CameraIntrinsics intrinsics, int window_size,
float max_rel_depth_diff) {
Mat3f normals = Mat::zeros(depth.size(), CV_32FC3);
for (int i = 0; i < depth.rows; i++) {
Expand Down

0 comments on commit dd546b4

Please sign in to comment.