Beispiel #1
0
 def test_save_plot_image(self):
     ver = sys.version[:3]
     check = True
     if ver != "2.7":
         file_path = "data/plot.png"
         list_lines = [
             np.asarray([(i, j) for j in range(5, 64, 5)])
             for i in range(5, 64, 5)
         ]
         losa.save_plot_image(file_path, list_lines, 64, 64, dpi=100)
         check = os.path.isfile(file_path)
     self.assertTrue(check)
Beispiel #2
0
                                           dist_hor,
                                           ratio=0.1,
                                           num_dot_miss=2,
                                           accepted_ratio=0.8)
list_ver_lines = prep.group_dots_ver_lines(list_points_ver_lines,
                                           slope_ver,
                                           dist_ver,
                                           ratio=0.1,
                                           num_dot_miss=2,
                                           accepted_ratio=0.8)
# Remove residual dots
list_hor_lines = prep.remove_residual_dots_hor(list_hor_lines, slope_hor, 2.0)
list_ver_lines = prep.remove_residual_dots_ver(list_ver_lines, slope_ver, 2.0)

# Save output for checking
io.save_plot_image(output_base + "/horizontal_lines.png", list_hor_lines,
                   height, width)
io.save_plot_image(output_base + "/vertical_lines.png", list_ver_lines, height,
                   width)
list_hor_data = post.calc_residual_hor(list_hor_lines, 0.0, 0.0)
list_ver_data = post.calc_residual_ver(list_ver_lines, 0.0, 0.0)
io.save_residual_plot(output_base + "/hor_residual_before_correction.png",
                      list_hor_data, height, width)
io.save_residual_plot(output_base + "/ver_residual_before_correction.png",
                      list_ver_data, height, width)

# 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)
Beispiel #3
0
# by the slope and the acceptable variation. Only lines with the number of
# dots >= 70% of the maximum number of dots on a line are kept.

list_hor_lines = prep.group_dots_hor_lines(mat1,
                                           hor_slope,
                                           dot_dist,
                                           ratio=0.3,
                                           num_dot_miss=6,
                                           accepted_ratio=0.7)
list_ver_lines = prep.group_dots_ver_lines(mat1,
                                           ver_slope,
                                           dot_dist,
                                           ratio=0.3,
                                           num_dot_miss=6,
                                           accepted_ratio=0.7)
io.save_plot_image(output_base + "/group_horizontal_dots.png", list_hor_lines,
                   height, width)
io.save_plot_image(output_base + "/group_vertical_dots.png", list_ver_lines,
                   height, width)

# Optional step: Remove residual dots.
# The method uses coordinates of dots on each line for parabolic fit, then
# remove dots with distance to the fitted parabolas greater than 2.0 pixel.
list_hor_lines = prep.remove_residual_dots_hor(list_hor_lines,
                                               hor_slope,
                                               residual=2.0)
list_ver_lines = prep.remove_residual_dots_ver(list_ver_lines,
                                               ver_slope,
                                               residual=2.0)
io.save_plot_image(output_base + "/horizontal_dots_refined.png",
                   list_hor_lines, height, width)
io.save_plot_image(output_base + "/vertical_dots_refined.png", list_ver_lines,
Beispiel #4
0
                    height, width)

print("4-> Group points into lines !!!!")
list_hor_lines = prep.group_dots_hor_lines(list_points_hor_lines, slope_hor,
                                           dist_hor)
list_ver_lines = prep.group_dots_ver_lines(list_points_ver_lines, slope_ver,
                                           dist_ver)
# Optional: remove residual dots
list_hor_lines = prep.remove_residual_dots_hor(list_hor_lines, slope_hor, 2.0)
list_ver_lines = prep.remove_residual_dots_ver(list_ver_lines, slope_ver, 2.0)

print("5-> Correct perspective effect !!!!")
# Optional: correct perspective effect.
list_hor_lines, list_ver_lines = proc.regenerate_grid_points_parabola(
    list_hor_lines, list_ver_lines, perspective=True)
io.save_plot_image(output_base + "/hor_lines.png", list_hor_lines, height,
                   width)
io.save_plot_image(output_base + "/ver_lines.png", list_ver_lines, height,
                   width)

# Check if the distortion is significant.
list_hor_data = post.calc_residual_hor(list_hor_lines, 0.0, 0.0)
io.save_residual_plot(output_base + "/residual_horizontal_points_before.png",
                      list_hor_data, height, width)
list_ver_data = post.calc_residual_ver(list_ver_lines, 0.0, 0.0)
io.save_residual_plot(output_base + "/residual_vertical_points_before.png",
                      list_ver_data, height, width)

print("6-> Calculate the centre of distortion !!!!")
(xcenter, ycenter) = proc.find_cod_coarse(list_hor_lines, list_ver_lines)
print("   X-center: {0}, Y-center: {1}".format(xcenter, ycenter))
Beispiel #5
0
# Group dots into lines.
list_hor_lines0 = prep.group_dots_hor_lines(mat1,
                                            hor_slope,
                                            dot_dist,
                                            ratio=0.3,
                                            num_dot_miss=2,
                                            accepted_ratio=0.6)
list_ver_lines0 = prep.group_dots_ver_lines(mat1,
                                            ver_slope,
                                            dot_dist,
                                            ratio=0.3,
                                            num_dot_miss=2,
                                            accepted_ratio=0.6)

# Save output for checking
io.save_plot_image(output_base + "/horizontal_lines.png", list_hor_lines0,
                   height, width)
io.save_plot_image(output_base + "/vertical_lines.png", list_ver_lines0,
                   height, width)
list_hor_data = post.calc_residual_hor(list_hor_lines0, 0.0, 0.0)
list_ver_data = post.calc_residual_ver(list_ver_lines0, 0.0, 0.0)
io.save_residual_plot(output_base + "/hor_residual_before_correction.png",
                      list_hor_data, height, width)
io.save_residual_plot(output_base + "/ver_residual_before_correction.png",
                      list_ver_data, height, width)

# Optional: for checking perspective distortion
(xcen_tmp, ycen_tmp) = proc.find_cod_bailey(list_hor_lines0, list_ver_lines0)
list_hor_coef = proc._para_fit_hor(list_hor_lines0, xcen_tmp, ycen_tmp)[0]
list_ver_coef = proc._para_fit_ver(list_ver_lines0, xcen_tmp, ycen_tmp)[0]
# Optional: plot the results
plt.figure(0)