From: Vadim Pisarevsky Date: Wed, 13 Jul 2011 06:19:21 +0000 (+0000) Subject: a few minor fixes in Python samples X-Git-Tag: accepted/tizen/6.0/unified/20201030.111113~6645 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=386f147597d2ac6d88c92a5c114cd4cf2a1e078f;p=platform%2Fupstream%2Fopencv.git a few minor fixes in Python samples --- diff --git a/samples/python2/find_obj.py b/samples/python2/find_obj.py index 9881d00..2a36ddb 100644 --- a/samples/python2/find_obj.py +++ b/samples/python2/find_obj.py @@ -37,10 +37,17 @@ def draw_match(img1, img2, p1, p2, status = None, H = None): red = (0, 0, 255) for (x1, y1), (x2, y2), inlier in zip(np.int32(p1), np.int32(p2), status): col = [red, green][inlier] - if not inlier: + if inlier: cv2.line(vis, (x1, y1), (x2+w1, y2), col) - cv2.circle(vis, (x1, y1), 2, col, -1) - cv2.circle(vis, (x2+w1, y2), 2, col, -1) + cv2.circle(vis, (x1, y1), 2, col, -1) + cv2.circle(vis, (x2+w1, y2), 2, col, -1) + else: + r = 2 + thickness = 3 + cv2.line(vis, (x1-r, y1-r), (x1+r, y1+r), col, thickness) + cv2.line(vis, (x1-r, y1+r), (x1+r, y1-r), col, thickness) + cv2.line(vis, (x2+w1-r, y2-r), (x2+w1+r, y2+r), col, thickness) + cv2.line(vis, (x2+w1-r, y2+r), (x2+w1+r, y2-r), col, thickness) return vis if __name__ == '__main__': diff --git a/samples/python2/gaussian_mix.py b/samples/python2/gaussian_mix.py index d7aaa21..1c06771 100644 --- a/samples/python2/gaussian_mix.py +++ b/samples/python2/gaussian_mix.py @@ -1,8 +1,8 @@ import numpy as np +import math from numpy import random import cv2 - def make_gaussians(cluster_n, img_size): points = [] ref_distrs = [] @@ -20,7 +20,7 @@ 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) - ang = np.rad2deg( np.arctan2(u[1, 0], u[0, 0]) ) + ang = np.arctan2(u[1, 0], u[0, 0])*(180/math.pi) s1, s2 = np.sqrt(w)*3.0 cv2.ellipse(img, (x, y), (s1, s2), ang, 0, 360, color, 1, cv2.CV_AA) diff --git a/samples/python2/inpaint.py b/samples/python2/inpaint.py index ddd8abc..0ae3854 100644 --- a/samples/python2/inpaint.py +++ b/samples/python2/inpaint.py @@ -5,8 +5,8 @@ from common import Sketcher help_message = '''USAGE: inpaint.py [] Keys: - SPACE - update inpaint - r - restore image + SPACE - inpaint + r - reset the inpainting mask ESC - exit ''' diff --git a/samples/python2/opt_flow.py b/samples/python2/opt_flow.py index 4a18664..8ab1aa2 100644 --- a/samples/python2/opt_flow.py +++ b/samples/python2/opt_flow.py @@ -1,4 +1,5 @@ import numpy as np +import math import cv2, cv import video @@ -29,7 +30,7 @@ def draw_hsv(flow): ang = np.arctan2(fy, fx) + np.pi v = np.sqrt(fx*fx+fy*fy) hsv = np.zeros((h, w, 3), np.uint8) - hsv[...,0] = np.rad2deg(ang)/2 + hsv[...,0] = ang*(180/math.pi/2) hsv[...,1] = 255 hsv[...,2] = np.minimum(v*4, 255) bgr = cv2.cvtColor(hsv, cv.CV_HSV2BGR) diff --git a/samples/python2/watershed.py b/samples/python2/watershed.py index 5d45417..ffddbbc 100644 --- a/samples/python2/watershed.py +++ b/samples/python2/watershed.py @@ -51,7 +51,7 @@ class App: print 'auto_update if', ['off', 'on'][self.auto_update] if ch in [ord('r'), ord('R')]: self.markers[:] = 0 - self.markers_vis[:] = self.img + self.markers_vis[:] = self.img.copy() self.sketch.show()