[英]computer vision distance btw pixels
大家好,我需要幫助來查找圖像中兩個像素(帶坐標)之間的像素數距離,在此先感謝
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)``
我用這個 function 來計算距離:
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])
Output:
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)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.