Ejemplo n.º 1
0
 def test_unwarp_line_backward(self):
     list_clines = post.unwarp_line_backward(self.list_dlines, self.x0,
                                             self.y0, self.list_fact)
     error = np.max(
         np.asarray([
             np.max(np.abs(line - self.list_lines[i]))
             for (i, line) in enumerate(list_clines)
         ]))
     self.assertTrue(error <= 1.0)
Ejemplo n.º 2
0
    def test_calc_residual_ver(self):
        dot_dist = 2.0
        list_fact = [1.0, -2.0 * 10**(-3)]
        list_ver_lines = [[[self.hei - y, x]
                           for y in np.arange(1, self.hei, dot_dist)]
                          for x in np.arange(1, self.wid, dot_dist)]
        list_ver_dlines = []
        for line in list_ver_lines:
            line1 = np.asarray(line)
            xu_list = line1[:, 1] - self.x0
            yu_list = line1[:, 0] - self.y0
            ru_list = np.sqrt(xu_list**2 + yu_list**2)
            flist = np.sum(np.asarray(
                [factor * ru_list**i for i, factor in enumerate(list_fact)]),
                           axis=0)
            xd_list = self.x0 + xu_list * flist
            yd_list = self.y0 + yu_list * flist
            list_ver_dlines.append(np.asarray(list(zip(yd_list, xd_list))))

        list_ver_clines = post.unwarp_line_backward(list_ver_dlines, self.x0,
                                                    self.y0, list_fact)
        list_res = post.calc_residual_ver(list_ver_clines, self.x0, self.y0)
        error = np.max(list_res[:, 1])
        self.assertTrue(error < 0.5)
Ejemplo n.º 3
0
# Regenerate grid points after correcting the perspective effect.
list_hor_lines, list_ver_lines = proc.regenerate_grid_points_parabola(
    list_hor_lines, list_ver_lines, perspective=True)

# Calculate parameters of the radial correction model
(xcenter, ycenter) = proc.find_cod_coarse(list_hor_lines, list_ver_lines)
list_fact = proc.calc_coef_backward(list_hor_lines, list_ver_lines, xcenter,
                                    ycenter, num_coef)
io.save_metadata_txt(output_base + "/coefficients_radial_distortion.txt",
                     xcenter, ycenter, list_fact)
print("X-center: {0}. Y-center: {1}".format(xcenter, ycenter))
print("Coefficients: {0}".format(list_fact))

# Check the correction results:
# Apply correction to the lines of points
list_uhor_lines = post.unwarp_line_backward(list_hor_lines, xcenter, ycenter,
                                            list_fact)
list_uver_lines = post.unwarp_line_backward(list_ver_lines, xcenter, ycenter,
                                            list_fact)
# Calculate the residual of the unwarpped points.
list_hor_data = post.calc_residual_hor(list_uhor_lines, xcenter, ycenter)
list_ver_data = post.calc_residual_ver(list_uver_lines, xcenter, ycenter)
# Save the results for checking
io.save_plot_image(output_base + "/unwarpped_horizontal_lines.png",
                   list_uhor_lines, height, width)
io.save_plot_image(output_base + "/unwarpped_vertical_lines.png",
                   list_uver_lines, height, width)
io.save_residual_plot(output_base + "/hor_residual_after_correction.png",
                      list_hor_data, height, width)
io.save_residual_plot(output_base + "/ver_residual_after_correction.png",
                      list_ver_data, height, width)