Python 计算机视觉距离btw像素

Python 计算机视觉距离btw像素,python,opencv,Python,Opencv,大家好,我需要帮助找到图像中两个像素(带坐标)之间的像素数距离 提前谢谢 import math import numpy as np import matplotlib.pyplot as plt from math import sqrt from PIL import Image, ImageOps %matplotlib inline`` `` img = cv.imread('building.jpg',-1) cv.imshow('image',img) # to display

大家好,我需要帮助找到图像中两个像素(带坐标)之间的像素数距离 提前谢谢

import math
import numpy as np
import matplotlib.pyplot as plt
from math import sqrt
from PIL import Image, ImageOps
%matplotlib inline``
``
img = cv.imread('building.jpg',-1)
cv.imshow('image',img)
 # to display image until you press any key
cv.waitKey(0)
 # to destroy all windows
cv.destroyAllWindows()
pixels = np.array(img)
width, height, channels = pixels.shape
print(width)
print (height)
P=img[200,510]
print (P)
Q=img[100,410]
print (Q)``

我已使用此函数计算距离:

def distance(x1, y1, x2, y2):
    return ((x2-x1)**2+(y2-y1)**2)**(1/2)

point1 = (200, 510)
point2 = (100, 410)

distance(point1[0], point1[1],
         point2[0], point2[1])
输出:

141.4213562373095

或者,您可以使用scipy完成此任务

from scipy.spatial.distance import euclidean
pt1 = (100, 100)
pt2 = (200, 200)
dist = euclidean (pt1, pt2)
# if want in int then use 
#dist = int(dist)

谢谢您的帮助,但它是以像素数表示的吗?即对角线上的像素数,如果您将其转换为整数,您可以将答案作为解决方案吗?;)对不起,我不能理解你问题的意思。请考虑简化示例(似乎没有必要导入
import
etc.)。如果这两点是你想要测量的,为什么不使用毕达哥拉斯定理呢<代码>数学sqrt(100*100+100*100)