我在 Windows 10 中作業,使用 Python 3.8 和 OpenCV 4.5,并創建一個人工資料集來訓練卷積神經網路。在一個步驟中,我需要翻譯一個contour結構,但我被這個問題困住了,我無法解決。
我需要翻譯contour byx_offset和y_offset。但我對np.arrayOpenCV 的型別和組織方式感到困惑contours。
我在 OpenCV 檔案(
當我列印contours時,我得到這個結果:
[array([[[207, 146]],
[[207, 455]],
[[603, 455]],
[[603, 146]]], dtype=int32)]
我試圖保持結構,但使用x_offsetand重新映射點y_offset,所以我的結果應該是這樣的:
[array([[[207 x_offset, 146 y_offset]],
[[207 x_offset, 455 y_offset]],
[[603 x_offset, 455 y_offset]],
[[603 x_offset, 146 y_offset]]], dtype=int32)]

有人可以在不丟失結構的情況下幫助演算法執行此操作contour嗎?所以我可以用drawContours這個翻譯來畫contour。
uj5u.com熱心網友回復:
您只需將 X 和 Y 偏移量作為元組添加到每個輪廓:
x_offset, y_offset = 5, 3
for contour in contours:
# contour with new offset is created
new_contour = contour (x_offset, y_offset)
# draw the new contour on the image
cv2.drawContours(im,new_contour,-1,(0,255,0),3)
我猜你的資料結構contours讓你感到困惑。contours是一個元組。每個標識的輪廓都存盤為一個單獨的元組。每個輪廓的點都存盤在這些元組中。
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/490883.html
