1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25 __all__ = ['ImageView']
26
27 from math import sin, cos
28 from numpy import array, zeros
29
30 from pycv.interfaces.opencv import CvPoint2D32f, CV_64FC1, cvGetAffineTransform, \
31 cvWarpAffine, cvCreateMat, cvReleaseMat, CV_INTER_LINEAR, \
32 CV_WARP_FILL_OUTLIERS, cvSetIdentity, CvScalar, cvGetReal2D, \
33 cvSetReal2D
34
35 from pycv.ext import imageview_transform_pairs, imageview_slide
36
38 """A rotated rectangular view of an image.
39
40 :Parameters:
41 iparam : array((3,),'i')
42 iparam[0] : width of the output patch
43 iparam[1] : height of the output patch
44 iparam[2] : flipping flag
45 Non-zero if in the view the direction from x-axis to
46 y-axis is counter-clockwise
47 Zero if in the view the direction from x-axis to
48 y-axis is clockwise
49 dparam : array((4,),'d')
50 dparam[0] : angle of rotation from the image's x-axis to the view's
51 x-axis, clockwise, (in radians)
52 dparam[1] : scaling ratio, or the view's one unit length
53 (in image pixels)
54 dparam[2] : x-coordinate of the center point (in image pixels)
55 dparam[3] : y-coordinate of the center point (in image pixels)
56 the center point of the view on the image is geometrically
57 transformed into location (0.5*w,0.5*h) on the output patch
58 """
59
60 - def __init__(self,w = 10,h = 10,x0 = 0,y0 = 0,scale = 1,angle = 0,flip = False):
61 """
62 Initialize an image view.
63
64 :Parameters:
65 w : int
66 width of the output patch
67 h : int
68 height of the output patch
69 x0, y0 : double, double
70 center point, location (x0,y0) on the image is geometrically
71 transformed to location (0.5*w,0.5*h) on the output patch
72 scale : double
73 scaling ratio, or the view's one unit length (in image pixel)
74 angle : double
75 angle of rotation from the image's x-axis to the view's x-axis,
76 clockwise, (in radian)
77 flip : boolean
78 to flip the view's y-axis or not
79 Non-zero if in the view the direction from x-axis to
80 y-axis is counter-clockwise
81 Zero if in the view the direction from x-axis to
82 y-axis is clockwise
83 """
84 self.map_matrix = cvCreateMat(2,3,CV_64FC1)
85
86 self.iparam = array((w,h,flip),'i')
87 self.dparam = array((angle, scale, x0, y0),'d')
88
91
92 - def slide(self, x=0, y=0):
93 """Slide the view along its x-axis and y-axis in the image.
94
95 :Parameters:
96 x : double
97 number of (patch) pixels to slide along the x-axis
98 y : double
99 number of (patch) pixels to slide along the y-axis
100
101 :Returns:
102 The dparam array is updated.
103 """
104 imageview_slide(self.iparam, self.dparam, float(x), float(y))
105
106
116