Skip to content
Snippets Groups Projects
Commit 2dc12cf5 authored by manurare's avatar manurare
Browse files

Fix nan values in scale term and coords artifacts in depthmap

parent 43347063
No related branches found
No related tags found
No related merge requests found
...@@ -121,7 +121,7 @@ public: ...@@ -121,7 +121,7 @@ public:
// depth map's sub map filename regular expression // depth map's sub map filename regular expression
int index_digit_number = 3; int index_digit_number = 3;
std::string depthmap_filename_regexp = "[a-zA-Z0-9\\_]*\\_depth\\_[0-9]{3}.pfm"; std::string depthmap_filename_regexp = "[a-zA-Z0-9\\_]*\\_disp\\_erp\\_[0-9]{3}.pfm";
std::string rgb_filename_regexp = "[a-zA-Z0-9\\_]*\\_rgb\\_[0-9]{3}.jpg"; std::string rgb_filename_regexp = "[a-zA-Z0-9\\_]*\\_rgb\\_[0-9]{3}.jpg";
std::string corr_filename_regexp = "[a-zA-Z0-9\\_]*\\_corr\\_[0-9]{3}\\_[0-9]{3}.json"; std::string corr_filename_regexp = "[a-zA-Z0-9\\_]*\\_corr\\_[0-9]{3}\\_[0-9]{3}.json";
// pixels corresponding filename regular expression // pixels corresponding filename regular expression
......
...@@ -122,9 +122,9 @@ void DepthmapStitcher::load_data(const std::string& data_root_dir, const std::ve ...@@ -122,9 +122,9 @@ void DepthmapStitcher::load_data(const std::string& data_root_dir, const std::ve
intidx2extidx[index] = depthmap_extindex; intidx2extidx[index] = depthmap_extindex;
} }
smatch m_prefixs; smatch m_prefixs;
regex_search(depthmap_filename_list[0], m_prefixs, std::regex("[a-zA-Z0-9]*_rgb")); regex_search(depthmap_filename_list[0], m_prefixs, std::regex("[a-zA-Z0-9\\_]*\\_disp"));
std::string prefix = m_prefixs[0].str(); std::string prefix = m_prefixs[0].str();
filename_prefix = prefix.substr(0, prefix.length()); filename_prefix = prefix.substr(0, prefix.length()-5);
LOG(INFO) << "File name prefix is " << filename_prefix; LOG(INFO) << "File name prefix is " << filename_prefix;
// 1) load the pixel corresponding relationship // 1) load the pixel corresponding relationship
......
...@@ -201,9 +201,12 @@ struct DepthmapStitcherGroup::ScaleResidual { ...@@ -201,9 +201,12 @@ struct DepthmapStitcherGroup::ScaleResidual {
T sum_number(0); T sum_number(0);
for (int index = 0; index < grid_width_ * grid_height_; index++) for (int index = 0; index < grid_width_ * grid_height_; index++)
{ {
sum_number += 1.0 / scale_list[index]; sum_number += 1.0 / (scale_list[index] + T(1e-10));
} }
residual[0] = sum_number; residual[0] = sum_number;
// if (ceres::isinf(residual[0]) || ceres::isnan(residual[0])){
// printf("INFINITY SCALE\n");
// }
return true; return true;
} }
......
...@@ -33,7 +33,7 @@ class BlendIt: ...@@ -33,7 +33,7 @@ class BlendIt:
# sub-image number # sub-image number
self.fidelity_weight = 1.0 self.fidelity_weight = 1.0
self.inflection_point = 10 # point where slope starts to affect the radial blendweights self.inflection_point = 10 # point where slope starts to affect the radial blendweights
self.diagonal_percentage = 30 # Percentage of diagonal until weights start decaying in frustum weights self.diagonal_percentage = 48.5 # Percentage of diagonal until weights start decaying in frustum weights
self.n_subimages = n_subimages self.n_subimages = n_subimages
self.blending_method = blending_method self.blending_method = blending_method
self.padding = padding self.padding = padding
...@@ -153,23 +153,19 @@ class BlendIt: ...@@ -153,23 +153,19 @@ class BlendIt:
erp_image_height, sph_modulo=False) erp_image_height, sph_modulo=False)
# process the image boundary # process the image boundary
erp_image_col_start = int(erp_image_col_start) if int(erp_image_col_start) > 0 else int( erp_image_col_start = int(erp_image_col_start + 0.5)
erp_image_col_start - 0.5) erp_image_col_stop = int(erp_image_col_stop + 0.5)
erp_image_col_stop = int(erp_image_col_stop + 0.5) if int(erp_image_col_stop) > 0 else int( erp_image_row_start = int(erp_image_row_start + 0.5)
erp_image_col_stop) erp_image_row_stop = int(erp_image_row_stop + 0.5)
erp_image_row_start = int(erp_image_row_start) if int(erp_image_row_start) > 0 else int(
erp_image_row_start - 0.5)
erp_image_row_stop = int(erp_image_row_stop + 0.5) if int(erp_image_row_stop) > 0 else int(
erp_image_row_stop)
triangle_x_range = np.linspace(erp_image_col_start, erp_image_col_stop, triangle_x_range = np.linspace(erp_image_col_start, erp_image_col_stop,
erp_image_col_stop - erp_image_col_start + 1) erp_image_col_stop - erp_image_col_start, endpoint=False)
triangle_y_range = np.linspace(erp_image_row_start, erp_image_row_stop, triangle_y_range = np.linspace(erp_image_row_start, erp_image_row_stop,
erp_image_row_stop - erp_image_row_start + 1) erp_image_row_stop - erp_image_row_start, endpoint=False)
triangle_xv, triangle_yv = np.meshgrid(triangle_x_range, triangle_y_range) triangle_xv, triangle_yv = np.meshgrid(triangle_x_range, triangle_y_range)
# process the wrap around # process the wrap around
triangle_xv = np.remainder(triangle_xv, erp_image_width) triangle_xv = np.remainder(triangle_xv, erp_image_width)
triangle_yv = np.remainder(triangle_yv, erp_image_height) triangle_yv = np.clip(triangle_yv, 0, erp_image_height - 1)
# 2) sample the pixel value from tanget image # 2) sample the pixel value from tanget image
# project spherical coordinate to tangent plane # project spherical coordinate to tangent plane
...@@ -328,29 +324,6 @@ class BlendIt: ...@@ -328,29 +324,6 @@ class BlendIt:
height, width = size height, width = size
weight_matrix = np.zeros((height, width), dtype=np.float) weight_matrix = np.zeros((height, width), dtype=np.float)
# Line in the form x = o + td. Where o origin and d direction vector
if height == width:
origin = np.array([0., 0.])
dir_vector = np.array([height - origin[0], width - origin[1]])
top_left = (origin + self.diagonal_percentage / 100. * dir_vector).astype(np.int)
bottom_right = (origin + (1 - self.diagonal_percentage / 100.) * dir_vector).astype(np.int)
weight_matrix[top_left[0]:bottom_right[0], top_left[1]:bottom_right[1]] = 1.
# If the image is not squared then two lines of the form above are needed displaced in X at the center of the img
else:
# Both lines are supposed to have slope 1. The beginning of the bottom line is the end of the top line
# displaced (width/height) horizontally
tophalf_diag_line_origin = np.array([0., 0.])
tophalf_diag_line_dir = np.array([height//2, height//2]) - tophalf_diag_line_origin
bottomhalf_diag_line_origin = np.array([height//2, width/height*width*0.5])
bottomhalf_diag_line_dir = np.array([height, width]) - bottomhalf_diag_line_origin
top_left = (tophalf_diag_line_origin + 2 * self.diagonal_percentage / 100. * tophalf_diag_line_dir).astype(np.int)
bottom_right = (bottomhalf_diag_line_origin + (1 - (2 * self.diagonal_percentage / 100.)) *
bottomhalf_diag_line_dir).astype(np.int)
weight_matrix[top_left[0]:bottom_right[0], top_left[1]:bottom_right[1]] = 1.
x_list = np.linspace(0, width, width, endpoint=False) x_list = np.linspace(0, width, width, endpoint=False)
y_list = np.linspace(0, height, height, endpoint=False) y_list = np.linspace(0, height, height, endpoint=False)
grid_x, grid_y = np.meshgrid(x_list, y_list) grid_x, grid_y = np.meshgrid(x_list, y_list)
...@@ -361,11 +334,20 @@ class BlendIt: ...@@ -361,11 +334,20 @@ class BlendIt:
dist_to_top = grid_y dist_to_top = grid_y
dist_to_bottom = np.abs(grid_y - height) dist_to_bottom = np.abs(grid_y - height)
# Build pyramid of distances
total_dist = np.dstack((dist_to_right, dist_to_left, dist_to_top, dist_to_bottom)) total_dist = np.dstack((dist_to_right, dist_to_left, dist_to_top, dist_to_bottom))
total_dist = np.min(total_dist, axis=2) total_dist = np.min(total_dist, axis=2)
total_dist[np.where(weight_matrix != 0.)] = 0
total_dist = (total_dist - np.min(total_dist)) / np.ptp(total_dist) total_dist = (total_dist - np.min(total_dist)) / np.ptp(total_dist)
total_dist[np.where(weight_matrix != 0.)] = 1 peak_coors = np.where(total_dist == 1)
peak_top_left = np.array([np.min(peak_coors[0]), np.min(peak_coors[1])])
peak_bottom_right = np.array([np.max(peak_coors[0]), np.max(peak_coors[1])])
unit_dir = np.array([1/np.sqrt(2), 1/np.sqrt(2)])
top_left = (peak_top_left - 2*self.diagonal_percentage*unit_dir).astype(np.int)
bottom_right = (peak_bottom_right + 2*self.diagonal_percentage*unit_dir).astype(np.int)
total_dist[top_left[0]:bottom_right[0]+1, top_left[1]:bottom_right[1]+1] = 0
total_dist = (total_dist - np.min(total_dist)) / np.ptp(total_dist)
total_dist[top_left[0]:bottom_right[0] + 1, top_left[1]:bottom_right[1] + 1] = 1
return total_dist return total_dist
def laplacian_matrix(self, n, m): def laplacian_matrix(self, n, m):
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment