像素间的计算机视觉距离

问题描述 投票:0回答:1

大家好,我需要帮助寻找图像中两个像素之间的像素数的距离(有坐标)thanks in advance。

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)``
python opencv
1个回答
1
投票

我使用这个函数来计算距离。

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

0
投票

或者你也可以用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)
© www.soinside.com 2019 - 2024. All rights reserved.