Added template extractor
This commit is contained in:
parent
9a24c5ab70
commit
6373a5220c
BIN
src/helpers/template_extraction/input/template.jpg
Normal file
BIN
src/helpers/template_extraction/input/template.jpg
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.2 MiB |
54
src/helpers/template_extraction/script.py
Normal file
54
src/helpers/template_extraction/script.py
Normal 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
|
Loading…
Reference in New Issue
Block a user