-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathPossibleChar.py
36 lines (20 loc) · 1.29 KB
/
PossibleChar.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# PossibleChar.py
import cv2
import numpy as np
import math
###################################################################################################
class PossibleChar:
# constructor #################################################################################
def __init__(self, _contour):
self.contour = _contour
self.boundingRect = cv2.boundingRect(self.contour) # It gives the (x,y,w,h) of a straight rectangle that bounds the contour. It is not sensetive to the rotation of the obejct ,so its area will not be minimum.
[intX, intY, intWidth, intHeight] = self.boundingRect
self.intBoundingRectX = intX
self.intBoundingRectY = intY
self.intBoundingRectWidth = intWidth
self.intBoundingRectHeight = intHeight
self.intBoundingRectArea = self.intBoundingRectWidth * self.intBoundingRectHeight
self.intCenterX = (self.intBoundingRectX + self.intBoundingRectX + self.intBoundingRectWidth) / 2
self.intCenterY = (self.intBoundingRectY + self.intBoundingRectY + self.intBoundingRectHeight) / 2
self.fltDiagonalSize = math.sqrt((self.intBoundingRectWidth ** 2) + (self.intBoundingRectHeight ** 2))
self.fltAspectRatio = float(self.intBoundingRectWidth) / float(self.intBoundingRectHeight)