Skip to content

Commit 7c7458e

Browse files
committed
Fixes Progress definition missing from Schema
1 parent f3cfb31 commit 7c7458e

File tree

5 files changed

+49
-35
lines changed

5 files changed

+49
-35
lines changed

V3Schema

three/MF/V3/Tasks/DetectCalibrationCard.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33

44
class DetectCalibrationCard:
55
"""*
6-
Detect the calibration card on one or both cameras.
6+
Turns on the detection the calibration card on one or both cameras.
7+
Use the Video Frame Descriptor to get the results of the detection.
78
89
> Request example:
910
@@ -41,7 +42,7 @@ def __init__(self, Index: int, Type: str, Input: int):
4142
# "DetectCalibrationCard"
4243
self.Type = Type
4344
"""
44-
Flag specifying on which camera(s) to detect the calibration card.
45+
Flag specifying on which camera(s) to start the detection the calibration card.
4546
[0: neither camera (disable), 1: left camera, 2: right camera, 3: both cameras]
4647
"""
4748
self.Input = Input
@@ -57,7 +58,7 @@ def __init__(self, Index: int, Type: str, Input: int, State: MF_V3_Task_TaskStat
5758
# "DetectCalibrationCard"
5859
self.Type = Type
5960
"""
60-
Flag sent in the request specifying on which camera(s) to detect the calibration card.
61+
Flag sent in the request specifying on which camera(s) to start the detection the calibration card.
6162
[0: neither camera (disable), 1: left camera, 2: right camera, 3: both cameras]
6263
"""
6364
self.Input = Input

three/_scanner.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -217,11 +217,11 @@ def __OnMessage(self, ws, message) -> None:
217217
# Extract the first (and only) item from the task.Progress dictionary
218218
# TODO Duct tape fix due to schema weirdness for progress
219219
key, process = next(iter(task.Progress.items()))
220-
task.Progress = Task.Progress(
221-
current=process["current"],
222-
step=process["step"],
223-
total=process["total"]
224-
)
220+
task.Progress = type('Progress', (object,), {
221+
'current': process["current"],
222+
'step': process["step"],
223+
'total': process["total"]
224+
})()
225225

226226
# Find the original task for reference
227227
inputTask = self.__FindTaskWithIndex(task.Index)

three/examples/turntableCalibration.py

Lines changed: 34 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ def OnTask(task:Task):
3232
done = True
3333
elif task.Type == "DetectCalibrationCard":
3434
if task.State == "Completed":
35-
print('Calibration Card Detected')
35+
print('Calibration Card Detection Started')
3636
elif task.State == "Failed":
3737
print('Calibration Card Detection Failed:', task.Error)
3838
done = True
@@ -51,15 +51,24 @@ def OnBuffer(bufferObject, buffer:bytes):
5151
if cornersTotal == 0:
5252
cardWidth = calibrationCard.size[0]
5353
cardHeight = calibrationCard.size[1]
54-
cornersTotal = (cardWidth - 1) * (cardHeight - 1)
54+
if cardWidth == 0 or cardHeight == 0:
55+
return;
56+
cornersTotal = int((cardWidth - 1) * (cardHeight - 1))
5557

56-
detectedCorners = int(len(calibrationCard.corners) / 2)
57-
# Camera 0
58-
if bufferObject.Index == 0:
59-
cornersDetected_0 = detectedCorners
60-
# Camera 1
58+
if calibrationCard.corners is not None:
59+
detectedCorners = calibrationCard.corners
60+
detectedCorners = int(len(detectedCorners) / 2)
61+
# Camera 0
62+
if bufferObject.Index == 0:
63+
cornersDetected_0 = detectedCorners
64+
# Camera 1
65+
else:
66+
cornersDetected_1 = detectedCorners
6167
else:
62-
cornersDetected_1 = detectedCorners
68+
if bufferObject.Index == 0:
69+
cornersDetected_0 = 0
70+
else:
71+
cornersDetected_1 = 0
6372

6473
# No calibration card in the descriptor
6574
else:
@@ -74,23 +83,27 @@ def OnBuffer(bufferObject, buffer:bytes):
7483
scanner = Scanner(OnTask=OnTask, OnMessage=None, OnBuffer=OnBuffer)
7584
scanner.Connect("ws://matterandform.local:8081")
7685

77-
# Start the video
78-
scanner.start_video()
86+
# # Start the video
87+
# scanner.start_video()
7988

80-
# Detect the calibration card
81-
print('******* Detecting the calibration card')
82-
scanner.detect_calibration_card(3) # left camera only, 2 = Right camera only, 3 = Both cameras
89+
# # Detect the calibration card
90+
# print('******* Detecting the calibration card')
91+
# scanner.detect_calibration_card(3) # left camera only, 2 = Right camera only, 3 = Both cameras
8392

84-
# Wait for the calibration card to be detected
85-
while cornersTotal == 0:
86-
time.sleep(0.1)
93+
# # Wait for the calibration card to be detected
94+
# print('Waiting for the calibration card to be detected')
95+
# timeout = time.time() + 10 # 10 seconds from now
96+
# while cornersTotal == 0 and time.time() < timeout:
97+
# time.sleep(0.1)
98+
# if cornersTotal == 0:
99+
# print("Timeout: Calibration card not detected within 10 seconds")
87100

88-
# Detect the calibration card for 5sec
89-
time.sleep(5)
101+
# # Detect the calibration card for 5sec
102+
# time.sleep(5)
90103

91-
# Stop the video
92-
scanner.detect_calibration_card(0) # Stop the detection
93-
scanner.stop_video()
104+
# # Stop the video
105+
# scanner.detect_calibration_card(0) # Stop the detection
106+
# scanner.stop_video()
94107

95108
# Calibration the turntable
96109
print('\n******* Calibrating the turntable')

three/scanner.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -244,11 +244,11 @@ def __OnMessage(self, ws, message) -> None:
244244
# Extract the first (and only) item from the task.Progress dictionary
245245
# TODO Duct tape fix due to schema weirdness for progress
246246
key, process = next(iter(task.Progress.items()))
247-
task.Progress = Task.Progress(
248-
current=process["current"],
249-
step=process["step"],
250-
total=process["total"]
251-
)
247+
task.Progress = type('Progress', (object,), {
248+
'current': process["current"],
249+
'step': process["step"],
250+
'total': process["total"]
251+
})()
252252

253253
# Find the original task for reference
254254
inputTask = self.__FindTaskWithIndex(task.Index)

0 commit comments

Comments
 (0)