Cleaned up arg handling

This commit is contained in:
Tom Selier 2023-09-14 09:49:07 +02:00
parent 6373a5220c
commit db5cb1f31c
2 changed files with 9 additions and 21 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 32 KiB

View File

@ -3,19 +3,14 @@ import numpy as np
import sys import sys
import os import os
# command:
# python template.py input_folder output_folder
#python template.py input_folder output_folder if(len(sys.argv) != 3):
try: print("Wrong amount of arguments")
input_folder = sys.argv[1]
except:
print("Need an input folder")
exit()
try: input_folder = sys.argv[1]
output_folder = sys.argv[2] output_folder = sys.argv[2]
except:
print("Need an output folder")
exit()
if(not os.path.isdir(input_folder)): if(not os.path.isdir(input_folder)):
print("Input folder not found") print("Input folder not found")
@ -27,28 +22,21 @@ if(not os.path.isdir(output_folder)):
# Aruco params # Aruco params
detector_params = cv2.aruco.DetectorParameters() detector_params = cv2.aruco.DetectorParameters()
dictionary = cv2.aruco.getPredefinedDictionary( dictionary = cv2.aruco.getPredefinedDictionary(cv2.aruco.DICT_ARUCO_ORIGINAL)
cv2.aruco.DICT_ARUCO_ORIGINAL)
detector = cv2.aruco.ArucoDetector(dictionary, detector_params) detector = cv2.aruco.ArucoDetector(dictionary, detector_params)
ids = np.zeros(10)
corners = np.zeros(40)
for file in os.listdir(input_folder): for file in os.listdir(input_folder):
filename = input_folder + '/' + file filename = input_folder + '/' + file
out_filename = output_folder + '/' + file out_filename = output_folder + '/' + file
img = cv2.imread(filename, 0) # open img img = cv2.imread(filename, 0)
small_img = cv2.resize(img, (400, 400)) small_img = cv2.resize(img, (400, 400))
#corners, ids, rejected
(corners, ids, rejected) = detector.detectMarkers(small_img) (corners, ids, rejected) = detector.detectMarkers(small_img)
new_image = cv2.aruco.drawDetectedMarkers( new_image = cv2.aruco.drawDetectedMarkers(
small_img, small_img,
corners, corners,
ids) ids)
cv2.imshow('window', new_image) cv2.imshow('window', new_image)
# cv2.imwrite(out_filename, img) # save img cv2.imwrite(out_filename, new_image)
cv2.waitKey(0) cv2.waitKey(0)
cv2.destroyAllWindows cv2.destroyAllWindows