对图片坐标进行线性映射


import cv2

path = "obama2.jpg"

img = cv2.imread(path)
y, x, c_1 = (list(img.shape))
print(x, ",", y, ",", c_1)
img = cv2.resize(img, (224, 224))
y_hat,x_hat, c_2 = (list(img.shape))
print(x_hat, ",", y_hat, ",", c_2)

# cv2.imwrite('obm.jpg', img)

def Change_lable(m,n,x,y,x_hat,y_hat):
m_hat = (m/x) * x_hat
n_hat = (n/y) * y_hat
return m_hat,n_hat
new_m,new_n = Change_lable(137,445,x,y,x_hat,y_hat)
print(new_m,",",new_n)
def Restore_lable(m_hat,n_hat,x,y,x_hat,y_hat):
m = m_hat*x/x_hat
n = n_hat*y/y_hat
return m,n
pre_m,pre_n = Restore_lable(new_m,new_n,x,y,x_hat,y_hat)
print(pre_m,",",pre_n)
结果:

626 , 1200 , 3
224 , 224 , 3
49.0223642172524 , 83.06666666666666
137.00000000000003 , 445.0

原图:↑

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值