我希望我能解釋我的問題。我有一個來自英特爾實感攝像頭的視頻,其中包含深度資訊。每當我的相機和地板之間的距離低于某個值時,我都需要繪制一個矩形。我的問題是視頻是在回圈中逐幀處理的。我撰寫了一個 if 陳述句,它在正確的時刻繪制矩形,但如果下一幀到來并且 if 陳述句不再填充,我的 recangle 就會消失。我知道為什么(當然;))但是我怎樣才能永遠“修復”我的矩形在那個位置。所以最后我想有很多recangles。這里有足夠多的矩形是我的代碼:非常感謝<3
while True:
frames = pipeline.wait_for_frames()
#Depth_Stream
depth_frame = frames.get_depth_frame()
#depth_color_frame = rs.colorizer().colorize(depth_frame) #Stream Einf?rben
depth_color_frame = depth_frame
depth_color_image = np.asanyarray(depth_color_frame.get_data()) #Erstellen Numpy Array
cv2.circle(depth_color_image,(x_Koordinate, y_Koordinate), 10, (0,0,255), 1) #Kreis zeichnen
cv2.imshow("Depth Stream", depth_color_image)
#array_ausgabe.write(np.array_str(depth_color_image)) #Export RGB-Werte für jedes Pixel
#numpy.savetxt('test.out', depth_color_image, )
#RGB_Stream
rgb_frame = frames.get_color_frame()
rgb_color_image = np.asanyarray(rgb_frame.get_data())
cv2.circle(rgb_color_image,(x_Koordinate,y_Koordinate), 10, (0,0,255), 1) #Kreis zeichnen
hight_over_table = korrigierter_abstand_zur_Kamera(x_Koordinate, y_Koordinate) - Abstand_zum_Tisch
if hight_over_table > 0:
cv2.rectangle(rgb_color_image,(x1_bounding_box,y1_bounding_box),(x2_bounding_box,y2_bounding_box),(0,255,0),3)
else: print("test")
cv2.imshow("RGB Stream", rgb_color_image)
key = cv2.waitKey(1)
if key == 27:
#cv2.destroyAllWindows()
break
uj5u.com熱心網友回復:
這似乎是您所要求的,但它可能不會按您的意愿行事。
在 while 回圈的上方創建一個串列。還添加一個布爾變數(可選 - 見下文)
rectangles = []
detected = False
while True:
當距離足夠小時,將矩形的坐標添加到串列中 - 使用元組。使用該detected變數可防止在每一幀的同一位置添加一個矩形。僅在第一幀上添加一個矩形,某些內容在范圍內。如果您打算在螢屏上跟蹤某些內容,請洗掉該代碼。
if hight_over_table > 0:
if not detected:
detected = True
rectangles.append(((x1_bounding_box,y1_bounding_box),(x2_bounding_box,y2_bounding_box)))
else:
detected = False
print("test")
每一幀,在顯示影像之前繪制所有矩形
for p1, p2 in rectangles:
cv2.rectangle(rgb_color_image,p1,p2,(0,255,0),3)
cv2.imshow("RGB Stream", rgb_color_image)
請注意,矩形被繪制到螢屏上,而不是表面上。如果您將相機指向天空,矩形仍然會存在。在技術上可以將矩形粘貼到表面上,但這要復雜得多。
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/420206.html
標籤:
