first commit

This commit is contained in:
Rusty Striker 2024-01-12 14:10:37 +02:00
commit 1011c7b5e9
Signed by: RustyStriker
GPG Key ID: 9DBDBC7C48FC3C31
1 changed files with 18 additions and 0 deletions

18
classify.py Normal file
View File

@ -0,0 +1,18 @@
import cv2 as cv
import numpy as np
import h5py as h5
# Extract letter from a bounding box
def extract_bb(img, bb):
# Get the bounding box
rect = cv.minAreaRect(bb.astype(np.float32).transpose())
# will be useful later, map center and size to ints
center, size = tuple(map(int, rect[0])), tuple(map(int, rect[1]))
# Calculate rotation matrix and rotate the image
rot_matrix = cv.getRotationMatrix2D(center, rect[2], 1)
rot_img = cv.warpAffine(img, rot_matrix, (img.shape[1], img.shape[0]))
# bounding box is now axis aligned, and we can crop it
print(size)
cropped = cv.getRectSubPix(rot_img, size, center)
return cropped