2 回答

TA貢獻1869條經驗 獲得超4個贊
當您嘗試反轉框上的調整大小操作時,您除以rhandrw但您永遠不會乘以hand w。
z[:, 0] = h * z[:, 0] / rh
z[:, 1] = w * z[:, 1] / rw
這解釋了為什么您的錯誤會隨著更大的圖像而變大。
作為旁注,您可以使用 numpy 索引來避免每行重復四次:
z[:, 0::2] = h * z[:, 0::2] / rh
z[:, 1::2] = w * z[:, 1::2] / rw

TA貢獻1846條經驗 獲得超7個贊
我必須轉換坐標而不是我正在處理的像素。
坐標,而不是像素....
def transform_boxes(boxes: np.ndarray, im):
"""
Transform back the original coordinate
:param boxes:
:param im: The original image
:return:
"""
z = np.copy(boxes)
(height, width, colors) = im.shape
new_h, new_w, img_size = get_float_new_wh(im)
z[:, 0::2] = height * z[:, 0::2] / new_h
z[:, 1::2] = width * z[:, 1::2] / new_w
return z
def get_new_wh(img):
"""
Get only new width and new height
:param img:
:return:
"""
new_h, new_w, img_size = get_float_new_wh(img)
new_h = int(new_h)
new_w = int(new_w)
new_h = new_h if new_h // 16 == 0 else (new_h // 16 + 1) * 16
new_w = new_w if new_w // 16 == 0 else (new_w // 16 + 1) * 16
return new_h, new_w, img_size
添加回答
舉報