36 min_detection_confidence = 0.5
37 min_tracking_confidence = 0.99
46 static_image_mode =
False,
47 max_num_objects = max_num_objects,
48 min_detection_confidence = min_detection_confidence,
49 min_tracking_confidence = min_tracking_confidence,
56 idle, winw, winh = helper.startFrame()
59 x, y, w, h = helper.drawInputFrame(
"c", inframe,
False,
False)
60 helper.itext(
'JeVois-Pro 3D Object Detection', 0, -1)
61 helper.itext(
'Detecting: ' + self.
model_name +
' - edit source code to change')
64 image = inframe.getCvRGBp()
65 iw, ih = image.shape[1], image.shape[0]
74 if results.detected_objects
is not None:
75 for detected_object
in results.detected_objects:
77 self.
draw_axis(helper, iw, ih, detected_object.rotation, detected_object.translation, 0.1)
80 fps = self.
timer.stop()
81 helper.iinfo(inframe, fps, winw, winh);
90 idx_to_coordinates = {}
92 for index, landmark
in enumerate(landmarks.landmark):
93 lm = helper.i2d(landmark.x * iw, landmark.y * ih,
"c")
94 helper.drawCircle(lm.x, lm.y, 5, col,
True)
95 idx_to_coordinates[index] = lm
101 num_landmarks = len(landmarks.landmark)
102 for connection
in connections:
103 start_idx = connection[0]
104 end_idx = connection[1]
105 if not (0 <= start_idx < num_landmarks
and 0 <= end_idx < num_landmarks):
106 raise ValueError(f
'Landmark index is out of range. Invalid connection '
107 f
'from landmark #{start_idx} to landmark #{end_idx}.')
108 if start_idx
in idx_to_coordinates
and end_idx
in idx_to_coordinates:
109 helper.drawLine(idx_to_coordinates[start_idx].x, idx_to_coordinates[start_idx].y,
110 idx_to_coordinates[end_idx].x, idx_to_coordinates[end_idx].y, col)
113 def draw_axis(self, helper, iw, ih, rotation, translation, axis_length):
114 focal_length = (1.0, 1.0)
115 principal_point = (0.0, 0.0)
116 axis_world = np.float32([[0, 0, 0], [1, 0, 0], [0, 1, 0], [0, 0, 1]])
117 axis_cam = np.matmul(rotation, axis_length * axis_world.T).T + translation
123 fx, fy = focal_length
124 px, py = principal_point
125 x_ndc = np.clip(-fx * x / (z + 1e-5) + px, -1., 1.)
126 y_ndc = np.clip(-fy * y / (z + 1e-5) + py, -1., 1.)
129 x_im = (1 + x_ndc) * 0.5 * iw
130 y_im = (1 - y_ndc) * 0.5 * ih
133 orig = helper.i2d(x_im[0], y_im[0],
"c")
134 xa = helper.i2d(x_im[1], y_im[1],
"c")
135 ya = helper.i2d(x_im[2], y_im[2],
"c")
136 za = helper.i2d(x_im[3], y_im[3],
"c")
137 helper.drawLine(orig.x, orig.y, xa.x, xa.y, 0xff0000ff)
138 helper.drawLine(orig.x, orig.y, ya.x, ya.y, 0xff00ff00)
139 helper.drawLine(orig.x, orig.y, za.x, za.y, 0xffff0000)