zoukankan      html  css  js  c++  java
  • 对图片坐标进行线性映射


    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

    原图:↑

  • 相关阅读:
    spring mvc 分页
    get/post时中文乱码问题的解决办法
    mysql-day01
    servler配置
    idea
    springMvc 核心配置
    ServletRequest面试题
    Servlet面试题
    Http面试题
    测试文件
  • 原文地址:https://www.cnblogs.com/ansang/p/8624158.html
Copyright © 2011-2022 走看看