From ff5f0ba151b941b2b166f2b7689662049ae795d5 Mon Sep 17 00:00:00 2001 From: Tom Selier Date: Thu, 14 Sep 2023 17:06:21 +0200 Subject: [PATCH] added basic cropping --- src/helpers/template_extraction/script.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/helpers/template_extraction/script.py b/src/helpers/template_extraction/script.py index 9f0ebd6..aaa8cf1 100644 --- a/src/helpers/template_extraction/script.py +++ b/src/helpers/template_extraction/script.py @@ -40,7 +40,7 @@ for file in os.listdir(input_folder): filename = input_folder + '/' + file out_filename = output_folder + '/' + file img = cv2.imread(filename, 0) - small_img = cv2.resize(img, (400, 400)) + small_img = cv2.resize(img, (750, 750)) (corners, ids, rejected) = detector.detectMarkers(small_img) new_image = cv2.aruco.drawDetectedMarkers( small_img, @@ -73,12 +73,18 @@ for file in os.listdir(input_folder): print("x[%d]: %d"%(i, x[i])) print("y[%d]: %d"%(i, y[i])) print() - i += 1 + offset = 20 + crop_img = new_image[ + np.min(x+offset):np.max(x-offset), + np.min(y+offset):np.max(y-offset) + ] + print("imshape[0]: " + str(small_img.shape[0])) print("imshape[1]: " + str(small_img.shape[1])) cv2.imshow('window', new_image) + cv2.imshow('cropped', crop_img) # cv2.imwrite(out_filename, new_image) cv2.waitKey(0)