MCPcopy Index your code
hub / github.com/Turing-Project/WriteGPT / dumpRotateImage

Function dumpRotateImage

RecognizaitonNetwork/ocr.py:22–38  ·  view source on GitHub ↗
(img, degree, pt1, pt2, pt3, pt4)

Source from the content-addressed store, hash-verified

20 return box
21
22def dumpRotateImage(img, degree, pt1, pt2, pt3, pt4):
23 height, width = img.shape[:2]
24 heightNew = int(width * fabs(sin(radians(degree))) + height * fabs(cos(radians(degree))))
25 widthNew = int(height * fabs(sin(radians(degree))) + width * fabs(cos(radians(degree))))
26 matRotation = cv2.getRotationMatrix2D((width // 2, height // 2), degree, 1)
27 matRotation[0, 2] += (widthNew - width) // 2
28 matRotation[1, 2] += (heightNew - height) // 2
29 imgRotation = cv2.warpAffine(img, matRotation, (widthNew, heightNew), borderValue=(255, 255, 255))
30 pt1 = list(pt1)
31 pt3 = list(pt3)
32
33 [[pt1[0]], [pt1[1]]] = np.dot(matRotation, np.array([[pt1[0]], [pt1[1]], [1]]))
34 [[pt3[0]], [pt3[1]]] = np.dot(matRotation, np.array([[pt3[0]], [pt3[1]], [1]]))
35 ydim, xdim = imgRotation.shape[:2]
36 imgOut = imgRotation[max(1, int(pt1[1])) : min(ydim - 1, int(pt3[1])), max(1, int(pt1[0])) : min(xdim - 1, int(pt3[0]))]
37
38 return imgOut
39
40def charRec(img, text_recs, adjust=False):
41 """

Callers 1

charRecFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected