我将kinectv2与YOLO2一起使用。我想提取边界框的中心(x,y)位置,以便将位置转移到深度框,然后将对象的距离添加到边界框标签。
现在,我具有边界框的左上角和右下角x,y坐标的位置,但是我不想那样做。
如何提取边界框的中心(x,y)。它不应该在“ tfnet.return_predict()”中吗?
此处代码:
colors = [tuple(255 * np.random.rand(3)) for _ in range(10)]
kinect = PyKinectRuntime.PyKinectRuntime(PyKinectV2.FrameSourceTypes_Color)
while True:
stime = time.time()
if kinect.has_new_color_frame():
frame = kinect.get_last_color_frame()
frame = np.reshape(frame, (1080, 1920, 4))
frame = cv2.cvtColor(frame, cv2.COLOR_RGBA2RGB)
frame = cv2.resize(frame, (0, 0), fx=0.5, fy=0.5)
results = tfnet.return_predict(frame)
for color, result in zip(colors, results):
tl = (result['topleft']['x'], result['topleft']['y'])
#cnt = (result['x'], result['y'])
br = (result['bottomright']['x'], result['bottomright']['y'])
label = result['label']
confidence = result['confidence']
text = '{}: {:.0f}%'.format(label, confidence * 100)
frame = cv2.rectangle(frame, tl, br, color, 5)
frame = cv2.putText(
frame, text, tl, cv2.FONT_HERSHEY_COMPLEX, 1, (0, 0, 0), 2)
cv2.imshow('frame', frame)
frame = None
#print('FPS {:.1f}'.format(1 / (time.time() - stime)))
print(tl)
if cv2.waitKey(1) & 0xFF == ord('q'):
break