-
Notifications
You must be signed in to change notification settings - Fork 4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix some little problems #2
Open
gaunthan
wants to merge
2
commits into
IRIM-Technology-Transition-Lab:master
Choose a base branch
from
gaunthan:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+50
−63
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -61,28 +61,15 @@ def calibrate(directory, rows, cols, space, win=11, save=True, | |
# Setup colored output | ||
init() | ||
|
||
if len(directory_out) and (directory_out[0] == '/' or | ||
directory_out[0] == '\\'): | ||
directory_out = directory_out[1:] | ||
if len(directory_out) and (directory_out[-1] == '/' or | ||
directory_out[-1] == '\\'): | ||
directory_out = directory_out[:-1] | ||
|
||
if len(directory) and (directory[0] == '/' or directory[0] == '\\'): | ||
directory = directory[1:] | ||
if len(directory) and (directory[-1] == '/' or directory[-1] == '\\'): | ||
directory = directory[:-1] | ||
|
||
print Fore.WHITE + Style.BRIGHT + Back.MAGENTA + "\nWelcome\n" | ||
print(Fore.WHITE + Style.BRIGHT + Back.MAGENTA + "\nWelcome\n") | ||
|
||
# Figure out where the images are and get all file_names for that directory | ||
target_directory = os.path.join(os.getcwd(), directory) | ||
directory_out = os.path.join(os.getcwd(), directory_out) | ||
print "Searching for images in: " + target_directory | ||
target_directory = directory | ||
print("Searching for images in: " + target_directory) | ||
file_names = os.listdir(target_directory) | ||
print "Found Images:" | ||
print("Found Images:") | ||
for name in file_names: | ||
print "\t" + name | ||
print("\t" + name) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. would be great to at some point change all of these to f-strings, but not critical |
||
|
||
if visualize: | ||
print ("\nYou have enabled visualizations.\n\tEach visualization will " | ||
|
@@ -91,9 +78,9 @@ def calibrate(directory, rows, cols, space, win=11, save=True, | |
|
||
# Check grid symmetry | ||
if rows == cols: | ||
print (Style.BRIGHT + Back.RED + "It is best to use an asymmetric grid," | ||
" rows and cols should be different") | ||
print(Style.RESET_ALL) | ||
print((Style.BRIGHT + Back.RED + "It is best to use an asymmetric grid," | ||
" rows and cols should be different")) | ||
print((Style.RESET_ALL)) | ||
exit() | ||
|
||
# prepare object points, like (0,0,0), (1,0,0), (2,0,0) ....,(6,5,0) | ||
|
@@ -119,12 +106,12 @@ def calibrate(directory, rows, cols, space, win=11, save=True, | |
|
||
# Check if output directory exists, if not, make it. | ||
if save: | ||
print (Style.BRIGHT + Back.MAGENTA + "\nSaving output to: " + | ||
directory_out) | ||
print((Style.BRIGHT + Back.MAGENTA + "\nSaving output to: " + | ||
directory_out)) | ||
if not os.path.exists(directory_out): | ||
os.makedirs(directory_out) | ||
print Style.BRIGHT + Back.GREEN + "\tMade a new output directory" | ||
print "\n" | ||
print(Style.BRIGHT + Back.GREEN + "\tMade a new output directory") | ||
print("\n") | ||
|
||
######################################################################### | ||
image_size = None | ||
|
@@ -136,7 +123,7 @@ def calibrate(directory, rows, cols, space, win=11, save=True, | |
|
||
# If the image_file isn't an image, move on | ||
if img is not None: | ||
print Style.BRIGHT + Back.CYAN + "searching image: " + image_file | ||
print(Style.BRIGHT + Back.CYAN + "searching image: " + image_file) | ||
|
||
if visualize: | ||
cv2.imshow('Raw Image', img) | ||
|
@@ -153,8 +140,8 @@ def calibrate(directory, rows, cols, space, win=11, save=True, | |
|
||
# If we found chessboard corners lets work on them | ||
if re_projection_error: | ||
print (Style.BRIGHT + Back.GREEN + "\tfound " + | ||
("centers" if circles else "corners")) | ||
print((Style.BRIGHT + Back.GREEN + "\tfound " + | ||
("centers" if circles else "corners"))) | ||
object_points.append(object_point) | ||
|
||
# Since this is a good image, we will take its size as the | ||
|
@@ -191,8 +178,8 @@ def calibrate(directory, rows, cols, space, win=11, save=True, | |
corners2 = corners | ||
|
||
image_points.append(corners2) | ||
print (Style.BRIGHT + Back.GREEN + | ||
"\t\tfound sub-pixel corners") | ||
print((Style.BRIGHT + Back.GREEN + | ||
"\t\tfound sub-pixel corners")) | ||
new_color_image = \ | ||
cv2.drawChessboardCorners(color_image, (cols, rows), | ||
corners2, re_projection_error) | ||
|
@@ -210,25 +197,25 @@ def calibrate(directory, rows, cols, space, win=11, save=True, | |
color_image) | ||
cv2.waitKey(5000) | ||
else: | ||
print (Style.BRIGHT + Back.RED + "\tcould not find " + | ||
("Centers" if circles else "Corners")) | ||
print "\n" | ||
print((Style.BRIGHT + Back.RED + "\tcould not find " + | ||
("Centers" if circles else "Corners"))) | ||
print("\n") | ||
|
||
# Check how many good images we found | ||
if number_found >= 10: | ||
print (Style.BRIGHT + Back.GREEN + "Found " + str(number_found) + | ||
" calibratable images.") | ||
print((Style.BRIGHT + Back.GREEN + "Found " + str(number_found) + | ||
" calibratable images.")) | ||
elif number_found == 0: | ||
print (Style.BRIGHT + Back.RED + "Found " + str(number_found) + | ||
" calibratable images. \nNow Exiting") | ||
print(Style.RESET_ALL) | ||
print((Style.BRIGHT + Back.RED + "Found " + str(number_found) + | ||
" calibratable images. \nNow Exiting")) | ||
print((Style.RESET_ALL)) | ||
exit() | ||
else: | ||
print (Style.BRIGHT + Back.YELLOW + "Found " + str(number_found) + | ||
" calibratable images.") | ||
print((Style.BRIGHT + Back.YELLOW + "Found " + str(number_found) + | ||
" calibratable images.")) | ||
|
||
####################################################################### | ||
print Style.BRIGHT + Back.CYAN + "Beginning Calibration" | ||
print(Style.BRIGHT + Back.CYAN + "Beginning Calibration") | ||
|
||
# Execute calibration | ||
(re_projection_error, camera_matrix, distortion_coefficients, | ||
|
@@ -241,7 +228,7 @@ def calibrate(directory, rows, cols, space, win=11, save=True, | |
camera_matrix, distortion_coefficients, (w, h), 1, (w, h)) | ||
|
||
# Go through all images and undistort them | ||
print Style.BRIGHT + Back.CYAN + "Beginning Undistort" | ||
print(Style.BRIGHT + Back.CYAN + "Beginning Undistort") | ||
i = 0 | ||
for image_file in file_names: | ||
image_file = os.path.join(target_directory, image_file) | ||
|
@@ -251,7 +238,7 @@ def calibrate(directory, rows, cols, space, win=11, save=True, | |
|
||
# If the image_file isn't an image, move on | ||
if img is not None: | ||
print Style.BRIGHT + Back.CYAN + "undistorting image: " + image_file | ||
print(Style.BRIGHT + Back.CYAN + "undistorting image: " + image_file) | ||
|
||
if visualize: | ||
cv2.imshow('Raw Image', img) | ||
|
@@ -274,34 +261,34 @@ def calibrate(directory, rows, cols, space, win=11, save=True, | |
i += 1 | ||
|
||
######################################################################### | ||
print "\n" | ||
print Fore.WHITE + Style.BRIGHT + Back.MAGENTA + "Intrinsic Matrix:" | ||
print Fore.WHITE + Style.BRIGHT + Back.MAGENTA + str(camera_matrix) | ||
print "\n" | ||
print Fore.WHITE + Style.BRIGHT + Back.MAGENTA + "Distortion Matrix:" | ||
print (Fore.WHITE + Style.BRIGHT + Back.MAGENTA + | ||
str(distortion_coefficients)) | ||
print "\n" | ||
print Fore.WHITE + Style.BRIGHT + Back.MAGENTA + "Optimal Camera Matrix:" | ||
print Fore.WHITE + Style.BRIGHT + Back.MAGENTA + str(new_camera_matrix) | ||
print "\n" | ||
print (Fore.WHITE + Style.BRIGHT + Back.MAGENTA + | ||
"Optimal Camera Matrix Crop:") | ||
print Fore.WHITE + Style.BRIGHT + Back.MAGENTA + str(roi) | ||
print("\n") | ||
print(Fore.WHITE + Style.BRIGHT + Back.MAGENTA + "Intrinsic Matrix:") | ||
print(Fore.WHITE + Style.BRIGHT + Back.MAGENTA + str(camera_matrix)) | ||
print("\n") | ||
print(Fore.WHITE + Style.BRIGHT + Back.MAGENTA + "Distortion Matrix:") | ||
print((Fore.WHITE + Style.BRIGHT + Back.MAGENTA + | ||
str(distortion_coefficients))) | ||
print("\n") | ||
print(Fore.WHITE + Style.BRIGHT + Back.MAGENTA + "Optimal Camera Matrix:") | ||
print(Fore.WHITE + Style.BRIGHT + Back.MAGENTA + str(new_camera_matrix)) | ||
print("\n") | ||
print((Fore.WHITE + Style.BRIGHT + Back.MAGENTA + | ||
"Optimal Camera Matrix Crop:")) | ||
print(Fore.WHITE + Style.BRIGHT + Back.MAGENTA + str(roi)) | ||
|
||
# Calculate Re-projection Error | ||
tot_error = 0 | ||
for i in xrange(len(object_points)): | ||
for i in range(len(object_points)): | ||
image_points_2, _ = cv2.projectPoints( | ||
object_points[i], rotation_vectors[i], translation_vectors[i], | ||
camera_matrix, distortion_coefficients) | ||
error = cv2.norm(image_points[i], image_points_2, | ||
cv2.NORM_L2) / len(image_points_2) | ||
tot_error += error | ||
mean_error = tot_error / len(object_points) | ||
print "\n" | ||
print (Fore.WHITE + Style.BRIGHT + Back.MAGENTA + "Re-projection Error: " + | ||
str(mean_error)) | ||
print("\n") | ||
print((Fore.WHITE + Style.BRIGHT + Back.MAGENTA + "Re-projection Error: " + | ||
str(mean_error))) | ||
|
||
if save: | ||
with open(os.path.join(directory_out, 'result.txt'), 'w') as \ | ||
|
@@ -337,5 +324,5 @@ def calibrate(directory, rows, cols, space, win=11, save=True, | |
result_json_file: | ||
json.dump(json_dict, result_json_file, indent=4) | ||
|
||
print(Style.RESET_ALL) | ||
print((Style.RESET_ALL)) | ||
cv2.destroyAllWindows() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should sanitize with expand user