-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFrame.py
More file actions
50 lines (38 loc) · 1.82 KB
/
Frame.py
File metadata and controls
50 lines (38 loc) · 1.82 KB
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
PARTITION_NUM = 4
import cv2
import math
from Fragment import Fragment
from FragmentProcessor import FragmentProcessor
class Frame:
""" A Frame holds a raw and processed image capture
Attributes:
height (int): Frame height.
width (int): Frame width.
image (np.ndarry): Raw image capture.
fragments (list[Fragment]): Partitioned and processed fragments.
processedFrame (np.ndarry): Consolidated and processed fragments.
"""
def __init__(self, image):
""" Inits Frame
Args:
image (np.ndarry): Image capture received from Video Camera.
"""
if (image.shape[0] != 480 and image.shape[1] != 640):
raise Exception(str(image.shape[0]) + "x" + str(image.shape[1]) + " is not 480x640")
self.height = image.shape[0]
self.width = image.shape[1]
self.image = image
self.fragments = FragmentProcessor.partition(image)
self.processedFrame = FragmentProcessor.consolidate(self.fragments)
def calculateVariation(self):
""" Calculate variation between expected center point and skewed point.
"""
# Tentative/Placeholder algorithm
# Obtain top-most and bottom-most center points
top = self.fragments[0]
bottom = self.fragments[PARTITION_NUM - 1]
# Draw line between expected center point (top) and skewed point (bottom)
cv2.line(self.processedFrame, (top.relativeContourCtrX, top.relativeContourCtrY), (bottom.relativeImageCtrX, bottom.relativeImageCtrY), (255, 0, 0), 2)
# Calculate variation (distance away from center)
currentError = (-1) * int(math.degrees(math.atan((top.relativeContourCtrX - bottom.relativeImageCtrX) / (top.relativeContourCtrY- bottom.relativeImageCtrY))))
return currentError