Added template extractor

This commit is contained in:
Tom Selier 2023-09-14 09:33:57 +02:00
parent 9a24c5ab70
commit 6373a5220c
2 changed files with 54 additions and 0 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.2 MiB

View File

@ -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