Package pycv :: Package cs :: Package cv :: Module imageview
[hide private]
[frames] | no frames]

Source Code for Module pycv.cs.cv.imageview

  1  # PyCV - A Computer Vision Package for Python Incorporating Fast Training of Face Detection 
  2   
  3  # Copyright 2007 Nanyang Technological University, Singapore. 
  4  # Authors: Minh-Tri Pham, Viet-Dung D. Hoang, and Tat-Jen Cham. 
  5   
  6  # This file is part of PyCV. 
  7   
  8  # PyCV is free software: you can redistribute it and/or modify 
  9  # it under the terms of the GNU General Public  
 10  # License as published by the Free Software Foundation, either version  
 11  # 3 of the License, or (at your option) any later version. 
 12   
 13  # PyCV is distributed in the hope that it will be useful, 
 14  # but WITHOUT ANY WARRANTY; without even the implied warranty of 
 15  # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
 16  # GNU General Public License for more details. 
 17   
 18  # You should have received a copy of the GNU General Public License 
 19  # along with this program.  If not, see <http://www.gnu.org/licenses/>. 
 20   
 21  # --------------------------------------------------------------------- 
 22  #!/usr/bin/env python 
 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   
37 -class ImageView:
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
89 - def __del__(self):
90 cvReleaseMat(self.map_matrix)
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
108 A = zeros(6) 109 B = zeros(6) 110 imageview_transform_pairs(self.iparam, self.dparam, A, B) 111 C3 = CvPoint2D32f * 3 112 src = C3((A[0],A[1]),(A[2],A[3]),(A[4],A[5])) 113 dst = C3((B[0],B[1]),(B[2],B[3]),(B[4],B[5])) 114 cvGetAffineTransform(src,dst,self.map_matrix) 115 return self.map_matrix
116