first commit
This commit is contained in:
commit
1011c7b5e9
1 changed files with 18 additions and 0 deletions
18
classify.py
Normal file
18
classify.py
Normal 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
|
||||
|
Loading…
Reference in a new issue