1
0
mirror of https://github.com/opencv/opencv.git synced 2026-07-29 15:23:05 +04:00

python: 'cv2.' -> 'cv.' via 'import cv2 as cv'

This commit is contained in:
Alexander Alekhin
2017-12-11 12:55:03 +03:00
parent 9665dde678
commit 5560db73bf
162 changed files with 2083 additions and 2084 deletions
+9 -9
View File
@@ -10,7 +10,7 @@ if PY3:
import numpy as np
from numpy import random
import cv2
import cv2 as cv
def make_gaussians(cluster_n, img_size):
points = []
@@ -28,10 +28,10 @@ def make_gaussians(cluster_n, img_size):
def draw_gaussain(img, mean, cov, color):
x, y = np.int32(mean)
w, u, _vt = cv2.SVDecomp(cov)
w, u, _vt = cv.SVDecomp(cov)
ang = np.arctan2(u[1, 0], u[0, 0])*(180/np.pi)
s1, s2 = np.sqrt(w)*3.0
cv2.ellipse(img, (x, y), (s1, s2), ang, 0, 360, color, 1, cv2.LINE_AA)
cv.ellipse(img, (x, y), (s1, s2), ang, 0, 360, color, 1, cv.LINE_AA)
if __name__ == '__main__':
@@ -45,9 +45,9 @@ if __name__ == '__main__':
points, ref_distrs = make_gaussians(cluster_n, img_size)
print('EM (opencv) ...')
em = cv2.ml.EM_create()
em = cv.ml.EM_create()
em.setClustersNumber(cluster_n)
em.setCovarianceMatrixType(cv2.ml.EM_COV_MAT_GENERIC)
em.setCovarianceMatrixType(cv.ml.EM_COV_MAT_GENERIC)
em.trainEM(points)
means = em.getMeans()
covs = em.getCovs() # Known bug: https://github.com/opencv/opencv/pull/4232
@@ -56,14 +56,14 @@ if __name__ == '__main__':
img = np.zeros((img_size, img_size, 3), np.uint8)
for x, y in np.int32(points):
cv2.circle(img, (x, y), 1, (255, 255, 255), -1)
cv.circle(img, (x, y), 1, (255, 255, 255), -1)
for m, cov in ref_distrs:
draw_gaussain(img, m, cov, (0, 255, 0))
for m, cov in found_distrs:
draw_gaussain(img, m, cov, (0, 0, 255))
cv2.imshow('gaussian mixture', img)
ch = cv2.waitKey(0)
cv.imshow('gaussian mixture', img)
ch = cv.waitKey(0)
if ch == 27:
break
cv2.destroyAllWindows()
cv.destroyAllWindows()