diff --git a/src/helpers/template_extraction/input/template.jpg b/src/helpers/template_extraction/input/template.jpg new file mode 100644 index 0000000..73242ca Binary files /dev/null and b/src/helpers/template_extraction/input/template.jpg differ diff --git a/src/helpers/template_extraction/script.py b/src/helpers/template_extraction/script.py new file mode 100644 index 0000000..d839035 --- /dev/null +++ b/src/helpers/template_extraction/script.py @@ -0,0 +1,54 @@ +import cv2 +import numpy as np +import sys +import os + + +#python template.py input_folder output_folder +try: + input_folder = sys.argv[1] +except: + print("Need an input folder") + exit() + +try: + output_folder = sys.argv[2] +except: + print("Need an output folder") + exit() + +if(not os.path.isdir(input_folder)): + print("Input folder not found") + exit() + +if(not os.path.isdir(output_folder)): + print("Output folder not found") + exit() + +# Aruco params +detector_params = cv2.aruco.DetectorParameters() +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 + 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.waitKey(0) +cv2.destroyAllWindows \ No newline at end of file