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