簡體   English   中英

繪制一個帶有 x,y 底部和頂部坐標的矩形

[英]Draw a rectangle with x,y bottom and top coordinates

我的坐標定義為:

tl = (result['topleft']['x'], result['topleft']['y'])
br = (result['bottomright']['x'], result['bottomright']['y'])

我想使用 OpenCv 在感興趣的對象周圍繪制一個矩形; 我試過:

cv2.rectangle(img, (tl[0], tl[1]), ( tl[0]-br[1], tl[1]-br[0] ), (255, 0, 0), 2)

但它不包括對象。 我該如何解決?

您以錯誤的格式調用cv2.rectangle() 它應該是

cv2.rectangle(img, tl, br, (255, 0, 0), 2)

這是文檔所說的:

cv.Rectangle(img, pt1, pt2, color, thickness=1, lineType=8, shift=0) 

其中pt1pt2應該是相反的頂點坐標。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM