Spaces:
Runtime error
Runtime error
File size: 707 Bytes
ac1c6ae 53f6094 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
import numpy as np
import cv2
def pil_cv2_image_converter(image):
numpy_image = np.array(image)
# Convert to an OpenCV image; notice the COLOR_RGB2BGR flag, which means
# that the color is converted from RGB to BGR format.
opencv_image = cv2.cvtColor(numpy_image, cv2.COLOR_RGB2BGR)
return opencv_image
def chi2_distance(histA, histB, eps = 1e-10):
# compute the chi-squared distance
d = 0.5 * np.sum([((a - b) ** 2) / (a + b + eps)
for (a, b) in zip(histA, histB)])
# return the chi-squared distance
return d
def euclidean_distance(x, y):
# compute the Euclidean distance
d = np.sqrt(np.sum((x - y) ** 2))
# return the Euclidean distance
return d
|