Package pycv :: Package interfaces :: Package opencv :: Module CVtypes
[hide private]
[frames] | no frames]

Source Code for Module pycv.interfaces.opencv.CVtypes

   1  # PyCV - A Computer Vision Package for Python Incorporating Fast Training of Face Detection 
   2  # Copyright 2007, 2008 Minh-Tri Pham, Viet-Dung D. Hoang, Tat-Jen Cham,  
   3  # and Nanyang Technological University 
   4   
   5  # This file is part of PyCV. 
   6   
   7  # PyCV is free software: you can redistribute it and/or modify 
   8  # it under the terms of the GNU General Public  
   9  # License as published by the Free Software Foundation, either version  
  10  # 3 of the License, or (at your option) any later version. 
  11   
  12  # PyCV is distributed in the hope that it will be useful, 
  13  # but WITHOUT ANY WARRANTY; without even the implied warranty of 
  14  # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
  15  # GNU General Public License for more details. 
  16   
  17  # You should have received a copy of the GNU General Public License 
  18  # along with this program.  If not, see <http://www.gnu.org/licenses/>. 
  19   
  20  # Non-free versions of PyCV, when available, are under terms different  
  21  # from those of the General Public License. They do not require you to 
  22  # accompany any object code using PyCV with the corresponding 
  23  # source code. Users interested in such a license should contact us 
  24  # (mtpham@ntu.edu.sg) for more information. 
  25  # --------------------------------------------------------------------- 
  26  #!/usr/bin/env python 
  27  """ 
  28  This file started life as cvtypes.py with the following header (that I can't read) 
  29   
  30  Wrapper-Modul cvtypes.py zur Verwendung der OpenCV-Bibliothek beta5 
  31  unter Python, wobei der Zugriff ueber ctypes erfolgt. 
  32  Autor: Michael Otto 
  33  To do: noch fehlende Strukturen wrappen (z. B. CvKalman) 
  34         noch fehlende Konstanten wrappen (z. B. CV_MAX_DIM_HEAP) 
  35         noch fehlende Makros und Inlinefunktionen wrappen 
  36         ausgiebig testen 
  37  Log:   2006/07/25 Dokumentationsstrings hinzugefuegt 
  38         2006/07/10 Fehler in cvGEMM, cvMatMulAdd und cvMatMul beseitigt 
  39         2006/06/28 Modul erzeugt 
  40   
  41  I hacked it both automatically and by hand to bring it up to date with OpenCV 1.0 and 
  42  to use prototype for the functions. I also added from_param methods to allow lists to many 
  43  functions that expect a C array. 
  44   
  45  I checked with Michael and he graciously agreed to let me give it away. This software is 
  46  free for any use. If you or your lawyer are stupid enough to believe that Micheal or I have 
  47  any liability for it, you should not use it, otherwise be our guest. 
  48   
  49  Gary Bishop February 2007 
  50   
  51  Updated 12 May 2007 to include modifications provided by Russell Warren 
  52  """ 
  53   
  54  # --- Importe ---------------------------------------------------------------- 
  55   
  56  import ctypes, os, sys 
  57  from ctypes import Structure, Union, POINTER, SetPointerType, CFUNCTYPE, cdll, byref, sizeof 
  58  from ctypes import c_char_p, c_double, c_float, c_byte, c_ubyte, c_int, c_void_p, c_ulong 
  59  from ctypes import c_uint32, c_short, c_char, c_longlong 
  60  import math 
  61  # ----Load the DLLs ---------------------------------------------------------- 
  62  # modified a little bit by Minh-Tri Pham 
  63  if os.name == 'posix' and sys.platform.startswith('linux'): 
  64      try: 
  65          _cxDLL = cdll.LoadLibrary('libcxcore.so.1') 
  66          _cvDLL = cdll.LoadLibrary('libcv.so.1') 
  67          _hgDLL = cdll.LoadLibrary('libhighgui.so.1') 
  68      except: 
  69          raise ImportError("Cannot import OpenCV's .so files. Make sure you have their path included in your PATH variable.") 
  70  elif os.name == 'posix' and sys.platform.startswith('darwin'): 
  71      try: 
  72          _cxDLL = cdll.LoadLibrary('libcxcore.dylib') 
  73          _cvDLL = cdll.LoadLibrary('libcv.dylib') 
  74          _hgDLL = cdll.LoadLibrary('libhighgui.dylib') 
  75      except: 
  76          raise ImportError("Cannot import OpenCV's .dynlib files. Make sure you have their path included in your PATH variable.") 
  77  elif os.name == 'nt': 
  78      try: 
  79          _cxDLL = cdll.cxcore100 
  80          _cvDLL = cdll.cv100 
  81          _hgDLL = cdll.highgui100 
  82      except: 
  83          raise ImportError("Cannot import OpenCV's .DLL files. Make sure you have their path included in your PATH variable.") 
  84  else: 
  85      raise NotImplemented 
  86   
  87  # --- CONSTANTS AND STUFF FROM CV.H ------------------------------------------------------ 
  88   
  89  CV_BLUR_NO_SCALE = 0 
  90  CV_BLUR = 1 
  91  CV_GAUSSIAN = 2 
  92  CV_MEDIAN = 3 
  93  CV_BILATERAL = 4 
  94  CV_INPAINT_NS = 0 
  95  CV_INPAINT_TELEA = 1 
  96  CV_SCHARR = -1 
  97  CV_MAX_SOBEL_KSIZE = 7 
  98  CV_BGR2BGRA = 0 
  99  CV_RGB2RGBA = CV_BGR2BGRA 
 100  CV_BGRA2BGR = 1 
 101  CV_RGBA2RGB = CV_BGRA2BGR 
 102  CV_BGR2RGBA = 2 
 103  CV_RGB2BGRA = CV_BGR2RGBA 
 104  CV_RGBA2BGR = 3 
 105  CV_BGRA2RGB = CV_RGBA2BGR 
 106  CV_BGR2RGB = 4 
 107  CV_RGB2BGR = CV_BGR2RGB 
 108  CV_BGRA2RGBA = 5 
 109  CV_RGBA2BGRA = CV_BGRA2RGBA 
 110  CV_BGR2GRAY = 6 
 111  CV_RGB2GRAY = 7 
 112  CV_GRAY2BGR = 8 
 113  CV_GRAY2RGB = CV_GRAY2BGR 
 114  CV_GRAY2BGRA = 9 
 115  CV_GRAY2RGBA = CV_GRAY2BGRA 
 116  CV_BGRA2GRAY = 10 
 117  CV_RGBA2GRAY = 11 
 118  CV_BGR2BGR565 = 12 
 119  CV_RGB2BGR565 = 13 
 120  CV_BGR5652BGR = 14 
 121  CV_BGR5652RGB = 15 
 122  CV_BGRA2BGR565 = 16 
 123  CV_RGBA2BGR565 = 17 
 124  CV_BGR5652BGRA = 18 
 125  CV_BGR5652RGBA = 19 
 126  CV_GRAY2BGR565 = 20 
 127  CV_BGR5652GRAY = 21 
 128  CV_BGR2BGR555 = 22 
 129  CV_RGB2BGR555 = 23 
 130  CV_BGR5552BGR = 24 
 131  CV_BGR5552RGB = 25 
 132  CV_BGRA2BGR555 = 26 
 133  CV_RGBA2BGR555 = 27 
 134  CV_BGR5552BGRA = 28 
 135  CV_BGR5552RGBA = 29 
 136  CV_GRAY2BGR555 = 30 
 137  CV_BGR5552GRAY = 31 
 138  CV_BGR2XYZ = 32 
 139  CV_RGB2XYZ = 33 
 140  CV_XYZ2BGR = 34 
 141  CV_XYZ2RGB = 35 
 142  CV_BGR2YCrCb = 36 
 143  CV_RGB2YCrCb = 37 
 144  CV_YCrCb2BGR = 38 
 145  CV_YCrCb2RGB = 39 
 146  CV_BGR2HSV = 40 
 147  CV_RGB2HSV = 41 
 148  CV_BGR2Lab = 44 
 149  CV_RGB2Lab = 45 
 150  CV_BayerBG2BGR = 46 
 151  CV_BayerGB2BGR = 47 
 152  CV_BayerRG2BGR = 48 
 153  CV_BayerGR2BGR = 49 
 154  CV_BayerBG2RGB = CV_BayerRG2BGR 
 155  CV_BayerGB2RGB = CV_BayerGR2BGR 
 156  CV_BayerRG2RGB = CV_BayerBG2BGR 
 157  CV_BayerGR2RGB = CV_BayerGB2BGR 
 158  CV_BGR2Luv = 50 
 159  CV_RGB2Luv = 51 
 160  CV_BGR2HLS = 52 
 161  CV_RGB2HLS = 53 
 162  CV_HSV2BGR = 54 
 163  CV_HSV2RGB = 55 
 164  CV_Lab2BGR = 56 
 165  CV_Lab2RGB = 57 
 166  CV_Luv2BGR = 58 
 167  CV_Luv2RGB = 59 
 168  CV_HLS2BGR = 60 
 169  CV_HLS2RGB = 61 
 170  CV_COLORCVT_MAX = 100 
 171  CV_INTER_NN = 0 
 172  CV_INTER_LINEAR = 1 
 173  CV_INTER_CUBIC = 2 
 174  CV_INTER_AREA = 3 
 175  CV_WARP_FILL_OUTLIERS = 8 
 176  CV_WARP_INVERSE_MAP = 16 
 177  CV_SHAPE_RECT = 0 
 178  CV_SHAPE_CROSS = 1 
 179  CV_SHAPE_ELLIPSE = 2 
 180  CV_SHAPE_CUSTOM = 100 
 181  CV_MOP_OPEN = 2 
 182  CV_MOP_CLOSE = 3 
 183  CV_MOP_GRADIENT = 4 
 184  CV_MOP_TOPHAT = 5 
 185  CV_MOP_BLACKHAT = 6 
 186  CV_TM_SQDIFF = 0 
 187  CV_TM_SQDIFF_NORMED = 1 
 188  CV_TM_CCORR = 2 
 189  CV_TM_CCORR_NORMED = 3 
 190  CV_TM_CCOEFF = 4 
 191  CV_TM_CCOEFF_NORMED = 5 
 192  CV_LKFLOW_PYR_A_READY = 1 
 193  CV_LKFLOW_PYR_B_READY = 2 
 194  CV_LKFLOW_INITIAL_GUESSES = 4 
 195  CV_POLY_APPROX_DP = 0 
 196  CV_DOMINANT_IPAN = 1 
 197  CV_CONTOURS_MATCH_I1 = 1 
 198  CV_CONTOURS_MATCH_I2 = 2 
 199  CV_CONTOURS_MATCH_I3 = 3 
 200  CV_CONTOUR_TREES_MATCH_I1 = 1 
 201  CV_CLOCKWISE = 1 
 202  CV_COUNTER_CLOCKWISE = 2 
 203  CV_COMP_CORREL = 0 
 204  CV_COMP_CHISQR = 1 
 205  CV_COMP_INTERSECT = 2 
 206  CV_COMP_BHATTACHARYYA = 3 
 207  CV_VALUE = 1 
 208  CV_ARRAY = 2 
 209  CV_DIST_MASK_3 = 3 
 210  CV_DIST_MASK_5 = 5 
 211  CV_DIST_MASK_PRECISE = 0 
 212  CV_THRESH_BINARY = 0      # value = (value > threshold) ? max_value : 0 
 213  CV_THRESH_BINARY_INV = 1  # value = (value > threshold) ? 0 : max_value 
 214  CV_THRESH_TRUNC = 2       # value = (value > threshold) ? threshold : value 
 215  CV_THRESH_TOZERO = 3      # value = (value > threshold) ? value : 0 
 216  CV_THRESH_TOZERO_INV = 4  # value = (value > threshold) ? 0 : value 
 217  CV_THRESH_MASK = 7 
 218  CV_THRESH_OTSU = 8        # use Otsu algorithm to choose the optimal threshold value 
 219  CV_ADAPTIVE_THRESH_MEAN_C = 0 
 220  CV_ADAPTIVE_THRESH_GAUSSIAN_C = 1 
 221  CV_FLOODFILL_FIXED_RANGE = 1 << 16 
 222  CV_FLOODFILL_MASK_ONLY = 1 << 17 
 223  CV_CANNY_L2_GRADIENT = 1 << 31 
 224  CV_HOUGH_STANDARD = 0 
 225  CV_HOUGH_PROBABILISTIC = 1 
 226  CV_HOUGH_MULTI_SCALE = 2 
 227  CV_HOUGH_GRADIENT = 3 
 228  CV_HAAR_DO_CANNY_PRUNING = 1 
 229  CV_HAAR_SCALE_IMAGE = 2 
 230  CV_CALIB_USE_INTRINSIC_GUESS = 1 
 231  CV_CALIB_FIX_ASPECT_RATIO = 2 
 232  CV_CALIB_FIX_PRINCIPAL_POINT = 4 
 233  CV_CALIB_ZERO_TANGENT_DIST = 8 
 234  CV_CALIB_CB_ADAPTIVE_THRESH = 1 
 235  CV_CALIB_CB_NORMALIZE_IMAGE = 2 
 236  CV_CALIB_CB_FILTER_QUADS = 4 
 237  CV_FM_7POINT = 1 
 238  CV_FM_8POINT = 2 
 239  CV_FM_LMEDS_ONLY = 4 
 240  CV_FM_RANSAC_ONLY = 8 
 241  CV_FM_LMEDS = CV_FM_LMEDS_ONLY + CV_FM_8POINT 
 242  CV_FM_RANSAC = CV_FM_RANSAC_ONLY + CV_FM_8POINT 
 243   
 244  #Viji Periapoilan 4/16/2007 (start) 
 245  #Added constants for contour retrieval mode - Apr 19th 
 246  CV_RETR_EXTERNAL = 0 
 247  CV_RETR_LIST     = 1 
 248  CV_RETR_CCOMP    = 2 
 249  CV_RETR_TREE     = 3 
 250   
 251  #Added constants for contour approximation method  - Apr 19th 
 252  CV_CHAIN_CODE               = 0 
 253  CV_CHAIN_APPROX_NONE        = 1 
 254  CV_CHAIN_APPROX_SIMPLE      = 2 
 255  CV_CHAIN_APPROX_TC89_L1     = 3 
 256  CV_CHAIN_APPROX_TC89_KCOS   = 4 
 257  CV_LINK_RUNS                = 5 
 258  #Viji Periapoilan 4/16/2007(end) 
 259  # --- CONSTANTS AND STUFF FROM highgui.h ---- 
 260  CV_WINDOW_AUTOSIZE = 1 
 261  CV_EVENT_MOUSEMOVE = 0 
 262  CV_EVENT_LBUTTONDOWN = 1 
 263  CV_EVENT_RBUTTONDOWN = 2 
 264  CV_EVENT_MBUTTONDOWN = 3 
 265  CV_EVENT_LBUTTONUP = 4 
 266  CV_EVENT_RBUTTONUP = 5 
 267  CV_EVENT_MBUTTONUP = 6 
 268  CV_EVENT_LBUTTONDBLCLK = 7 
 269  CV_EVENT_RBUTTONDBLCLK = 8 
 270  CV_EVENT_MBUTTONDBLCLK = 9 
 271  CV_EVENT_FLAG_LBUTTON = 1 
 272  CV_EVENT_FLAG_RBUTTON = 2 
 273  CV_EVENT_FLAG_MBUTTON = 4 
 274  CV_EVENT_FLAG_CTRLKEY = 8 
 275  CV_EVENT_FLAG_SHIFTKEY = 16 
 276  CV_EVENT_FLAG_ALTKEY = 32 
 277  CV_LOAD_IMAGE_UNCHANGED = -1 # 8 bit, color or gray - deprecated, use CV_LOAD_IMAGE_ANYCOLOR 
 278  CV_LOAD_IMAGE_GRAYSCALE =  0 # 8 bit, gray 
 279  CV_LOAD_IMAGE_COLOR     =  1 # 8 bit unless combined with CV_LOAD_IMAGE_ANYDEPTH, color 
 280  CV_LOAD_IMAGE_ANYDEPTH  =  2 # any depth, if specified on its own gray by itself 
 281                               # equivalent to CV_LOAD_IMAGE_UNCHANGED but can be modified 
 282                               # with CV_LOAD_IMAGE_ANYDEPTH 
 283  CV_LOAD_IMAGE_ANYCOLOR  =  4 
 284  CV_CVTIMG_FLIP = 1 
 285  CV_CVTIMG_SWAP_RB = 2 
 286  CV_CAP_ANY = 0     # autodetect 
 287  CV_CAP_MIL = 100     # MIL proprietary drivers 
 288  CV_CAP_VFW = 200     # platform native 
 289  CV_CAP_V4L = 200 
 290  CV_CAP_V4L2 = 200 
 291  CV_CAP_FIREWARE = 300     # IEEE 1394 drivers 
 292  CV_CAP_IEEE1394 = 300 
 293  CV_CAP_DC1394 = 300 
 294  CV_CAP_CMU1394 = 300 
 295  CV_CAP_STEREO = 400     # TYZX proprietary drivers 
 296  CV_CAP_TYZX = 400 
 297  CV_TYZX_LEFT = 400 
 298  CV_TYZX_RIGHT = 401 
 299  CV_TYZX_COLOR = 402 
 300  CV_TYZX_Z = 403 
 301  CV_CAP_QT = 500     # Quicktime 
 302  CV_CAP_PROP_POS_MSEC = 0 
 303  CV_CAP_PROP_POS_FRAMES = 1 
 304  CV_CAP_PROP_POS_AVI_RATIO = 2 
 305  CV_CAP_PROP_FRAME_WIDTH = 3 
 306  CV_CAP_PROP_FRAME_HEIGHT = 4 
 307  CV_CAP_PROP_FPS = 5 
 308  CV_CAP_PROP_FOURCC = 6 
 309  CV_CAP_PROP_FRAME_COUNT = 7 
 310  CV_CAP_PROP_FORMAT = 8 
 311  CV_CAP_PROP_MODE = 9 
 312  CV_CAP_PROP_BRIGHTNESS = 10 
 313  CV_CAP_PROP_CONTRAST = 11 
 314  CV_CAP_PROP_SATURATION = 12 
 315  CV_CAP_PROP_HUE = 13 
 316  CV_CAP_PROP_GAIN = 14 
 317  CV_CAP_PROP_CONVERT_RGB = 15 
 318   
 319  # --- CONSTANTS AND STUFF FROM cxcore.h ---- 
 320  CV_AUTOSTEP = 0x7fffffff 
 321  CV_MAX_ARR = 10 
 322  CV_NO_DEPTH_CHECK = 1 
 323  CV_NO_CN_CHECK = 2 
 324  CV_NO_SIZE_CHECK = 4 
 325  CV_CMP_EQ = 0 
 326  CV_CMP_GT = 1 
 327  CV_CMP_GE = 2 
 328  CV_CMP_LT = 3 
 329  CV_CMP_LE = 4 
 330  CV_CMP_NE = 5 
 331  CV_CHECK_RANGE = 1 
 332  CV_CHECK_QUIET = 2 
 333  CV_RAND_UNI = 0 
 334  CV_RAND_NORMAL = 1 
 335  CV_GEMM_A_T = 1 
 336  CV_GEMM_B_T = 2 
 337  CV_GEMM_C_T = 4 
 338  CV_SVD_MODIFY_A = 1 
 339  CV_SVD_U_T = 2 
 340  CV_SVD_V_T = 4 
 341  CV_LU = 0 
 342  CV_SVD = 1 
 343  CV_SVD_SYM = 2 
 344  CV_COVAR_SCRAMBLED = 0 
 345  CV_COVAR_NORMAL = 1 
 346  CV_COVAR_USE_AVG = 2 
 347  CV_COVAR_SCALE = 4 
 348  CV_COVAR_ROWS = 8 
 349  CV_COVAR_COLS = 16 
 350  CV_PCA_DATA_AS_ROW = 0 
 351  CV_PCA_DATA_AS_COL = 1 
 352  CV_PCA_USE_AVG = 2 
 353  CV_C = 1 
 354  CV_L1 = 2 
 355  CV_L2 = 4 
 356  CV_NORM_MASK = 7 
 357  CV_RELATIVE = 8 
 358  CV_DIFF = 16 
 359  CV_MINMAX = 32 
 360  CV_DIFF_C = (CV_DIFF | CV_C) 
 361  CV_DIFF_L1 = (CV_DIFF | CV_L1) 
 362  CV_DIFF_L2 = (CV_DIFF | CV_L2) 
 363  CV_RELATIVE_C = (CV_RELATIVE | CV_C) 
 364  CV_RELATIVE_L1 = (CV_RELATIVE | CV_L1) 
 365  CV_RELATIVE_L2 = (CV_RELATIVE | CV_L2) 
 366  CV_REDUCE_SUM = 0 
 367  CV_REDUCE_AVG = 1 
 368  CV_REDUCE_MAX = 2 
 369  CV_REDUCE_MIN = 3 
 370  CV_DXT_FORWARD = 0 
 371  CV_DXT_INVERSE = 1 
 372  CV_DXT_SCALE = 2     # divide result by size of array 
 373  CV_DXT_INV_SCALE = CV_DXT_INVERSE + CV_DXT_SCALE 
 374  CV_DXT_INVERSE_SCALE = CV_DXT_INV_SCALE 
 375  CV_DXT_ROWS = 4     # transfor each row individually 
 376  CV_DXT_MUL_CONJ = 8     # conjugate the second argument of cvMulSpectrums 
 377  CV_FRONT = 1 
 378  CV_BACK = 0 
 379  CV_GRAPH_VERTEX = 1 
 380  CV_GRAPH_TREE_EDGE = 2 
 381  CV_GRAPH_BACK_EDGE = 4 
 382  CV_GRAPH_FORWARD_EDGE = 8 
 383  CV_GRAPH_CROSS_EDGE = 16 
 384  CV_GRAPH_ANY_EDGE = 30 
 385  CV_GRAPH_NEW_TREE = 32 
 386  CV_GRAPH_BACKTRACKING = 64 
 387  CV_GRAPH_OVER = -1 
 388  CV_GRAPH_ALL_ITEMS = -1 
 389  CV_GRAPH_ITEM_VISITED_FLAG = 1 << 30 
 390  CV_GRAPH_SEARCH_TREE_NODE_FLAG = 1 << 29 
 391  CV_GRAPH_FORWARD_EDGE_FLAG = 1 << 28 
 392  CV_FILLED = -1 
 393  CV_AA = 16 
 394  CV_FONT_HERSHEY_SIMPLEX = 0 
 395  CV_FONT_HERSHEY_PLAIN = 1 
 396  CV_FONT_HERSHEY_DUPLEX = 2 
 397  CV_FONT_HERSHEY_COMPLEX = 3 
 398  CV_FONT_HERSHEY_TRIPLEX = 4 
 399  CV_FONT_HERSHEY_COMPLEX_SMALL = 5 
 400  CV_FONT_HERSHEY_SCRIPT_SIMPLEX = 6 
 401  CV_FONT_HERSHEY_SCRIPT_COMPLEX = 7 
 402  CV_FONT_ITALIC = 16 
 403  CV_FONT_VECTOR0 = CV_FONT_HERSHEY_SIMPLEX 
 404  CV_ErrModeLeaf = 0     # print error and exit program 
 405  CV_ErrModeParent = 1     # print error and continue 
 406  CV_ErrModeSilent = 2     # don't print and continue 
 407   
 408  #------ 
 409   
 410  # make function prototypes a bit easier to declare 
411 -def cfunc(name, dll, result, *args):
412 '''build and apply a ctypes prototype complete with parameter flags 413 e.g. 414 cvMinMaxLoc = cfunc('cvMinMaxLoc', _cxDLL, None, 415 ('image', POINTER(IplImage), 1), 416 ('min_val', POINTER(double), 2), 417 ('max_val', POINTER(double), 2), 418 ('min_loc', POINTER(CvPoint), 2), 419 ('max_loc', POINTER(CvPoint), 2), 420 ('mask', POINTER(IplImage), 1, None)) 421 means locate cvMinMaxLoc in dll _cxDLL, it returns nothing. 422 The first argument is an input image. The next 4 arguments are output, and the last argument is 423 input with an optional value. A typical call might look like: 424 425 min_val,max_val,min_loc,max_loc = cvMinMaxLoc(img) 426 ''' 427 atypes = [] 428 aflags = [] 429 for arg in args: 430 atypes.append(arg[1]) 431 aflags.append((arg[2], arg[0]) + arg[3:]) 432 return CFUNCTYPE(result, *atypes)((name, dll), tuple(aflags))
433
434 -class ListPOINTER(object):
435 '''Just like a POINTER but accept a list of ctype as an argument'''
436 - def __init__(self, etype):
437 self.etype = etype
438
439 - def from_param(self, param):
440 if isinstance(param, (list,tuple)): 441 return (self.etype * len(param))(*param)
442
443 -class ListPOINTER2(object):
444 '''Just like POINTER(POINTER(ctype)) but accept a list of lists of ctype'''
445 - def __init__(self, etype):
446 self.etype = etype
447
448 - def from_param(self, param):
449 if isinstance(param, (list,tuple)): 450 val = (POINTER(self.etype) * len(param))() 451 for i,v in enumerate(param): 452 if isinstance(v, (list,tuple)): 453 val[i] = (self.etype * len(v))(*v) 454 else: 455 raise TypeError, 'nested list or tuple required at %d' % i 456 return val 457 else: 458 raise TypeError, 'list or tuple required'
459
460 -class ByRefArg(object):
461 '''Just like a POINTER but accept an argument and pass it byref'''
462 - def __init__(self, atype):
463 self.atype = atype
464
465 - def from_param(self, param):
466 return byref(param)
467
468 -class CallableToFunc(object):
469 '''Make the callable argument into a C callback'''
470 - def __init__(self, cbacktype):
471 self.cbacktype = cbacktype
472
473 - def from_param(self, param):
474 return self.cbacktype(param)
475 476 # --- Globale Variablen und Ausnahmen ---------------------------------------- 477 478 CV_TM_SQDIFF =0 479 CV_TM_SQDIFF_NORMED =1 480 CV_TM_CCORR =2 481 CV_TM_CCORR_NORMED =3 482 CV_TM_CCOEFF =4 483 CV_TM_CCOEFF_NORMED =5 484 485 # Image type (IplImage) 486 IPL_DEPTH_SIGN = 0x80000000 487 488 IPL_DEPTH_1U = 1 489 IPL_DEPTH_8U = 8 490 IPL_DEPTH_16U = 16 491 IPL_DEPTH_32F = 32 492 493 IPL_DEPTH_8S = IPL_DEPTH_SIGN + IPL_DEPTH_8U 494 IPL_DEPTH_16S = IPL_DEPTH_SIGN + IPL_DEPTH_16U 495 IPL_DEPTH_32S = IPL_DEPTH_SIGN + 32 496 497 IPL_DATA_ORDER_PIXEL = 0 498 IPL_DATA_ORDER_PLANE = 1 499 500 IPL_ORIGIN_TL = 0 501 IPL_ORIGIN_BL = 1 502 503 IPL_ALIGN_4BYTES = 4 504 IPL_ALIGN_8BYTES = 8 505 IPL_ALIGN_16BYTES = 16 506 IPL_ALIGN_32BYTES = 32 507 508 IPL_ALIGN_DWORD = IPL_ALIGN_4BYTES 509 IPL_ALIGN_QWORD = IPL_ALIGN_8BYTES 510 511 IPL_BORDER_CONSTANT = 0 512 IPL_BORDER_REPLICATE = 1 513 IPL_BORDER_REFLECT = 2 514 IPL_BORDER_WRAP = 3 515 516 IPL_IMAGE_HEADER = 1 517 IPL_IMAGE_DATA = 2 518 IPL_IMAGE_ROI = 4 519 520 CV_TYPE_NAME_IMAGE = "opencv-image" 521 522 IPL_DEPTH_64F = 64 523 524 # Matrix type (CvMat) 525 CV_CN_MAX = 4 526 CV_CN_SHIFT = 3 527 CV_DEPTH_MAX = (1 << CV_CN_SHIFT) 528 529 CV_8U = 0 530 CV_8S = 1 531 CV_16U = 2 532 CV_16S = 3 533 CV_32S = 4 534 CV_32F = 5 535 CV_64F = 6 536 CV_USRTYPE1 = 7 537 538 # 539 # Sim Harbert 4/9/2007 (start) 540 # Added following defines: 541 # 542 CV_THRESH_BINARY = 0 543 CV_THRESH_BINARY_INV = 1 544 CV_THRESH_TRUNC = 2 545 CV_THRESH_TOZERO = 3 546 CV_THRESH_TOZERO_INV = 4 547 548 CV_C = 1 549 CV_L1 = 2 550 CV_L2 = 4 551 552 CV_PI = math.pi 553 554 # Sim Harbert 4/9/2007 (end) 555 556 #Viji Periapoilan 4/16/2007 (start) 557 # Added the following constants to work with facedetect sample 558 CV_INTER_NN = 0 #nearest-neigbor interpolation, 559 CV_INTER_LINEAR = 1 #bilinear interpolation (used by default) 560 CV_INTER_CUBIC = 2 # bicubic interpolation. 561 CV_INTER_AREA = 3 #resampling using pixel area relation. It is preferred method for image decimation that gives moire-free results. In case of zooming it is similar to CV_INTER_NN method. 562 563 #Added constants for contour retrieval mode - Apr 19th 564 CV_RETR_EXTERNAL = 0 565 CV_RETR_LIST = 1 566 CV_RETR_CCOMP = 2 567 CV_RETR_TREE = 3 568 569 #Added constants for contour approximation method - Apr 19th 570 CV_CHAIN_CODE = 0 571 CV_CHAIN_APPROX_NONE = 1 572 CV_CHAIN_APPROX_SIMPLE = 2 573 CV_CHAIN_APPROX_TC89_L1 = 3 574 CV_CHAIN_APPROX_TC89_KCOS = 4 575 CV_LINK_RUNS = 5 576 #Viji Periapoilan 4/16/2007(end) 577 578 #Viji Periapoilan 5/23/2007(start) 579 CV_WHOLE_SEQ_END_INDEX = 0x3fffffff 580 #CV_WHOLE_SEQ = CvSlice(0, CV_WHOLE_SEQ_END_INDEX) 581 582 #Viji Periapoilan 5/23/2007(end) 583
584 -def CV_MAKETYPE(depth,cn):
585 return ((depth) + (((cn)-1) << CV_CN_SHIFT))
586 CV_MAKE_TYPE = CV_MAKETYPE 587 588 CV_8UC1 = CV_MAKETYPE(CV_8U,1) 589 CV_8UC2 = CV_MAKETYPE(CV_8U,2) 590 CV_8UC3 = CV_MAKETYPE(CV_8U,3) 591 CV_8UC4 = CV_MAKETYPE(CV_8U,4) 592 593 CV_8SC1 = CV_MAKETYPE(CV_8S,1) 594 CV_8SC2 = CV_MAKETYPE(CV_8S,2) 595 CV_8SC3 = CV_MAKETYPE(CV_8S,3) 596 CV_8SC4 = CV_MAKETYPE(CV_8S,4) 597 598 CV_16UC1 = CV_MAKETYPE(CV_16U,1) 599 CV_16UC2 = CV_MAKETYPE(CV_16U,2) 600 CV_16UC3 = CV_MAKETYPE(CV_16U,3) 601 CV_16UC4 = CV_MAKETYPE(CV_16U,4) 602 603 CV_16SC1 = CV_MAKETYPE(CV_16S,1) 604 CV_16SC2 = CV_MAKETYPE(CV_16S,2) 605 CV_16SC3 = CV_MAKETYPE(CV_16S,3) 606 CV_16SC4 = CV_MAKETYPE(CV_16S,4) 607 608 CV_32SC1 = CV_MAKETYPE(CV_32S,1) 609 CV_32SC2 = CV_MAKETYPE(CV_32S,2) 610 CV_32SC3 = CV_MAKETYPE(CV_32S,3) 611 CV_32SC4 = CV_MAKETYPE(CV_32S,4) 612 613 CV_32FC1 = CV_MAKETYPE(CV_32F,1) 614 CV_32FC2 = CV_MAKETYPE(CV_32F,2) 615 CV_32FC3 = CV_MAKETYPE(CV_32F,3) 616 CV_32FC4 = CV_MAKETYPE(CV_32F,4) 617 618 CV_64FC1 = CV_MAKETYPE(CV_64F,1) 619 CV_64FC2 = CV_MAKETYPE(CV_64F,2) 620 CV_64FC3 = CV_MAKETYPE(CV_64F,3) 621 CV_64FC4 = CV_MAKETYPE(CV_64F,4) 622 623 CV_AUTO_STEP = 0x7fffffff 624 625 CV_MAT_CN_MASK = ((CV_CN_MAX - 1) << CV_CN_SHIFT)
626 -def CV_MAT_CN(flags):
627 return ((((flags) & CV_MAT_CN_MASK) >> CV_CN_SHIFT) + 1)
628 CV_MAT_DEPTH_MASK = (CV_DEPTH_MAX - 1)
629 -def CV_MAT_DEPTH(flags):
630 return ((flags) & CV_MAT_DEPTH_MASK)
631 CV_MAT_TYPE_MASK = (CV_DEPTH_MAX*CV_CN_MAX - 1)
632 -def CV_MAT_TYPE(flags):
633 ((flags) & CV_MAT_TYPE_MASK)
634 CV_MAT_CONT_FLAG_SHIFT = 9 635 CV_MAT_CONT_FLAG = (1 << CV_MAT_CONT_FLAG_SHIFT)
636 -def CV_IS_MAT_CONT(flags):
637 return ((flags) & CV_MAT_CONT_FLAG)
638 CV_IS_CONT_MAT = CV_IS_MAT_CONT 639 CV_MAT_TEMP_FLAG_SHIFT = 10 640 CV_MAT_TEMP_FLAG = (1 << CV_MAT_TEMP_FLAG_SHIFT)
641 -def CV_IS_TEMP_MAT(flags):
642 return ((flags) & CV_MAT_TEMP_FLAG)
643 644 CV_MAGIC_MASK = 0xFFFF0000 645 CV_MAT_MAGIC_VAL = 0x42420000 646 CV_TYPE_NAME_MAT = "opencv-matrix" 647 648 # Termination criteria for iterative algorithms 649 CV_TERMCRIT_ITER = 1 650 CV_TERMCRIT_NUMBER = CV_TERMCRIT_ITER 651 CV_TERMCRIT_EPS = 2 652 653 # Data structures for persistence (a.k.a serialization) functionality 654 CV_STORAGE_READ = 0 655 CV_STORAGE_WRITE = 1 656 CV_STORAGE_WRITE_TEXT = CV_STORAGE_WRITE 657 CV_STORAGE_WRITE_BINARY = CV_STORAGE_WRITE 658 CV_STORAGE_APPEND = 2 659 660 CV_MAX_DIM = 32 661 662 CV_FILLED = -1 663 CV_AA = 16 664 665 CV_VERSION = "1.0.0" 666 CV_MAJOR_VERSION = 1 667 CV_MINOR_VERSION = 0 668 CV_SUBMINOR_VERSION = 0 669 CV_WINDOW_AUTOSIZE = 1 670 671 CV_CAP_PROP_POS_MSEC = 0 672 CV_CAP_PROP_POS_FRAMES = 1 673 CV_CAP_PROP_POS_AVI_RATIO = 2 674 CV_CAP_PROP_FRAME_WIDTH = 3 675 CV_CAP_PROP_FRAME_HEIGHT = 4 676 CV_CAP_PROP_FPS = 5 677 CV_CAP_PROP_FOURCC = 6 678 CV_CAP_PROP_FRAME_COUNT = 7 679 CV_CAP_PROP_FORMAT = 8 680 CV_CAP_PROP_MODE = 9 681 CV_CAP_PROP_BRIGHTNESS =10 682 CV_CAP_PROP_CONTRAST =11 683 CV_CAP_PROP_SATURATION =12 684 CV_CAP_PROP_HUE =13 685 CV_CAP_PROP_GAIN =14 686 CV_CAP_PROP_CONVERT_RGB =15 687
688 -def CV_FOURCC(c1,c2,c3,c4):
689 return (((ord(c1))&255) + (((ord(c2))&255)<<8) + (((ord(c3))&255)<<16) + (((ord(c4))&255)<<24))
690 691 #Viji Periapoilan 5/21/2007(start) 692 #/****************************************************************************************\ 693 #* Sequence types * 694 #\****************************************************************************************/ 695 696 CV_SEQ_MAGIC_VAL = 0x42990000 697 698 #define CV_IS_SEQ(seq) \ 699 # ((seq) != NULL && (((CvSeq*)(seq))->flags & CV_MAGIC_MASK) == CV_SEQ_MAGIC_VAL) 700 701 CV_SET_MAGIC_VAL = 0x42980000 702 #define CV_IS_SET(set) \ 703 # ((set) != NULL && (((CvSeq*)(set))->flags & CV_MAGIC_MASK) == CV_SET_MAGIC_VAL) 704 705 CV_SEQ_ELTYPE_BITS = 9 706 CV_SEQ_ELTYPE_MASK = ((1 << CV_SEQ_ELTYPE_BITS) - 1) 707 CV_SEQ_ELTYPE_POINT = CV_32SC2 #/* (x,y) */ 708 CV_SEQ_ELTYPE_CODE = CV_8UC1 #/* freeman code: 0..7 */ 709 CV_SEQ_ELTYPE_GENERIC = 0 710 CV_SEQ_ELTYPE_PTR = CV_USRTYPE1 711 CV_SEQ_ELTYPE_PPOINT = CV_SEQ_ELTYPE_PTR #/* &(x,y) */ 712 CV_SEQ_ELTYPE_INDEX = CV_32SC1 #/* #(x,y) */ 713 CV_SEQ_ELTYPE_GRAPH_EDGE = 0 #/* &next_o, &next_d, &vtx_o, &vtx_d */ 714 CV_SEQ_ELTYPE_GRAPH_VERTEX = 0 #/* first_edge, &(x,y) */ 715 CV_SEQ_ELTYPE_TRIAN_ATR = 0 #/* vertex of the binary tree */ 716 CV_SEQ_ELTYPE_CONNECTED_COMP= 0 #/* connected component */ 717 CV_SEQ_ELTYPE_POINT3D = CV_32FC3 #/* (x,y,z) */ 718 719 CV_SEQ_KIND_BITS = 3 720 CV_SEQ_KIND_MASK = (((1 << CV_SEQ_KIND_BITS) - 1)<<CV_SEQ_ELTYPE_BITS) 721 722 723 #/* types of sequences */ 724 CV_SEQ_KIND_GENERIC = (0 << CV_SEQ_ELTYPE_BITS) 725 CV_SEQ_KIND_CURVE = (1 << CV_SEQ_ELTYPE_BITS) 726 CV_SEQ_KIND_BIN_TREE = (2 << CV_SEQ_ELTYPE_BITS) 727 728 #Viji Periapoilan 5/21/2007(end) 729 730 731 # hack the ctypes.Structure class to include printing the fields
732 -class _Structure(Structure):
733 - def __repr__(self):
734 '''Print the fields''' 735 res = [] 736 for field in self._fields_: 737 res.append('%s=%s' % (field[0], repr(getattr(self, field[0])))) 738 return self.__class__.__name__ + '(' + ','.join(res) + ')'
739 @classmethod
740 - def from_param(cls, obj):
741 '''Magically construct from a tuple''' 742 if isinstance(obj, cls): 743 return obj 744 if isinstance(obj, tuple): 745 return cls(*obj) 746 raise TypeError
747 748 # --- Klassen- und Funktionsdefinitionen ------------------------------------- 749 750 # 2D point with integer coordinates
751 -class CvPoint(_Structure):
752 _fields_ = [("x", c_int), 753 ("y", c_int)]
754 755 # 2D point with floating-point coordinates
756 -class CvPoint2D32f(_Structure):
757 _fields_ = [("x", c_float), 758 ("y", c_float)]
759 760 # 3D point with floating-point coordinates
761 -class CvPoint3D32f(_Structure):
762 _fields_ = [("x", c_float), 763 ("y", c_float), 764 ("z", c_float)]
765 766 # 2D point with double precision floating-point coordinates
767 -class CvPoint2D64f(_Structure):
768 _fields_ = [("x", c_double), 769 ("y", c_double)]
770 CvPoint2D64d = CvPoint2D64f 771 772 # 3D point with double precision floating-point coordinates
773 -class CvPoint3D64f(_Structure):
774 _fields_ = [("x", c_double), 775 ("y", c_double), 776 ("z", c_double)]
777 CvPoint3D64d = CvPoint3D64f 778 779 # pixel-accurate size of a rectangle
780 -class CvSize(_Structure):
781 _fields_ = [("width", c_int), 782 ("height", c_int)]
783 784 # sub-pixel accurate size of a rectangle
785 -class CvSize2D32f(_Structure):
786 _fields_ = [("width", c_float), 787 ("height", c_float)]
788 789 # offset and size of a rectangle
790 -class CvRect(_Structure):
791 _fields_ = [("x", c_int), 792 ("y", c_int), 793 ("width", c_int), 794 ("height", c_int)]
795 - def bloat(self, s):
796 return CvRect(self.x-s, self.y-s, self.width+2*s, self.height+2*s)
797 798 # A container for 1-,2-,3- or 4-tuples of numbers
799 -class CvScalar(_Structure):
800 _fields_ = [("val", c_double * 4)]
801 - def __init__(self, *vals):
802 '''Enable initialization with multiple parameters instead of just a tuple''' 803 if len(vals) == 1: 804 super(CvScalar, self).__init__(vals[0]) 805 else: 806 super(CvScalar, self).__init__(vals)
807 808 # Termination criteria for iterative algorithms
809 -class CvTermCriteria(_Structure):
810 _fields_ = [("type", c_int), 811 ("max_iter", c_int), 812 ("epsilon", c_double)]
813 814 # Multi-channel matrix
815 -class CvMat(Structure):
816 _fields_ = [("type", c_int), 817 ("step", c_int), 818 ("refcount", c_void_p), 819 ("hdr_refcount", c_int), 820 ("data", c_void_p), 821 ("rows", c_int), 822 ("cols", c_int)]
823 824 # Multi-dimensional dense multi-channel matrix
825 -class CvMatNDdata(Union):
826 _fields_ = [("ptr", POINTER(c_ubyte)), 827 ("s", POINTER(c_short)), 828 ("i", POINTER(c_int)), 829 ("fl", POINTER(c_float)), 830 ("db", POINTER(c_double))]
831 -class CvMatNDdim(Structure):
832 _fields_ = [("size", c_int), 833 ("step", c_int)]
834 -class CvMatND(Structure):
835 _fields_ = [("type", c_int), 836 ("dims", c_int), 837 ("refcount", c_void_p), 838 ("data", CvMatNDdata), 839 ("dim", CvMatNDdim*CV_MAX_DIM)]
840 841 # IPL image header
842 -class IplImage(Structure):
843 _fields_ = [("nSize", c_int), 844 ("ID", c_int), 845 ("nChannels", c_int), 846 ("alphaChannel", c_int), 847 ("depth", c_int), 848 ("colorModel", c_char * 4), 849 ("channelSeq", c_char * 4), 850 ("dataOrder", c_int), 851 ("origin", c_int), 852 ("align", c_int), 853 ("width", c_int), 854 ("height", c_int), 855 ("roi", c_void_p), 856 ("maskROI", c_void_p), 857 ("imageID", c_void_p), 858 ("tileInfo", c_void_p), 859 ("imageSize", c_int), 860 ("imageData", c_int), 861 ("widthStep", c_int), 862 ("BorderMode", c_int * 4), 863 ("BorderConst", c_int * 4), 864 ("imageDataOrigin", c_char_p)] 865
866 - def __repr__(self):
867 '''Print the fields''' 868 res = [] 869 for field in self._fields_: 870 if field[0] in ['imageData', 'imageDataOrigin']: continue 871 res.append('%s=%s' % (field[0], repr(getattr(self, field[0])))) 872 return self.__class__.__name__ + '(' + ','.join(res) + ')'
873 874 # List of attributes
875 -class CvAttrList(Structure):
876 _fields_ = [("attr", c_void_p), 877 ("next", c_void_p)]
878 879 # Memory storage 880 _lpCvMemStorage = POINTER("CvMemStorage")
881 -class CvMemStorage(Structure):
882 _fields_ = [("signature", c_int), 883 ("bottom", c_void_p), 884 ("top", c_void_p), 885 ("parent", _lpCvMemStorage), 886 ("block_size", c_int), 887 ("free_space", c_int)]
888 SetPointerType(_lpCvMemStorage, CvMemStorage) 889
890 -class CvMemStoragePos(Structure):
891 _fields_ = []
892 893 # Sequence
894 -class CvSeq(Structure):
895 _fields_ = [("flags", c_int), 896 ("header_size", c_int), 897 ("h_prev", c_void_p), 898 ("h_next", c_void_p), 899 ("v_prev", c_void_p), 900 ("v_next", c_void_p), 901 ("total", c_int), 902 ("elem_size", c_int), 903 ("block_max", c_void_p), 904 ("ptr", c_void_p), 905 ("delta_elems", c_int), 906 ("storage", POINTER(CvMemStorage)), 907 ("free_blocks", c_void_p), 908 ("first", c_void_p)] 909
910 - def hrange(self):
911 """ 912 generator function iterating along h_next 913 """ 914 s = self 915 t = type(self) 916 while s: 917 yield s 918 s = ctypes.cast(s.h_next , POINTER(CvSeq))
919
920 -class CvSeqBlock(Structure):
921 _fields_ = []
922
923 -class CvSeqWriter(Structure):
924 _fields_ = []
925
926 -class CvSeqReader(Structure):
927 _fields_ = []
928 929 # File storage
930 -class CvFileStorage(Structure):
931 _fields_ = []
932 933 # not implemented yet
934 -class CvSparseMat(Structure):
935 _fields_ = []
936
937 -class CvContourScanner(Structure):
938 _fields_ = []
939
940 -class CvHistogram(Structure):
941 _fields_ = [('type', c_int), 942 ('bins', c_void_p)]
943
944 -class CvString(Structure):
945 _fields_ = []
946
947 -class CvSlice(Structure):
948 _fields_ = [('start_index', c_int), 949 ('end_index', c_int)]
950
951 -class CvSET(Structure):
952 _fields_ = []
953
954 -class CvGraph(Structure):
955 _fields_ = []
956
957 -class CvGraphEdge(Structure):
958 _fields_ = []
959
960 -class CvGraphScanner(Structure):
961 _fields_ = []
962
963 -class CvFileNode(Structure):
964 _fields_ = []
965
966 -class CvStringHashNode(Structure):
967 _fields_ = []
968
969 -class CvTypeInfo(Structure):
970 _fields_ = []
971
972 -class CvContourTree(Structure):
973 _fields_ = []
974
975 -class CvBox2D(_Structure):
976 _fields_ = [('center', CvPoint2D32f), 977 ('size', CvSize2D32f), 978 ('angle', c_float)]
979
980 -class CvSubdiv2DPoint(Structure):
981 _fields_ = []
982
983 -class CvSubdiv2DPointLocation(Structure):
984 _fields_ = []
985
986 -class CvKalman(Structure):
987 _fields_ = []
988
989 -class CvConDensation(Structure):
990 _fields_ = []
991
992 -class CvHaarClassifierCascade(Structure):
993 _fields_ = []
994
995 -class CvPOSITObject(Structure):
996 _fields_ = []
997
998 -class CvMatr32f(Structure):
999 _fields_ = []
1000
1001 -class CvVect32f(Structure):
1002 _fields_ = []
1003
1004 -class CvCapture(Structure):
1005 _fields_ = []
1006
1007 -class CvVideoWriter(Structure):
1008 _fields_ = []
1009
1010 -class CvSetElem(Structure):
1011 _fields_ = []
1012
1013 -class CvGraphVtx(Structure):
1014 _fields_ = []
1015
1016 -class CvTreeNodeIterator(Structure):
1017 _fields_ = []
1018
1019 -class CvFont(Structure):
1020 _fields_ = []
1021
1022 -class CvLineIterator(Structure):
1023 _fields_ = []
1024
1025 -class CvModuleInfo(Structure):
1026 _fields_ = []
1027
1028 -class IplConvKernel(Structure):
1029 _fields_ = []
1030
1031 -class CvConnectedComp(_Structure):
1032 _fields_ = [('area', c_double), 1033 ('value', CvScalar), 1034 ('rect', CvRect), 1035 ('contour', POINTER(CvSeq))]
1036
1037 -class CvMOMENTS(Structure):
1038 _fields_ = []
1039
1040 -class CvHuMoments(Structure):
1041 _fields_ = []
1042
1043 -class CvChain(Structure):
1044 _fields_ = []
1045
1046 -class CvChainPtReader(Structure):
1047 _fields_ = []
1048 1049 #Added the fields for contour - Start
1050 -class CvContour(Structure):
1051 _fields_ = [("flags", c_int), 1052 ("header_size", c_int), 1053 ("h_prev", c_void_p), 1054 ("h_next", POINTER(CvSeq)), 1055 ("v_prev", c_void_p), 1056 ("v_next", c_void_p), 1057 ("total", c_int), 1058 ("elem_size", c_int), 1059 ("block_max", c_void_p), 1060 ("ptr", c_void_p), 1061 ("delta_elems", c_int), 1062 ("storage", POINTER(CvMemStorage)), 1063 ("free_blocks", c_void_p), 1064 ("first", c_void_p), 1065 ('rect', CvRect), 1066 ("color", c_int), 1067 ("reserved", c_int * 3)]
1068 #Added the fields for contour - End - Viji - Apr 19, 2007 1069
1070 -class CvCmpFunc(Structure):
1071 _fields_ = []
1072
1073 -class CvDistanceFunction(Structure):
1074 _fields_ = []
1075
1076 -class CvSubdiv2D(Structure):
1077 _fields_ = []
1078
1079 -class CvSubdiv2DEdge(Structure):
1080 _fields_ = []
1081 1082 1083 # --- 1 Operations on Arrays ------------------------------------------------- 1084 1085 # --- 1.1 Initialization ----------------------------------------------------- 1086 1087 # Creates header and allocates data 1088 cvCreateImage = cfunc('cvCreateImage', _cxDLL, POINTER(IplImage), 1089 ('size', CvSize, 1), # CvSize size 1090 ('depth', c_int, 1), # int depth 1091 ('channels', c_int, 1), # int channels 1092 ) 1093 1094 # Allocates, initializes, and returns structure IplImage 1095 cvCreateImageHeader = cfunc('cvCreateImageHeader', _cxDLL, POINTER(IplImage), 1096 ('size', CvSize, 1), # CvSize size 1097 ('depth', c_int, 1), # int depth 1098 ('channels', c_int, 1), # int channels 1099 ) 1100 1101 # Releases header 1102 cvReleaseImageHeader = cfunc('cvReleaseImageHeader', _cxDLL, None, 1103 ('image', ByRefArg(POINTER(IplImage)), 1), # IplImage** image 1104 ) 1105 1106 # Releases header and image data 1107 cvReleaseImage = cfunc('cvReleaseImage', _cxDLL, None, 1108 ('image', ByRefArg(POINTER(IplImage)), 1), # IplImage** image 1109 ) 1110 1111 # Initializes allocated by user image header 1112 cvInitImageHeader = cfunc('cvInitImageHeader', _cxDLL, POINTER(IplImage), 1113 ('image', POINTER(IplImage), 1), # IplImage* image 1114 ('size', CvSize, 1), # CvSize size 1115 ('depth', c_int, 1), # int depth 1116 ('channels', c_int, 1), # int channels 1117 ('origin', c_int, 1, 0), # int origin 1118 ('align', c_int, 1, 4), # int align 1119 ) 1120 1121 # Makes a full copy of image 1122 cvCloneImage = cfunc('cvCloneImage', _cxDLL, POINTER(IplImage), 1123 ('image', POINTER(IplImage), 1), # const IplImage* image 1124 ) 1125 1126 # Sets channel of interest to given value 1127 cvSetImageCOI = cfunc('cvSetImageCOI', _cxDLL, None, 1128 ('image', POINTER(IplImage), 1), # IplImage* image 1129 ('coi', c_int, 1), # int coi 1130 ) 1131 1132 # Returns index of channel of interest 1133 cvGetImageCOI = cfunc('cvGetImageCOI', _cxDLL, c_int, 1134 ('image', POINTER(IplImage), 1), # const IplImage* image 1135 ) 1136 1137 # Sets image ROI to given rectangle 1138 cvSetImageROI = cfunc('cvSetImageROI', _cxDLL, None, 1139 ('image', POINTER(IplImage), 1), # IplImage* image 1140 ('rect', CvRect, 1), # CvRect rect 1141 ) 1142 1143 # Releases image ROI 1144 cvResetImageROI = cfunc('cvResetImageROI', _cxDLL, None, 1145 ('image', POINTER(IplImage), 1), # IplImage* image 1146 ) 1147 1148 # Returns image ROI coordinates 1149 cvGetImageROI = cfunc('cvGetImageROI', _cxDLL, CvRect, 1150 ('image', POINTER(IplImage), 1), # const IplImage* image 1151 ) 1152 1153 # Creates new matrix 1154 cvCreateMat = cfunc('cvCreateMat', _cxDLL, POINTER(CvMat), 1155 ('rows', c_int, 1), # int rows 1156 ('cols', c_int, 1), # int cols 1157 ('type', c_int, 1), # int type 1158 ) 1159 1160 # Creates new matrix header 1161 cvCreateMatHeader = cfunc('cvCreateMatHeader', _cxDLL, POINTER(CvMat), 1162 ('rows', c_int, 1), # int rows 1163 ('cols', c_int, 1), # int cols 1164 ('type', c_int, 1), # int type 1165 ) 1166 1167 # Deallocates matrix 1168 cvReleaseMat = cfunc('cvReleaseMat', _cxDLL, None, 1169 ('mat', ByRefArg(POINTER(CvMat)), 1), # CvMat** mat 1170 ) 1171 1172 # Initializes matrix header 1173 cvInitMatHeader = cfunc('cvInitMatHeader', _cxDLL, POINTER(CvMat), 1174 ('mat', POINTER(CvMat), 1), # CvMat* mat 1175 ('rows', c_int, 1), # int rows 1176 ('cols', c_int, 1), # int cols 1177 ('type', c_int, 1), # int type 1178 ('data', c_void_p, 1, None), # void* data 1179 ('step', c_int, 1), # int step 1180 ) 1181 1182 # Creates matrix copy 1183 cvCloneMat = cfunc('cvCloneMat', _cxDLL, POINTER(CvMat), 1184 ('mat', POINTER(CvMat), 1), # const CvMat* mat 1185 ) 1186 1187 # Creates multi-dimensional dense array 1188 cvCreateMatND = cfunc('cvCreateMatND', _cxDLL, POINTER(CvMatND), 1189 ('dims', c_int, 1), # int dims 1190 ('sizes', POINTER(c_int), 1), # const int* sizes 1191 ('type', c_int, 1), # int type 1192 ) 1193 1194 # Creates new matrix header 1195 cvCreateMatNDHeader = cfunc('cvCreateMatNDHeader', _cxDLL, POINTER(CvMatND), 1196 ('dims', c_int, 1), # int dims 1197 ('sizes', POINTER(c_int), 1), # const int* sizes 1198 ('type', c_int, 1), # int type 1199 ) 1200 1201 # Initializes multi-dimensional array header 1202 cvInitMatNDHeader = cfunc('cvInitMatNDHeader', _cxDLL, POINTER(CvMatND), 1203 ('mat', POINTER(CvMatND), 1), # CvMatND* mat 1204 ('dims', c_int, 1), # int dims 1205 ('sizes', POINTER(c_int), 1), # const int* sizes 1206 ('type', c_int, 1), # int type 1207 ('data', c_void_p, 1, None), # void* data 1208 ) 1209 1210 # Creates full copy of multi-dimensional array 1211 cvCloneMatND = cfunc('cvCloneMatND', _cxDLL, POINTER(CvMatND), 1212 ('mat', POINTER(CvMatND), 1), # const CvMatND* mat 1213 ) 1214 1215 # Allocates array data 1216 cvCreateData = cfunc('cvCreateData', _cxDLL, None, 1217 ('arr', c_void_p, 1), # CvArr* arr 1218 ) 1219 1220 # Releases array data 1221 cvReleaseData = cfunc('cvReleaseData', _cxDLL, None, 1222 ('arr', c_void_p, 1), # CvArr* arr 1223 ) 1224 1225 # Assigns user data to the array header 1226 cvSetData = cfunc('cvSetData', _cxDLL, None, 1227 ('arr', c_void_p, 1), # CvArr* arr 1228 ('data', c_void_p, 1), # void* data 1229 ('step', c_int, 1), # int step 1230 ) 1231 1232 # Retrieves low-level information about the array 1233 cvGetRawData = cfunc('cvGetRawData', _cxDLL, None, 1234 ('arr', c_void_p, 1), # const CvArr* arr 1235 ('data', POINTER(POINTER(c_byte)), 1), # uchar** data 1236 ('step', POINTER(c_int), 1, None), # int* step 1237 ('roi_size', POINTER(CvSize), 1, None), # CvSize* roi_size 1238 ) 1239 1240 # Returns matrix header for arbitrary array 1241 cvGetMat = cfunc('cvGetMat', _cxDLL, POINTER(CvMat), 1242 ('arr', c_void_p, 1), # const CvArr* arr 1243 ('header', POINTER(CvMat), 1), # CvMat* header 1244 ('coi', POINTER(c_int), 1, None), # int* coi 1245 ('allowND', c_int, 1, 0), # int allowND 1246 ) 1247 1248 # Returns image header for arbitrary array 1249 cvGetImage = cfunc('cvGetImage', _cxDLL, POINTER(IplImage), 1250 ('arr', c_void_p, 1), # const CvArr* arr 1251 ('image_header', POINTER(IplImage), 1), # IplImage* image_header 1252 ) 1253 1254 # Creates sparse array 1255 cvCreateSparseMat = cfunc('cvCreateSparseMat', _cxDLL, POINTER(CvSparseMat), 1256 ('dims', c_int, 1), # int dims 1257 ('sizes', POINTER(c_int), 1), # const int* sizes 1258 ('type', c_int, 1), # int type 1259 ) 1260 1261 # Deallocates sparse array 1262 cvReleaseSparseMat = cfunc('cvReleaseSparseMat', _cxDLL, None, 1263 ('mat', ByRefArg(POINTER(CvSparseMat)), 1), # CvSparseMat** mat 1264 ) 1265 1266 # Creates full copy of sparse array 1267 cvCloneSparseMat = cfunc('cvCloneSparseMat', _cxDLL, POINTER(CvSparseMat), 1268 ('mat', POINTER(CvSparseMat), 1), # const CvSparseMat* mat 1269 ) 1270 1271 # --- 1.2 Accessing Elements and sub-Arrays ---------------------------------- 1272 1273 # Returns matrix header corresponding to the rectangular sub-array of input image or matrix 1274 cvGetSubRect = cfunc('cvGetSubRect', _cxDLL, POINTER(CvMat), 1275 ('arr', c_void_p, 1), # const CvArr* arr 1276 ('submat', POINTER(CvMat), 2), # CvMat* submat 1277 ('rect', CvRect, 1), # CvRect rect 1278 ) 1279 1280 # Returns array row or row span 1281 cvGetRows = cfunc('cvGetRows', _cxDLL, POINTER(CvMat), 1282 ('arr', c_void_p, 1), # const CvArr* arr 1283 ('submat', POINTER(CvMat), 1), # CvMat* submat 1284 ('start_row', c_int, 1), # int start_row 1285 ('end_row', c_int, 1), # int end_row 1286 ('delta_row', c_int, 1, 1), # int delta_row 1287 ) 1288 1289 # Returns array column or column span 1290 cvGetCols = cfunc('cvGetCols', _cxDLL, POINTER(CvMat), 1291 ('arr', c_void_p, 1), # const CvArr* arr 1292 ('submat', POINTER(CvMat), 1), # CvMat* submat 1293 ('start_col', c_int, 1), # int start_col 1294 ('end_col', c_int, 1), # int end_col 1295 ) 1296 1297 # Returns one of array diagonals 1298 cvGetDiag = cfunc('cvGetDiag', _cxDLL, POINTER(CvMat), 1299 ('arr', c_void_p, 1), # const CvArr* arr 1300 ('submat', POINTER(CvMat), 1), # CvMat* submat 1301 ('diag', c_int, 1, 0), # int diag 1302 ) 1303 1304 # Returns size of matrix or image ROI 1305 cvGetSize = cfunc('cvGetSize', _cxDLL, CvSize, 1306 ('arr', c_void_p, 1), # const CvArr* arr 1307 ) 1308 1309 ### Initializes sparse array elements iterator 1310 ##cvInitSparseMatIterator = _cxDLL.cvInitSparseMatIterator 1311 ##cvInitSparseMatIterator.restype = POINTER(CvSparseNode) # CvSparseNode* 1312 ##cvInitSparseMatIterator.argtypes = [ 1313 ## c_void_p, # const CvSparseMat* mat 1314 ## c_void_p # CvSparseMatIterator* mat_iterator 1315 ## ] 1316 ## 1317 ### Initializes sparse array elements iterator 1318 ##cvGetNextSparseNode = _cxDLL.cvGetNextSparseNode 1319 ##cvGetNextSparseNode.restype = POINTER(CvSparseNode) # CvSparseNode* 1320 ##cvGetNextSparseNode.argtypes = [ 1321 ## c_void_p # CvSparseMatIterator* mat_iterator 1322 ## ] 1323 1324 # Returns type of array elements 1325 cvGetElemType = cfunc('cvGetElemType', _cxDLL, c_int, 1326 ('arr', c_void_p, 1), # const CvArr* arr 1327 ) 1328 1329 # Return number of array dimensions and their sizes or the size of particular dimension 1330 cvGetDims = cfunc('cvGetDims', _cxDLL, c_int, 1331 ('arr', c_void_p, 1), # const CvArr* arr 1332 ('sizes', POINTER(c_int), 1, None), # int* sizes 1333 ) 1334 1335 cvGetDimSize = cfunc('cvGetDimSize', _cxDLL, c_int, 1336 ('arr', c_void_p, 1), # const CvArr* arr 1337 ('index', c_int, 1), # int index 1338 ) 1339 1340 # Return pointer to the particular array element 1341 cvPtr1D = cfunc('cvPtr1D', _cxDLL, c_void_p, 1342 ('arr', c_void_p, 1), # const CvArr* arr 1343 ('idx0', c_int, 1), # int idx0 1344 ('type', POINTER(c_int), 1, None), # int* type 1345 ) 1346 1347 cvPtr2D = cfunc('cvPtr2D', _cxDLL, c_void_p, 1348 ('arr', c_void_p, 1), # const CvArr* arr 1349 ('idx0', c_int, 1), # int idx0 1350 ('idx1', c_int, 1), # int idx1 1351 ('type', POINTER(c_int), 1, None), # int* type 1352 ) 1353 1354 cvPtr3D = cfunc('cvPtr3D', _cxDLL, c_void_p, 1355 ('arr', c_void_p, 1), # const CvArr* arr 1356 ('idx0', c_int, 1), # int idx0 1357 ('idx1', c_int, 1), # int idx1 1358 ('idx2', c_int, 1), # int idx2 1359 ('type', POINTER(c_int), 1, None), # int* type 1360 ) 1361 1362 cvPtrND = cfunc('cvPtrND', _cxDLL, c_void_p, 1363 ('arr', c_void_p, 1), # const CvArr* arr 1364 ('idx', POINTER(c_int), 1), # int* idx 1365 ('type', POINTER(c_int), 1, None), # int* type 1366 ('create_node', c_int, 1, 1), # int create_node 1367 ('precalc_hashval', POINTER(c_uint32), 1, None), # unsigned* precalc_hashval 1368 ) 1369 1370 # Return the particular array element 1371 cvGet1D = cfunc('cvGet1D', _cxDLL, CvScalar, 1372 ('arr', c_void_p, 1), # const CvArr* arr 1373 ('idx0', c_int, 1), # int idx0 1374 ) 1375 1376 cvGet2D = cfunc('cvGet2D', _cxDLL, CvScalar, 1377 ('arr', c_void_p, 1), # const CvArr* arr 1378 ('idx0', c_int, 1), # int idx0 1379 ('idx1', c_int, 1), # int idx1 1380 ) 1381 1382 cvGet3D = cfunc('cvGet3D', _cxDLL, CvScalar, 1383 ('arr', c_void_p, 1), # const CvArr* arr 1384 ('idx0', c_int, 1), # int idx0 1385 ('idx1', c_int, 1), # int idx1 1386 ('idx2', c_int, 1), # int idx2 1387 ) 1388 1389 cvGetND = cfunc('cvGetND', _cxDLL, CvScalar, 1390 ('arr', c_void_p, 1), # const CvArr* arr 1391 ('idx', POINTER(c_int), 1), # int* idx 1392 ) 1393 1394 # Return the particular element of single-channel array 1395 cvGetReal1D = cfunc('cvGetReal1D', _cxDLL, c_double, 1396 ('arr', c_void_p, 1), # const CvArr* arr 1397 ('idx0', c_int, 1), # int idx0 1398 ) 1399 1400 cvGetReal2D = cfunc('cvGetReal2D', _cxDLL, c_double, 1401 ('arr', c_void_p, 1), # const CvArr* arr 1402 ('idx0', c_int, 1), # int idx0 1403 ('idx1', c_int, 1), # int idx1 1404 ) 1405 1406 cvGetReal3D = cfunc('cvGetReal3D', _cxDLL, c_double, 1407 ('arr', c_void_p, 1), # const CvArr* arr 1408 ('idx0', c_int, 1), # int idx0 1409 ('idx1', c_int, 1), # int idx1 1410 ('idx2', c_int, 1), # int idx2 1411 ) 1412 1413 cvGetRealND = cfunc('cvGetRealND', _cxDLL, c_double, 1414 ('arr', c_void_p, 1), # const CvArr* arr 1415 ('idx', POINTER(c_int), 1), # int* idx 1416 ) 1417 1418 # Change the particular array element 1419 cvSet1D = cfunc('cvSet1D', _cxDLL, None, 1420 ('arr', c_void_p, 1), # CvArr* arr 1421 ('idx0', c_int, 1), # int idx0 1422 ('value', CvScalar, 1), # CvScalar value 1423 ) 1424 1425 cvSet2D = cfunc('cvSet2D', _cxDLL, None, 1426 ('arr', c_void_p, 1), # CvArr* arr 1427 ('idx0', c_int, 1), # int idx0 1428 ('idx1', c_int, 1), # int idx1 1429 ('value', CvScalar, 1), # CvScalar value 1430 ) 1431 1432 cvSet3D = cfunc('cvSet3D', _cxDLL, None, 1433 ('arr', c_void_p, 1), # CvArr* arr 1434 ('idx0', c_int, 1), # int idx0 1435 ('idx1', c_int, 1), # int idx1 1436 ('idx2', c_int, 1), # int idx2 1437 ('value', CvScalar, 1), # CvScalar value 1438 ) 1439 1440 cvSetND = cfunc('cvSetND', _cxDLL, None, 1441 ('arr', c_void_p, 1), # CvArr* arr 1442 ('idx', POINTER(c_int), 1), # int* idx 1443 ('value', CvScalar, 1), # CvScalar value 1444 ) 1445 1446 # Change the particular array element 1447 cvSetReal1D = cfunc('cvSetReal1D', _cxDLL, None, 1448 ('arr', c_void_p, 1), # CvArr* arr 1449 ('idx0', c_int, 1), # int idx0 1450 ('value', c_double, 1), # double value 1451 ) 1452 1453 cvSetReal2D = cfunc('cvSetReal2D', _cxDLL, None, 1454 ('arr', c_void_p, 1), # CvArr* arr 1455 ('idx0', c_int, 1), # int idx0 1456 ('idx1', c_int, 1), # int idx1 1457 ('value', c_double, 1), # double value 1458 ) 1459 1460 cvSetReal3D = cfunc('cvSetReal3D', _cxDLL, None, 1461 ('arr', c_void_p, 1), # CvArr* arr 1462 ('idx0', c_int, 1), # int idx0 1463 ('idx1', c_int, 1), # int idx1 1464 ('idx2', c_int, 1), # int idx2 1465 ('value', c_double, 1), # double value 1466 ) 1467 1468 cvSetRealND = cfunc('cvSetRealND', _cxDLL, None, 1469 ('arr', c_void_p, 1), # CvArr* arr 1470 ('idx', POINTER(c_int), 1), # int* idx 1471 ('value', c_double, 1), # double value 1472 ) 1473 1474 # Clears the particular array element 1475 cvClearND = cfunc('cvClearND', _cxDLL, None, 1476 ('arr', c_void_p, 1), # CvArr* arr 1477 ('idx', POINTER(c_int), 1), # int* idx 1478 ) 1479 1480 # --- 1.3 Copying and Filling ------------------------------------------------ 1481 1482 # Copies one array to another 1483 cvCopy = cfunc('cvCopy', _cxDLL, None, 1484 ('src', c_void_p, 1), # const CvArr* src 1485 ('dst', c_void_p, 1), # CvArr* dst 1486 ('mask', c_void_p, 1, None), # const CvArr* mask 1487 ) 1488 1489 # Sets every element of array to given value 1490 cvSet = cfunc('cvSet', _cxDLL, None, 1491 ('arr', c_void_p, 1), # CvArr* arr 1492 ('value', CvScalar, 1), # CvScalar value 1493 ('mask', c_void_p, 1, None), # const CvArr* mask 1494 ) 1495 1496 # Clears the array 1497 cvSetZero = cfunc('cvSetZero', _cxDLL, None, 1498 ('arr', c_void_p, 1), # CvArr* arr 1499 ) 1500 1501 cvZero = cvSetZero 1502 1503 # --- 1.4 Transforms and Permutations ---------------------------------------- 1504 1505 # Changes shape of matrix/image without copying data 1506 cvReshape = cfunc('cvReshape', _cxDLL, POINTER(CvMat), 1507 ('arr', c_void_p, 1), # const CvArr* arr 1508 ('header', POINTER(CvMat), 1), # CvMat* header 1509 ('new_cn', c_int, 1), # int new_cn 1510 ('new_rows', c_int, 1, 0), # int new_rows 1511 ) 1512 1513 # Changes shape of multi-dimensional array w/o copying data 1514 cvReshapeMatND = cfunc('cvReshapeMatND', _cxDLL, c_void_p, 1515 ('arr', c_void_p, 1), # const CvArr* arr 1516 ('sizeof_header', c_int, 1), # int sizeof_header 1517 ('header', c_void_p, 1), # CvArr* header 1518 ('new_cn', c_int, 1), # int new_cn 1519 ('new_dims', c_int, 1), # int new_dims 1520 ('new_sizes', POINTER(c_int), 1), # int* new_sizes 1521 ) 1522 1523 # Fill destination array with tiled source array 1524 cvRepeat = cfunc('cvRepeat', _cxDLL, None, 1525 ('src', c_void_p, 1), # const CvArr* src 1526 ('dst', c_void_p, 1), # CvArr* dst 1527 ) 1528 1529 # Flip a 2D array around vertical, horizontall or both axises 1530 cvFlip = cfunc('cvFlip', _cxDLL, None, 1531 ('src', c_void_p, 1), # const CvArr* src 1532 ('dst', c_void_p, 1, None), # CvArr* dst 1533 ('flip_mode', c_int, 1, 0), # int flip_mode 1534 ) 1535 1536 # Divides multi-channel array into several single-channel arrays or extracts a single channel from the array 1537 cvSplit = cfunc('cvSplit', _cxDLL, None, 1538 ('src', c_void_p, 1), # const CvArr* src 1539 ('dst0', c_void_p, 1, None), # CvArr* dst0 1540 ('dst1', c_void_p, 1, None), # CvArr* dst1 1541 ('dst2', c_void_p, 1, None), # CvArr* dst2 1542 ('dst3', c_void_p, 1, None), # CvArr* dst3 1543 ) 1544 1545 # Composes multi-channel array from several single-channel arrays or inserts a single channel into the array 1546 cvMerge = cfunc('cvMerge', _cxDLL, None, 1547 ('src0', c_void_p, 1), # const CvArr* src0 1548 ('src1', c_void_p, 1), # const CvArr* src1 1549 ('src2', c_void_p, 1), # const CvArr* src2 1550 ('src3', c_void_p, 1), # const CvArr* src3 1551 ('dst', c_void_p, 1), # CvArr* dst 1552 ) 1553 1554 # --- 1.5 Arithmetic, Logic and Comparison ----------------------------------- 1555 1556 # Performs look-up table transform of array 1557 cvLUT = cfunc('cvLUT', _cxDLL, None, 1558 ('src', c_void_p, 1), # const CvArr* src 1559 ('dst', c_void_p, 1), # CvArr* dst 1560 ('lut', c_void_p, 1), # const CvArr* lut 1561 ) 1562 1563 # Converts one array to another with optional linear transformation 1564 cvConvertScale = cfunc('cvConvertScale', _cxDLL, None, 1565 ('src', c_void_p, 1), # const CvArr* src 1566 ('dst', c_void_p, 1), # CvArr* dst 1567 ('scale', c_double, 1, 1), # double scale 1568 ('shift', c_double, 1, 0), # double shift 1569 ) 1570 1571 cvCvtScale = cvConvertScale 1572 1573 cvScale = cvConvertScale 1574
1575 -def cvConvert(src, dst):
1576 cvConvertScale(src, dst, 1, 0)
1577 1578 # Converts input array elements to 8-bit unsigned integer another with optional linear transformation 1579 cvConvertScaleAbs = cfunc('cvConvertScaleAbs', _cxDLL, None, 1580 ('src', c_void_p, 1), # const CvArr* src 1581 ('dst', c_void_p, 1), # CvArr* dst 1582 ('scale', c_double, 1, 1), # double scale 1583 ('shift', c_double, 1, 0), # double shift 1584 ) 1585 1586 cvCvtScaleAbs = cvConvertScaleAbs 1587 1588 # Computes per-element sum of two arrays 1589 cvAdd = cfunc('cvAdd', _cxDLL, None, 1590 ('src1', c_void_p, 1), # const CvArr* src1 1591 ('src2', c_void_p, 1), # const CvArr* src2 1592 ('dst', c_void_p, 1), # CvArr* dst 1593 ('mask', c_void_p, 1, None), # const CvArr* mask 1594 ) 1595 1596 # Computes sum of array and scalar 1597 cvAddS = cfunc('cvAddS', _cxDLL, None, 1598 ('src', c_void_p, 1), # const CvArr* src 1599 ('value', CvScalar, 1), # CvScalar value 1600 ('dst', c_void_p, 1), # CvArr* dst 1601 ('mask', c_void_p, 1, None), # const CvArr* mask 1602 ) 1603 1604 # Computes weighted sum of two arrays 1605 cvAddWeighted = cfunc('cvAddWeighted', _cxDLL, None, 1606 ('src1', c_void_p, 1), # const CvArr* src1 1607 ('alpha', c_double, 1), # double alpha 1608 ('src2', c_void_p, 1), # const CvArr* src2 1609 ('beta', c_double, 1), # double beta 1610 ('gamma', c_double, 1), # double gamma 1611 ('dst', c_void_p, 1), # CvArr* dst 1612 ) 1613 1614 # Computes per-element difference between two arrays 1615 cvSub = cfunc('cvSub', _cxDLL, None, 1616 ('src1', c_void_p, 1), # const CvArr* src1 1617 ('src2', c_void_p, 1), # const CvArr* src2 1618 ('dst', c_void_p, 1), # CvArr* dst 1619 ('mask', c_void_p, 1, None), # const CvArr* mask 1620 ) 1621 1622 # Computes difference between scalar and array 1623 cvSubRS = cfunc('cvSubRS', _cxDLL, None, 1624 ('src', c_void_p, 1), # const CvArr* src 1625 ('value', CvScalar, 1), # CvScalar value 1626 ('dst', c_void_p, 1), # CvArr* dst 1627 ('mask', c_void_p, 1, None), # const CvArr* mask 1628 ) 1629 1630 # Calculates per-element product of two arrays 1631 cvMul = cfunc('cvMul', _cxDLL, None, 1632 ('src1', c_void_p, 1), # const CvArr* src1 1633 ('src2', c_void_p, 1), # const CvArr* src2 1634 ('dst', c_void_p, 1), # CvArr* dst 1635 ('scale', c_double, 1, 1), # double scale 1636 ) 1637 1638 # Performs per-element division of two arrays 1639 cvDiv = cfunc('cvDiv', _cxDLL, None, 1640 ('src1', c_void_p, 1), # const CvArr* src1 1641 ('src2', c_void_p, 1), # const CvArr* src2 1642 ('dst', c_void_p, 1), # CvArr* dst 1643 ('scale', c_double, 1, 1), # double scale 1644 ) 1645 1646 # Calculates per-element bit-wise conjunction of two arrays 1647 cvAnd = cfunc('cvAnd', _cxDLL, None, 1648 ('src1', c_void_p, 1), # const CvArr* src1 1649 ('src2', c_void_p, 1), # const CvArr* src2 1650 ('dst', c_void_p, 1), # CvArr* dst 1651 ('mask', c_void_p, 1, None), # const CvArr* mask 1652 ) 1653 1654 # Calculates per-element bit-wise conjunction of array and scalar 1655 cvAndS = cfunc('cvAndS', _cxDLL, None, 1656 ('src', c_void_p, 1), # const CvArr* src 1657 ('value', CvScalar, 1), # CvScalar value 1658 ('dst', c_void_p, 1), # CvArr* dst 1659 ('mask', c_void_p, 1, None), # const CvArr* mask 1660 ) 1661 1662 # Calculates per-element bit-wise disjunction of two arrays 1663 cvOr = cfunc('cvOr', _cxDLL, None, 1664 ('src1', c_void_p, 1), # const CvArr* src1 1665 ('src2', c_void_p, 1), # const CvArr* src2 1666 ('dst', c_void_p, 1), # CvArr* dst 1667 ('mask', c_void_p, 1, None), # const CvArr* mask 1668 ) 1669 1670 # Calculates per-element bit-wise disjunction of array and scalar 1671 cvOrS = cfunc('cvOrS', _cxDLL, None, 1672 ('src', c_void_p, 1), # const CvArr* src 1673 ('value', CvScalar, 1), # CvScalar value 1674 ('dst', c_void_p, 1), # CvArr* dst 1675 ('mask', c_void_p, 1, None), # const CvArr* mask 1676 ) 1677 1678 # Performs per-element bit-wise "exclusive or" operation on two arrays 1679 cvXor = cfunc('cvXor', _cxDLL, None, 1680 ('src1', c_void_p, 1), # const CvArr* src1 1681 ('src2', c_void_p, 1), # const CvArr* src2 1682 ('dst', c_void_p, 1), # CvArr* dst 1683 ('mask', c_void_p, 1, None), # const CvArr* mask 1684 ) 1685 1686 # Performs per-element bit-wise "exclusive or" operation on array and scalar 1687 cvXorS = cfunc('cvXorS', _cxDLL, None, 1688 ('src', c_void_p, 1), # const CvArr* src 1689 ('value', CvScalar, 1), # CvScalar value 1690 ('dst', c_void_p, 1), # CvArr* dst 1691 ('mask', c_void_p, 1, None), # const CvArr* mask 1692 ) 1693 1694 # Performs per-element bit-wise inversion of array elements 1695 cvNot = cfunc('cvNot', _cxDLL, None, 1696 ('src', c_void_p, 1), # const CvArr* src 1697 ('dst', c_void_p, 1), # CvArr* dst 1698 ) 1699 1700 # Performs per-element comparison of two arrays 1701 cvCmp = cfunc('cvCmp', _cxDLL, None, 1702 ('src1', c_void_p, 1), # const CvArr* src1 1703 ('src2', c_void_p, 1), # const CvArr* src2 1704 ('dst', c_void_p, 1), # CvArr* dst 1705 ('cmp_op', c_int, 1), # int cmp_op 1706 ) 1707 1708 # Performs per-element comparison of array and scalar 1709 cvCmpS = cfunc('cvCmpS', _cxDLL, None, 1710 ('src', c_void_p, 1), # const CvArr* src 1711 ('value', c_double, 1), # double value 1712 ('dst', c_void_p, 1), # CvArr* dst 1713 ('cmp_op', c_int, 1), # int cmp_op 1714 ) 1715 1716 # Checks that array elements lie between elements of two other arrays 1717 cvInRange = cfunc('cvInRange', _cxDLL, None, 1718 ('src', c_void_p, 1), # const CvArr* src 1719 ('lower', c_void_p, 1), # const CvArr* lower 1720 ('upper', c_void_p, 1), # const CvArr* upper 1721 ('dst', c_void_p, 1), # CvArr* dst 1722 ) 1723 1724 # Checks that array elements lie between two scalars 1725 cvInRangeS = cfunc('cvInRangeS', _cxDLL, None, 1726 ('src', c_void_p, 1), # const CvArr* src 1727 ('lower', CvScalar, 1), # CvScalar lower 1728 ('upper', CvScalar, 1), # CvScalar upper 1729 ('dst', c_void_p, 1), # CvArr* dst 1730 ) 1731 1732 # Finds per-element maximum of two arrays 1733 cvMax = cfunc('cvMax', _cxDLL, None, 1734 ('src1', c_void_p, 1), # const CvArr* src1 1735 ('src2', c_void_p, 1), # const CvArr* src2 1736 ('dst', c_void_p, 1), # CvArr* dst 1737 ) 1738 1739 # Finds per-element maximum of array and scalar 1740 cvMaxS = cfunc('cvMaxS', _cxDLL, None, 1741 ('src', c_void_p, 1), # const CvArr* src 1742 ('value', c_double, 1), # double value 1743 ('dst', c_void_p, 1), # CvArr* dst 1744 ) 1745 1746 # Finds per-element minimum of two arrays 1747 cvMin = cfunc('cvMin', _cxDLL, None, 1748 ('src1', c_void_p, 1), # const CvArr* src1 1749 ('src2', c_void_p, 1), # const CvArr* src2 1750 ('dst', c_void_p, 1), # CvArr* dst 1751 ) 1752 1753 # Finds per-element minimum of array and scalar 1754 cvMinS = cfunc('cvMinS', _cxDLL, None, 1755 ('src', c_void_p, 1), # const CvArr* src 1756 ('value', c_double, 1), # double value 1757 ('dst', c_void_p, 1), # CvArr* dst 1758 ) 1759 1760 # Calculates absolute difference between two arrays 1761 cvAbsDiff = cfunc('cvAbsDiff', _cxDLL, None, 1762 ('src1', c_void_p, 1), # const CvArr* src1 1763 ('src2', c_void_p, 1), # const CvArr* src2 1764 ('dst', c_void_p, 1), # CvArr* dst 1765 ) 1766 1767 # Calculates absolute difference between array and scalar 1768 cvAbsDiffS = cfunc('cvAbsDiffS', _cxDLL, None, 1769 ('src', c_void_p, 1), # const CvArr* src 1770 ('dst', c_void_p, 1), # CvArr* dst 1771 ('value', CvScalar, 1), # CvScalar value 1772 ) 1773
1774 -def cvAbs(src, dst):
1775 value = CvScalar() 1776 value.val[0] = 0.0 1777 value.val[1] = 0.0 1778 value.val[2] = 0.0 1779 value.val[3] = 0.0 1780 cvAbsDiffS(src, dst, value)
1781 1782 # --- 1.6 Statistics --------------------------------------------------------- 1783 1784 # Counts non-zero array elements 1785 cvCountNonZero = cfunc('cvCountNonZero', _cxDLL, c_int, 1786 ('arr', c_void_p, 1), # const CvArr* arr 1787 ) 1788 1789 # Summarizes array elements 1790 cvSum = cfunc('cvSum', _cxDLL, CvScalar, 1791 ('arr', c_void_p, 1), # const CvArr* arr 1792 ) 1793 1794 # Calculates average (mean) of array elements 1795 cvAvg = cfunc('cvAvg', _cxDLL, CvScalar, 1796 ('arr', c_void_p, 1), # const CvArr* arr 1797 ('mask', c_void_p, 1, None), # const CvArr* mask 1798 ) 1799 1800 # Calculates average (mean) of array elements 1801 cvAvgSdv = cfunc('cvAvgSdv', _cxDLL, None, 1802 ('arr', c_void_p, 1), # const CvArr* arr 1803 ('mean', POINTER(CvScalar), 1), # CvScalar* mean 1804 ('std_dev', POINTER(CvScalar), 1), # CvScalar* std_dev 1805 ('mask', c_void_p, 1, None), # const CvArr* mask 1806 ) 1807 1808 # Finds global minimum and maximum in array or subarray 1809 ## cvMinMaxLoc = _cxDLL.cvMinMaxLoc 1810 ## cvMinMaxLoc.restype = None # void 1811 ## cvMinMaxLoc.argtypes = [ 1812 ## c_void_p, # const CvArr* arr 1813 ## c_void_p, # double* min_val 1814 ## c_void_p, # double* max_val 1815 ## c_void_p, # CvPoint* min_loc=NULL 1816 ## c_void_p, # CvPoint* max_loc=NULL 1817 ## c_void_p # const CvArr* mask=NULL 1818 ## ] 1819 1820 cvMinMaxLoc = cfunc('cvMinMaxLoc', _cxDLL, None, 1821 ('image', POINTER(IplImage), 1), 1822 ('min_val', POINTER(c_double), 2), 1823 ('max_val', POINTER(c_double), 2), 1824 ('min_loc', POINTER(CvPoint), 2), 1825 ('max_loc', POINTER(CvPoint), 2), 1826 ('mask', c_void_p, 1, None)) 1827 1828 1829 # Calculates absolute array norm, absolute difference norm or relative difference norm 1830 cvNorm = cfunc('cvNorm', _cxDLL, c_double, 1831 ('arr1', c_void_p, 1), # const CvArr* arr1 1832 ('arr2', c_void_p, 1, None), # const CvArr* arr2 1833 ('norm_type', c_int, 1), # int norm_type 1834 ('mask', c_void_p, 1, None), # const CvArr* mask 1835 ) 1836 1837 # --- 1.7 Linear Algebra ----------------------------------------------------- 1838 1839 # Initializes scaled identity matrix 1840 cvSetIdentity = cfunc('cvSetIdentity', _cxDLL, None, 1841 ('mat', c_void_p, 1), # CvArr* mat 1842 ('value', CvScalar, 1), # CvScalar value 1843 ) 1844 1845 # Calculates dot product of two arrays in Euclidian metrics 1846 cvDotProduct = cfunc('cvDotProduct', _cxDLL, c_double, 1847 ('src1', c_void_p, 1), # const CvArr* src1 1848 ('src2', c_void_p, 1), # const CvArr* src2 1849 ) 1850 1851 # Calculates cross product of two 3D vectors 1852 cvCrossProduct = cfunc('cvCrossProduct', _cxDLL, None, 1853 ('src1', c_void_p, 1), # const CvArr* src1 1854 ('src2', c_void_p, 1), # const CvArr* src2 1855 ('dst', c_void_p, 1), # CvArr* dst 1856 ) 1857 1858 # Calculates sum of scaled array and another array 1859 cvScaleAdd = cfunc('cvScaleAdd', _cxDLL, None, 1860 ('src1', c_void_p, 1), # const CvArr* src1 1861 ('scale', CvScalar, 1), # CvScalar scale 1862 ('src2', c_void_p, 1), # const CvArr* src2 1863 ('dst', c_void_p, 1), # CvArr* dst 1864 ) 1865 1866 # Performs generalized matrix multiplication 1867 cvGEMM = cfunc('cvGEMM', _cxDLL, None, 1868 ('src1', c_void_p, 1), # const CvArr* src1 1869 ('src2', c_void_p, 1), # const CvArr* src2 1870 ('alpha', c_double, 1), # double alpha 1871 ('src3', c_void_p, 1), # const CvArr* src3 1872 ('beta', c_double, 1), # double beta 1873 ('dst', c_void_p, 1), # CvArr* dst 1874 ('tABC', c_int, 1, 0), # int tABC 1875 ) 1876
1877 -def cvMatMulAdd(src1, src2, src3, dst):
1878 cvGEMM(src1, src2, 1, src3, 1, dst, 0)
1879
1880 -def cvMatMul(src1, src2, dst):
1881 cvMatMulAdd(src1, src2, 0, dst)
1882 1883 # Performs matrix transform of every array element 1884 cvTransform = cfunc('cvTransform', _cxDLL, None, 1885 ('src', c_void_p, 1), # const CvArr* src 1886 ('dst', c_void_p, 1), # CvArr* dst 1887 ('transmat', POINTER(CvMat), 1), # const CvMat* transmat 1888 ('shiftvec', POINTER(CvMat), 1, None), # const CvMat* shiftvec 1889 ) 1890 1891 # Performs perspective matrix transform of vector array 1892 cvPerspectiveTransform = cfunc('cvPerspectiveTransform', _cxDLL, None, 1893 ('src', c_void_p, 1), # const CvArr* src 1894 ('dst', c_void_p, 1), # CvArr* dst 1895 ('mat', POINTER(CvMat), 1), # const CvMat* mat 1896 ) 1897 1898 # Calculates product of array and transposed array 1899 cvMulTransposed = cfunc('cvMulTransposed', _cxDLL, None, 1900 ('src', c_void_p, 1), # const CvArr* src 1901 ('dst', c_void_p, 1), # CvArr* dst 1902 ('order', c_int, 1), # int order 1903 ('delta', c_void_p, 1, None), # const CvArr* delta 1904 ) 1905 1906 # Returns trace of matrix 1907 cvTrace = cfunc('cvTrace', _cxDLL, CvScalar, 1908 ('mat', c_void_p, 1), # const CvArr* mat 1909 ) 1910 1911 # Transposes matrix 1912 cvTranspose = cfunc('cvTranspose', _cxDLL, None, 1913 ('src', c_void_p, 1), # const CvArr* src 1914 ('dst', c_void_p, 1), # CvArr* dst 1915 ) 1916 1917 # Returns determinant of matrix 1918 cvDet = cfunc('cvDet', _cxDLL, c_double, 1919 ('mat', c_void_p, 1), # const CvArr* mat 1920 ) 1921 1922 # Finds inverse or pseudo-inverse of matrix 1923 cvInvert = cfunc('cvInvert', _cxDLL, c_double, 1924 ('src', c_void_p, 1), # const CvArr* src 1925 ('dst', c_void_p, 1), # CvArr* dst 1926 ('method', c_int, 1), # int method 1927 ) 1928 1929 # Solves linear system or least-squares problem 1930 cvSolve = cfunc('cvSolve', _cxDLL, c_int, 1931 ('src1', c_void_p, 1), # const CvArr* src1 1932 ('src2', c_void_p, 1), # const CvArr* src2 1933 ('dst', c_void_p, 1), # CvArr* dst 1934 ('method', c_int, 1), # int method 1935 ) 1936 1937 # Performs singular value decomposition of real floating-point matrix 1938 cvSVD = cfunc('cvSVD', _cxDLL, None, 1939 ('A', c_void_p, 1), # CvArr* A 1940 ('W', c_void_p, 1), # CvArr* W 1941 ('U', c_void_p, 1, None), # CvArr* U 1942 ('V', c_void_p, 1, None), # CvArr* V 1943 ('flags', c_int, 1, 0), # int flags 1944 ) 1945 1946 # Performs singular value back substitution 1947 cvSVBkSb = cfunc('cvSVBkSb', _cxDLL, None, 1948 ('W', c_void_p, 1), # const CvArr* W 1949 ('U', c_void_p, 1), # const CvArr* U 1950 ('V', c_void_p, 1), # const CvArr* V 1951 ('B', c_void_p, 1), # const CvArr* B 1952 ('X', c_void_p, 1), # CvArr* X 1953 ('flags', c_int, 1), # int flags 1954 ) 1955 1956 # Computes eigenvalues and eigenvectors of symmetric matrix 1957 cvEigenVV = cfunc('cvEigenVV', _cxDLL, None, 1958 ('mat', c_void_p, 1), # CvArr* mat 1959 ('evects', c_void_p, 1), # CvArr* evects 1960 ('evals', c_void_p, 1), # CvArr* evals 1961 ('eps', c_double, 1, 0), # double eps 1962 ) 1963 1964 # Calculates covariation matrix of the set of vectors 1965 cvCalcCovarMatrix = cfunc('cvCalcCovarMatrix', _cxDLL, None, 1966 ('vects', POINTER(c_void_p), 1), # const CvArr** vects 1967 ('count', c_int, 1), # int count 1968 ('cov_mat', c_void_p, 1), # CvArr* cov_mat 1969 ('avg', c_void_p, 1), # CvArr* avg 1970 ('flags', c_int, 1), # int flags 1971 ) 1972 1973 # Calculates Mahalonobis distance between two vectors 1974 cvMahalanobis = cfunc('cvMahalanobis', _cxDLL, c_double, 1975 ('vec1', c_void_p, 1), # const CvArr* vec1 1976 ('vec2', c_void_p, 1), # const CvArr* vec2 1977 ('mat', c_void_p, 1), # CvArr* mat 1978 ) 1979 1980 # --- 1.8 Math Functions ----------------------------------------------------- 1981 1982 # Round to nearest integer
1983 -def cvRound(val):
1984 return int(val + 0.5)
1985 1986 # Calculates cubic root 1987 cvCbrt = cfunc('cvCbrt', _cxDLL, c_float, 1988 ('value', c_float, 1), # float value 1989 ) 1990 1991 # Calculates angle of 2D vector 1992 cvFastArctan = cfunc('cvFastArctan', _cxDLL, c_float, 1993 ('y', c_float, 1), # float y 1994 ('x', c_float, 1), # float x 1995 ) 1996 1997 # Calculates magnitude and/or angle of 2d vectors 1998 cvCartToPolar = cfunc('cvCartToPolar', _cxDLL, None, 1999 ('x', c_void_p, 1), # const CvArr* x 2000 ('y', c_void_p, 1), # const CvArr* y 2001 ('magnitude', c_void_p, 1), # CvArr* magnitude 2002 ('angle', c_void_p, 1, None), # CvArr* angle 2003 ('angle_in_degrees', c_int, 1, 0), # int angle_in_degrees 2004 ) 2005 2006 # Calculates cartesian coordinates of 2d vectors represented in polar form 2007 cvPolarToCart = cfunc('cvPolarToCart', _cxDLL, None, 2008 ('magnitude', c_void_p, 1), # const CvArr* magnitude 2009 ('angle', c_void_p, 1), # const CvArr* angle 2010 ('x', c_void_p, 1), # CvArr* x 2011 ('y', c_void_p, 1), # CvArr* y 2012 ('angle_in_degrees', c_int, 1, 0), # int angle_in_degrees 2013 ) 2014 2015 # Raises every array element to power 2016 cvPow = cfunc('cvPow', _cxDLL, None, 2017 ('src', c_void_p, 1), # const CvArr* src 2018 ('dst', c_void_p, 1), # CvArr* dst 2019 ('power', c_double, 1), # double power 2020 ) 2021 2022 # Calculates exponent of every array element 2023 cvExp = cfunc('cvExp', _cxDLL, None, 2024 ('src', c_void_p, 1), # const CvArr* src 2025 ('dst', c_void_p, 1), # CvArr* dst 2026 ) 2027 2028 # Calculates natural logarithm of every array element absolute value 2029 cvLog = cfunc('cvLog', _cxDLL, None, 2030 ('src', c_void_p, 1), # const CvArr* src 2031 ('dst', c_void_p, 1), # CvArr* dst 2032 ) 2033 2034 # Finds real roots of a cubic equation 2035 cvSolveCubic = cfunc('cvSolveCubic', _cxDLL, None, 2036 ('coeffs', c_void_p, 1), # const CvArr* coeffs 2037 ('roots', c_void_p, 1), # CvArr* roots 2038 ) 2039 2040 # --- 1.9 Random Number Generation ------------------------------------------- 2041 2042 # Fills array with random numbers and updates the RNG state 2043 cvRandArr = cfunc('cvRandArr', _cxDLL, None, 2044 ('rng', c_void_p, 1), # CvRNG* rng 2045 ('arr', c_void_p, 1), # CvArr* arr 2046 ('dist_type', c_int, 1), # int dist_type 2047 ('param1', CvScalar, 1), # CvScalar param1 2048 ('param2', CvScalar, 1), # CvScalar param2 2049 ) 2050 2051 # --- 1.10 Discrete Transforms ----------------------------------------------- 2052 2053 # Performs forward or inverse Discrete Fourier transform of 1D or 2D floating-point array 2054 CV_DXT_FORWARD = 0 2055 CV_DXT_INVERSE = 1 2056 CV_DXT_SCALE = 2 2057 CV_DXT_ROWS = 4 2058 CV_DXT_INV_SCALE = CV_DXT_SCALE | CV_DXT_INVERSE 2059 CV_DXT_INVERSE_SCALE = CV_DXT_INV_SCALE 2060 2061 cvDFT = cfunc('cvDFT', _cxDLL, None, 2062 ('src', c_void_p, 1), # const CvArr* src 2063 ('dst', c_void_p, 1), # CvArr* dst 2064 ('flags', c_int, 1), # int flags 2065 ('nonzero_rows', c_int, 1, 0), # int nonzero_rows 2066 ) 2067 2068 # Returns optimal DFT size for given vector size 2069 cvGetOptimalDFTSize = cfunc('cvGetOptimalDFTSize', _cxDLL, c_int, 2070 ('size0', c_int, 1), # int size0 2071 ) 2072 2073 # Performs per-element multiplication of two Fourier spectrums 2074 cvMulSpectrums = cfunc('cvMulSpectrums', _cxDLL, None, 2075 ('src1', c_void_p, 1), # const CvArr* src1 2076 ('src2', c_void_p, 1), # const CvArr* src2 2077 ('dst', c_void_p, 1), # CvArr* dst 2078 ('flags', c_int, 1), # int flags 2079 ) 2080 2081 # Performs forward or inverse Discrete Cosine transform of 1D or 2D floating-point array 2082 CV_DXT_FORWARD = 0 2083 CV_DXT_INVERSE = 1 2084 CV_DXT_ROWS = 4 2085 2086 cvDCT = cfunc('cvDCT', _cxDLL, None, 2087 ('src', c_void_p, 1), # const CvArr* src 2088 ('dst', c_void_p, 1), # CvArr* dst 2089 ('flags', c_int, 1), # int flags 2090 ) 2091 2092 # --- 2 Dynamic Structures --------------------------------------------------- 2093 2094 # --- 2.1 Memory Storages ---------------------------------------------------- 2095 2096 # Creates memory storage 2097 cvCreateMemStorage = cfunc('cvCreateMemStorage', _cxDLL, POINTER(CvMemStorage), 2098 ('block_size', c_int, 1, 0), # int block_size 2099 ) 2100 2101 # Creates child memory storage 2102 cvCreateChildMemStorage = cfunc('cvCreateChildMemStorage', _cxDLL, POINTER(CvMemStorage), 2103 ('parent', POINTER(CvMemStorage), 1), # CvMemStorage* parent 2104 ) 2105 2106 # Releases memory storage 2107 cvReleaseMemStorage = cfunc('cvReleaseMemStorage', _cxDLL, None, 2108 ('storage', POINTER(POINTER(CvMemStorage)), 1), # CvMemStorage** storage 2109 ) 2110 2111 # Clears memory storage 2112 cvClearMemStorage = cfunc('cvClearMemStorage', _cxDLL, None, 2113 ('storage', POINTER(CvMemStorage), 1), # CvMemStorage* storage 2114 ) 2115 2116 # Allocates memory buffer in the storage 2117 cvMemStorageAlloc = cfunc('cvMemStorageAlloc', _cxDLL, c_void_p, 2118 ('storage', POINTER(CvMemStorage), 1), # CvMemStorage* storage 2119 ('size', c_ulong, 1), # size_t size 2120 ) 2121 2122 # Allocates text string in the storage 2123 cvMemStorageAllocString = cfunc('cvMemStorageAllocString', _cxDLL, CvString, 2124 ('storage', POINTER(CvMemStorage), 1), # CvMemStorage* storage 2125 ('ptr', c_char_p, 1), # const char* ptr 2126 ('len', c_int, 1), # int len 2127 ) 2128 2129 # Saves memory storage position 2130 cvSaveMemStoragePos = cfunc('cvSaveMemStoragePos', _cxDLL, None, 2131 ('storage', POINTER(CvMemStorage), 1), # const CvMemStorage* storage 2132 ('pos', POINTER(CvMemStoragePos), 1), # CvMemStoragePos* pos 2133 ) 2134 2135 # Restores memory storage position 2136 cvRestoreMemStoragePos = cfunc('cvRestoreMemStoragePos', _cxDLL, None, 2137 ('storage', POINTER(CvMemStorage), 1), # CvMemStorage* storage 2138 ('pos', POINTER(CvMemStoragePos), 1), # CvMemStoragePos* pos 2139 ) 2140 2141 # --- 2.2 Sequences ---------------------------------------------------------- 2142 2143 # Creates sequence 2144 cvCreateSeq = cfunc('cvCreateSeq', _cxDLL, POINTER(CvSeq), 2145 ('seq_flags', c_int, 1), # int seq_flags 2146 ('header_size', c_int, 1), # int header_size 2147 ('elem_size', c_int, 1), # int elem_size 2148 ('storage', POINTER(CvMemStorage), 1), # CvMemStorage* storage 2149 ) 2150 2151 # Sets up sequence block size 2152 cvSetSeqBlockSize = cfunc('cvSetSeqBlockSize', _cxDLL, None, 2153 ('seq', POINTER(CvSeq), 1), # CvSeq* seq 2154 ('delta_elems', c_int, 1), # int delta_elems 2155 ) 2156 2157 # Adds element to sequence end 2158 cvSeqPush = cfunc('cvSeqPush', _cxDLL, c_void_p, 2159 ('seq', POINTER(CvSeq), 1), # CvSeq* seq 2160 ('element', c_void_p, 1, None), # void* element 2161 ) 2162 2163 # Removes element from sequence end 2164 cvSeqPop = cfunc('cvSeqPop', _cxDLL, None, 2165 ('seq', POINTER(CvSeq), 1), # CvSeq* seq 2166 ('element', c_void_p, 1, None), # void* element 2167 ) 2168 2169 # Adds element to sequence beginning 2170 cvSeqPushFront = cfunc('cvSeqPushFront', _cxDLL, c_void_p, 2171 ('seq', POINTER(CvSeq), 1), # CvSeq* seq 2172 ('element', c_void_p, 1, None), # void* element 2173 ) 2174 2175 # Removes element from sequence beginning 2176 cvSeqPopFront = cfunc('cvSeqPopFront', _cxDLL, None, 2177 ('seq', POINTER(CvSeq), 1), # CvSeq* seq 2178 ('element', c_void_p, 1, None), # void* element 2179 ) 2180 2181 # Pushes several elements to the either end of sequence 2182 cvSeqPushMulti = cfunc('cvSeqPushMulti', _cxDLL, None, 2183 ('seq', POINTER(CvSeq), 1), # CvSeq* seq 2184 ('elements', c_void_p, 1), # void* elements 2185 ('count', c_int, 1), # int count 2186 ('in_front', c_int, 1, 0), # int in_front 2187 ) 2188 2189 # Removes several elements from the either end of sequence 2190 cvSeqPopMulti = cfunc('cvSeqPopMulti', _cxDLL, None, 2191 ('seq', POINTER(CvSeq), 1), # CvSeq* seq 2192 ('elements', c_void_p, 1), # void* elements 2193 ('count', c_int, 1), # int count 2194 ('in_front', c_int, 1, 0), # int in_front 2195 ) 2196 2197 # Inserts element in sequence middle 2198 cvSeqInsert = cfunc('cvSeqInsert', _cxDLL, c_void_p, 2199 ('seq', POINTER(CvSeq), 1), # CvSeq* seq 2200 ('before_index', c_int, 1), # int before_index 2201 ('element', c_void_p, 1, None), # void* element 2202 ) 2203 2204 # Removes element from sequence middle 2205 cvSeqRemove = cfunc('cvSeqRemove', _cxDLL, None, 2206 ('seq', POINTER(CvSeq), 1), # CvSeq* seq 2207 ('index', c_int, 1), # int index 2208 ) 2209 2210 # Clears sequence 2211 cvClearSeq = cfunc('cvClearSeq', _cxDLL, None, 2212 ('seq', POINTER(CvSeq), 1), # CvSeq* seq 2213 ) 2214 2215 # Returns pointer to sequence element by its index 2216 cvGetSeqElem = cfunc('cvGetSeqElem', _cxDLL, c_void_p, 2217 ('seq', POINTER(CvSeq), 1), # const CvSeq* seq 2218 ('index', c_int, 1), # int index 2219 ) 2220
2221 -def CV_GET_SEQ_ELEM(TYPE, seq, index):
2222 result = cvGetSeqElem(seq) 2223 return cast(result, POINTER(TYPE))
2224 2225 # Returns index of concrete sequence element 2226 cvSeqElemIdx = cfunc('cvSeqElemIdx', _cxDLL, c_int, 2227 ('seq', POINTER(CvSeq), 1), # const CvSeq* seq 2228 ('element', c_void_p, 1), # const void* element 2229 ('block', POINTER(POINTER(CvSeqBlock)), 1, None), # CvSeqBlock** block 2230 ) 2231 2232 # Copies sequence to one continuous block of memory 2233 cvCvtSeqToArray = cfunc('cvCvtSeqToArray', _cxDLL, c_void_p, 2234 ('seq', POINTER(CvSeq), 1), # const CvSeq* seq 2235 ('elements', c_void_p, 1), # void* elements 2236 ('slice', CvSlice, 1), # CvSlice slice 2237 ) 2238 2239 # Constructs sequence from array 2240 cvMakeSeqHeaderForArray = cfunc('cvMakeSeqHeaderForArray', _cxDLL, POINTER(CvSeq), 2241 ('seq_type', c_int, 1), # int seq_type 2242 ('header_size', c_int, 1), # int header_size 2243 ('elem_size', c_int, 1), # int elem_size 2244 ('elements', c_void_p, 1), # void* elements 2245 ('total', c_int, 1), # int total 2246 ('seq', POINTER(CvSeq), 1), # CvSeq* seq 2247 ('block', POINTER(CvSeqBlock), 1), # CvSeqBlock* block 2248 ) 2249 2250 # Makes separate header for the sequence slice 2251 cvSeqSlice = cfunc('cvSeqSlice', _cxDLL, POINTER(CvSeq), 2252 ('seq', POINTER(CvSeq), 1), # const CvSeq* seq 2253 ('slice', CvSlice, 1), # CvSlice slice 2254 ('storage', POINTER(CvMemStorage), 1, None), # CvMemStorage* storage 2255 ('copy_data', c_int, 1, 0), # int copy_data 2256 ) 2257 2258 # Removes sequence slice 2259 cvSeqRemoveSlice = cfunc('cvSeqRemoveSlice', _cxDLL, None, 2260 ('seq', POINTER(CvSeq), 1), # CvSeq* seq 2261 ('slice', CvSlice, 1), # CvSlice slice 2262 ) 2263 2264 # Inserts array in the middle of sequence 2265 cvSeqInsertSlice = cfunc('cvSeqInsertSlice', _cxDLL, None, 2266 ('seq', POINTER(CvSeq), 1), # CvSeq* seq 2267 ('before_index', c_int, 1), # int before_index 2268 ('from_arr', c_void_p, 1), # const CvArr* from_arr 2269 ) 2270 2271 # Reverses the order of sequence elements 2272 cvSeqInvert = cfunc('cvSeqInvert', _cxDLL, None, 2273 ('seq', POINTER(CvSeq), 1), # CvSeq* seq 2274 ) 2275 2276 # a < b ? -1 : a > b ? 1 : 0 2277 CvCmpFunc = CFUNCTYPE(c_int, # int 2278 c_void_p, # const void* a 2279 c_void_p, # const void* b 2280 c_void_p) # void* userdata 2281 2282 # Sorts sequence element using the specified comparison function 2283 cvSeqSort = cfunc('cvSeqSort', _cxDLL, None, 2284 ('seq', POINTER(CvSeq), 1), # CvSeq* seq 2285 ('func', CvCmpFunc, 1), # CvCmpFunc func 2286 ('userdata', c_void_p, 1, None), # void* userdata 2287 ) 2288 2289 # Searches element in sequence 2290 cvSeqSearch = cfunc('cvSeqSearch', _cxDLL, c_void_p, 2291 ('seq', POINTER(CvSeq), 1), # CvSeq* seq 2292 ('elem', c_void_p, 1), # const void* elem 2293 ('func', CvCmpFunc, 1), # CvCmpFunc func 2294 ('is_sorted', c_int, 1), # int is_sorted 2295 ('elem_idx', POINTER(c_int), 1), # int* elem_idx 2296 ('userdata', c_void_p, 1, None), # void* userdata 2297 ) 2298 2299 # Initializes process of writing data to sequence 2300 cvStartAppendToSeq = cfunc('cvStartAppendToSeq', _cxDLL, None, 2301 ('seq', POINTER(CvSeq), 1), # CvSeq* seq 2302 ('writer', POINTER(CvSeqWriter), 1), # CvSeqWriter* writer 2303 ) 2304 2305 # Creates new sequence and initializes writer for it 2306 cvStartWriteSeq = cfunc('cvStartWriteSeq', _cxDLL, None, 2307 ('seq_flags', c_int, 1), # int seq_flags 2308 ('header_size', c_int, 1), # int header_size 2309 ('elem_size', c_int, 1), # int elem_size 2310 ('storage', POINTER(CvMemStorage), 1), # CvMemStorage* storage 2311 ('writer', POINTER(CvSeqWriter), 1), # CvSeqWriter* writer 2312 ) 2313 2314 # Finishes process of writing sequence 2315 cvEndWriteSeq = cfunc('cvEndWriteSeq', _cxDLL, POINTER(CvSeq), 2316 ('writer', POINTER(CvSeqWriter), 1), # CvSeqWriter* writer 2317 ) 2318 2319 # Updates sequence headers from the writer state 2320 cvFlushSeqWriter = cfunc('cvFlushSeqWriter', _cxDLL, None, 2321 ('writer', POINTER(CvSeqWriter), 1), # CvSeqWriter* writer 2322 ) 2323 2324 # Initializes process of sequential reading from sequence 2325 cvStartReadSeq = cfunc('cvStartReadSeq', _cxDLL, None, 2326 ('seq', POINTER(CvSeq), 1), # const CvSeq* seq 2327 ('reader', POINTER(CvSeqReader), 1), # CvSeqReader* reader 2328 ('reverse', c_int, 1, 0), # int reverse 2329 ) 2330 2331 # Returns the current reader position 2332 cvGetSeqReaderPos = cfunc('cvGetSeqReaderPos', _cxDLL, c_int, 2333 ('reader', POINTER(CvSeqReader), 1), # CvSeqReader* reader 2334 ) 2335 2336 # Moves the reader to specified position 2337 cvSetSeqReaderPos = cfunc('cvSetSeqReaderPos', _cxDLL, None, 2338 ('reader', POINTER(CvSeqReader), 1), # CvSeqReader* reader 2339 ('index', c_int, 1), # int index 2340 ('is_relative', c_int, 1, 0), # int is_relative 2341 ) 2342 2343 # --- 2.3 Sets --------------------------------------------------------------- 2344 2345 # Creates empty set 2346 cvCreateSet = cfunc('cvCreateSet', _cxDLL, POINTER(CvSET), 2347 ('set_flags', c_int, 1), # int set_flags 2348 ('header_size', c_int, 1), # int header_size 2349 ('elem_size', c_int, 1), # int elem_size 2350 ('storage', POINTER(CvMemStorage), 1), # CvMemStorage* storage 2351 ) 2352 2353 # Occupies a node in the set 2354 cvSetAdd = cfunc('cvSetAdd', _cxDLL, c_int, 2355 ('set_header', POINTER(CvSET), 1), # CvSet* set_header 2356 ('elem', POINTER(CvSetElem), 1, None), # CvSetElem* elem 2357 ('inserted_elem', POINTER(POINTER(CvSetElem)), 1, None), # CvSetElem** inserted_elem 2358 ) 2359 2360 # Removes element from set 2361 cvSetRemove = cfunc('cvSetRemove', _cxDLL, None, 2362 ('set_header', POINTER(CvSET), 1), # CvSet* set_header 2363 ('index', c_int, 1), # int index 2364 ) 2365 2366 # Clears set 2367 cvClearSet = cfunc('cvClearSet', _cxDLL, None, 2368 ('set_header', POINTER(CvSET), 1), # CvSet* set_header 2369 ) 2370 2371 # --- 2.4 Graphs ------------------------------------------------------------- 2372 2373 # Creates empty graph 2374 cvCreateGraph = cfunc('cvCreateGraph', _cxDLL, POINTER(CvGraph), 2375 ('graph_flags', c_int, 1), # int graph_flags 2376 ('header_size', c_int, 1), # int header_size 2377 ('vtx_size', c_int, 1), # int vtx_size 2378 ('edge_size', c_int, 1), # int edge_size 2379 ('storage', POINTER(CvMemStorage), 1), # CvMemStorage* storage 2380 ) 2381 2382 # Adds vertex to graph 2383 cvGraphAddVtx = cfunc('cvGraphAddVtx', _cxDLL, c_int, 2384 ('graph', POINTER(CvGraph), 1), # CvGraph* graph 2385 ('vtx', POINTER(CvGraphVtx), 1, None), # const CvGraphVtx* vtx 2386 ('inserted_vtx', POINTER(POINTER(CvGraphVtx)), 1, None), # CvGraphVtx** inserted_vtx 2387 ) 2388 2389 # Removes vertex from graph 2390 cvGraphRemoveVtx = cfunc('cvGraphRemoveVtx', _cxDLL, c_int, 2391 ('graph', POINTER(CvGraph), 1), # CvGraph* graph 2392 ('index', c_int, 1), # int index 2393 ) 2394 2395 # Removes vertex from graph 2396 cvGraphRemoveVtxByPtr = cfunc('cvGraphRemoveVtxByPtr', _cxDLL, c_int, 2397 ('graph', POINTER(CvGraph), 1), # CvGraph* graph 2398 ('vtx', POINTER(CvGraphVtx), 1), # CvGraphVtx* vtx 2399 ) 2400 2401 # Adds edge to graph 2402 cvGraphAddEdge = cfunc('cvGraphAddEdge', _cxDLL, c_int, 2403 ('graph', POINTER(CvGraph), 1), # CvGraph* graph 2404 ('start_idx', c_int, 1), # int start_idx 2405 ('end_idx', c_int, 1), # int end_idx 2406 ('edge', POINTER(CvGraphEdge), 1, None), # const CvGraphEdge* edge 2407 ('inserted_edge', POINTER(POINTER(CvGraphEdge)), 1, None), # CvGraphEdge** inserted_edge 2408 ) 2409 2410 # Adds edge to graph 2411 cvGraphAddEdgeByPtr = cfunc('cvGraphAddEdgeByPtr', _cxDLL, c_int, 2412 ('graph', POINTER(CvGraph), 1), # CvGraph* graph 2413 ('start_vtx', POINTER(CvGraphVtx), 1), # CvGraphVtx* start_vtx 2414 ('end_vtx', POINTER(CvGraphVtx), 1), # CvGraphVtx* end_vtx 2415 ('edge', POINTER(CvGraphEdge), 1, None), # const CvGraphEdge* edge 2416 ('inserted_edge', POINTER(POINTER(CvGraphEdge)), 1, None), # CvGraphEdge** inserted_edge 2417 ) 2418 2419 # Removes edge from graph 2420 cvGraphRemoveEdge = cfunc('cvGraphRemoveEdge', _cxDLL, None, 2421 ('graph', POINTER(CvGraph), 1), # CvGraph* graph 2422 ('start_idx', c_int, 1), # int start_idx 2423 ('end_idx', c_int, 1), # int end_idx 2424 ) 2425 2426 # Removes edge from graph 2427 cvGraphRemoveEdgeByPtr = cfunc('cvGraphRemoveEdgeByPtr', _cxDLL, None, 2428 ('graph', POINTER(CvGraph), 1), # CvGraph* graph 2429 ('start_vtx', POINTER(CvGraphVtx), 1), # CvGraphVtx* start_vtx 2430 ('end_vtx', POINTER(CvGraphVtx), 1), # CvGraphVtx* end_vtx 2431 ) 2432 2433 # Finds edge in graph 2434 cvFindGraphEdge = cfunc('cvFindGraphEdge', _cxDLL, POINTER(CvGraphEdge), 2435 ('graph', POINTER(CvGraph), 1), # const CvGraph* graph 2436 ('start_idx', c_int, 1), # int start_idx 2437 ('end_idx', c_int, 1), # int end_idx 2438 ) 2439 2440 # Finds edge in graph 2441 cvFindGraphEdgeByPtr = cfunc('cvFindGraphEdgeByPtr', _cxDLL, POINTER(CvGraphEdge), 2442 ('graph', POINTER(CvGraph), 1), # const CvGraph* graph 2443 ('start_vtx', POINTER(CvGraphVtx), 1), # const CvGraphVtx* start_vtx 2444 ('end_vtx', POINTER(CvGraphVtx), 1), # const CvGraphVtx* end_vtx 2445 ) 2446 2447 # Counts edges indicent to the vertex 2448 cvGraphVtxDegree = cfunc('cvGraphVtxDegree', _cxDLL, c_int, 2449 ('graph', POINTER(CvGraph), 1), # const CvGraph* graph 2450 ('vtx_idx', c_int, 1), # int vtx_idx 2451 ) 2452 2453 # Finds edge in graph 2454 cvGraphVtxDegreeByPtr = cfunc('cvGraphVtxDegreeByPtr', _cxDLL, c_int, 2455 ('graph', POINTER(CvGraph), 1), # const CvGraph* graph 2456 ('vtx', POINTER(CvGraphVtx), 1), # const CvGraphVtx* vtx 2457 ) 2458 2459 # Clears graph 2460 cvClearGraph = cfunc('cvClearGraph', _cxDLL, None, 2461 ('graph', POINTER(CvGraph), 1), # CvGraph* graph 2462 ) 2463 2464 # Clone graph 2465 cvCloneGraph = cfunc('cvCloneGraph', _cxDLL, POINTER(CvGraph), 2466 ('graph', POINTER(CvGraph), 1), # const CvGraph* graph 2467 ('storage', POINTER(CvMemStorage), 1), # CvMemStorage* storage 2468 ) 2469 2470 # Creates structure for depth-first graph traversal 2471 cvCreateGraphScanner = cfunc('cvCreateGraphScanner', _cxDLL, POINTER(CvGraphScanner), 2472 ('graph', POINTER(CvGraph), 1), # CvGraph* graph 2473 ('vtx', POINTER(CvGraphVtx), 1, None), # CvGraphVtx* vtx 2474 ('mask', c_int, 1), # int mask 2475 ) 2476 2477 # Makes one or more steps of the graph traversal procedure 2478 cvNextGraphItem = cfunc('cvNextGraphItem', _cxDLL, c_int, 2479 ('scanner', POINTER(CvGraphScanner), 1), # CvGraphScanner* scanner 2480 ) 2481 2482 # Finishes graph traversal procedure 2483 cvReleaseGraphScanner = cfunc('cvReleaseGraphScanner', _cxDLL, None, 2484 ('scanner', POINTER(POINTER(CvGraphScanner)), 1), # CvGraphScanner** scanner 2485 ) 2486 2487 # --- 2.5 Trees -------------------------------------------------------------- 2488 2489 # Initializes tree node iterator 2490 cvInitTreeNodeIterator = cfunc('cvInitTreeNodeIterator', _cxDLL, None, 2491 ('tree_iterator', POINTER(CvTreeNodeIterator), 1), # CvTreeNodeIterator* tree_iterator 2492 ('first', c_void_p, 1), # const void* first 2493 ('max_level', c_int, 1), # int max_level 2494 ) 2495 2496 # Returns the currently observed node and moves iterator toward the next node 2497 cvNextTreeNode = cfunc('cvNextTreeNode', _cxDLL, c_void_p, 2498 ('tree_iterator', POINTER(CvTreeNodeIterator), 1), # CvTreeNodeIterator* tree_iterator 2499 ) 2500 2501 # Returns the currently observed node and moves iterator toward the previous node 2502 cvPrevTreeNode = cfunc('cvPrevTreeNode', _cxDLL, c_void_p, 2503 ('tree_iterator', POINTER(CvTreeNodeIterator), 1), # CvTreeNodeIterator* tree_iterator 2504 ) 2505 2506 # Gathers all node pointers to the single sequence 2507 cvTreeToNodeSeq = cfunc('cvTreeToNodeSeq', _cxDLL, POINTER(CvSeq), 2508 ('first', c_void_p, 1), # const void* first 2509 ('header_size', c_int, 1), # int header_size 2510 ('storage', POINTER(CvMemStorage), 1), # CvMemStorage* storage 2511 ) 2512 2513 # Adds new node to the tree 2514 cvInsertNodeIntoTree = cfunc('cvInsertNodeIntoTree', _cxDLL, None, 2515 ('node', c_void_p, 1), # void* node 2516 ('parent', c_void_p, 1), # void* parent 2517 ('frame', c_void_p, 1), # void* frame 2518 ) 2519 2520 # Removes node from tree 2521 cvRemoveNodeFromTree = cfunc('cvRemoveNodeFromTree', _cxDLL, None, 2522 ('node', c_void_p, 1), # void* node 2523 ('frame', c_void_p, 1), # void* frame 2524 ) 2525 2526 # --- 3 Drawing Functions ---------------------------------------------------- 2527 2528 # --- 3.1 Curves and Shapes -------------------------------------------------- 2529 2530 # Constructs a color value
2531 -def CV_RGB(r, g, b):
2532 result = CvScalar() 2533 result.val[0] = b 2534 result.val[1] = g 2535 result.val[2] = r 2536 return result
2537 2538 # Draws a line segment connecting two points 2539 cvLine = cfunc('cvLine', _cxDLL, None, 2540 ('img', c_void_p, 1), # CvArr* img 2541 ('pt1', CvPoint, 1), # CvPoint pt1 2542 ('pt2', CvPoint, 1), # CvPoint pt2 2543 ('color', CvScalar, 1), # CvScalar color 2544 ('thickness', c_int, 1, 1), # int thickness 2545 ('line_type', c_int, 1, 8), # int line_type 2546 ('shift', c_int, 1, 0), # int shift 2547 ) 2548 2549 # Draws simple, thick or filled rectangle 2550 cvRectangle = cfunc('cvRectangle', _cxDLL, None, 2551 ('img', c_void_p, 1), # CvArr* img 2552 ('pt1', CvPoint, 1), # CvPoint pt1 2553 ('pt2', CvPoint, 1), # CvPoint pt2 2554 ('color', CvScalar, 1), # CvScalar color 2555 ('thickness', c_int, 1, 1), # int thickness 2556 ('line_type', c_int, 1, 8), # int line_type 2557 ('shift', c_int, 1, 0), # int shift 2558 ) 2559 2560 # Draws a circle 2561 cvCircle = cfunc('cvCircle', _cxDLL, None, 2562 ('img', c_void_p, 1), # CvArr* img 2563 ('center', CvPoint, 1), # CvPoint center 2564 ('radius', c_int, 1), # int radius 2565 ('color', CvScalar, 1), # CvScalar color 2566 ('thickness', c_int, 1, 1), # int thickness 2567 ('line_type', c_int, 1, 8), # int line_type 2568 ('shift', c_int, 1, 0), # int shift 2569 ) 2570 2571 # Draws simple or thick elliptic arc or fills ellipse sector 2572 cvEllipse = cfunc('cvEllipse', _cxDLL, None, 2573 ('img', c_void_p, 1), # CvArr* img 2574 ('center', CvPoint, 1), # CvPoint center 2575 ('axes', CvSize, 1), # CvSize axes 2576 ('angle', c_double, 1), # double angle 2577 ('start_angle', c_double, 1), # double start_angle 2578 ('end_angle', c_double, 1), # double end_angle 2579 ('color', CvScalar, 1), # CvScalar color 2580 ('thickness', c_int, 1, 1), # int thickness 2581 ('line_type', c_int, 1, 8), # int line_type 2582 ('shift', c_int, 1, 0), # int shift 2583 ) 2584
2585 -def cvEllipseBox(img, box, color, thickness=1, line_type=8, shift=0):
2586 '''Draws simple or thick elliptic arc or fills ellipse sector''' 2587 cvEllipse(img, CvPoint(int(box.center.x), int(box.center.y)), 2588 CvSize(int(box.size.height*0.5),int(box.size.width*0.5)), 2589 box.angle, 0, 360, color, thickness, line_type, shift)
2590 2591 2592 # Fills polygons interior 2593 cvFillPoly = cfunc('cvFillPoly', _cxDLL, None, 2594 ('img', c_void_p, 1), # CvArr* img 2595 ('pts', POINTER(POINTER(CvPoint)), 1), # CvPoint** pts 2596 ('npts', POINTER(c_int), 1), # int* npts 2597 ('contours', c_int, 1), # int contours 2598 ('color', CvScalar, 1), # CvScalar color 2599 ('line_type', c_int, 1, 8), # int line_type 2600 ('shift', c_int, 1, 0), # int shift 2601 ) 2602 2603 # Fills convex polygon 2604 cvFillConvexPoly = cfunc('cvFillConvexPoly', _cxDLL, None, 2605 ('img', c_void_p, 1), # CvArr* img 2606 ('pts', POINTER(CvPoint), 1), # CvPoint* pts 2607 ('npts', c_int, 1), # int npts 2608 ('color', CvScalar, 1), # CvScalar color 2609 ('line_type', c_int, 1, 8), # int line_type 2610 ('shift', c_int, 1, 0), # int shift 2611 ) 2612 2613 # Draws simple or thick polygons 2614 cvPolyLine = cfunc('cvPolyLine', _cxDLL, None, 2615 ('img', c_void_p, 1), # CvArr* img 2616 ('pts', POINTER(POINTER(CvPoint)), 1), # CvPoint** pts 2617 ('npts', POINTER(c_int), 1), # int* npts 2618 ('contours', c_int, 1), # int contours 2619 ('is_closed', c_int, 1), # int is_closed 2620 ('color', CvScalar, 1), # CvScalar color 2621 ('thickness', c_int, 1, 1), # int thickness 2622 ('line_type', c_int, 1, 8), # int line_type 2623 ('shift', c_int, 1, 0), # int shift 2624 ) 2625 2626 # --- 3.2 Text --------------------------------------------------------------- 2627 2628 # Initializes font structure 2629 cvInitFont = cfunc('cvInitFont', _cxDLL, None, 2630 ('font', POINTER(CvFont), 1), # CvFont* font 2631 ('font_face', c_int, 1), # int font_face 2632 ('hscale', c_double, 1), # double hscale 2633 ('vscale', c_double, 1), # double vscale 2634 ('shear', c_double, 1, 0), # double shear 2635 ('thickness', c_int, 1, 1), # int thickness 2636 ('line_type', c_int, 1, 8), # int line_type 2637 ) 2638 2639 # Draws text string 2640 cvPutText = cfunc('cvPutText', _cxDLL, None, 2641 ('img', c_void_p, 1), # CvArr* img 2642 ('text', c_char_p, 1), # const char* text 2643 ('org', CvPoint, 1), # CvPoint org 2644 ('font', POINTER(CvFont), 1), # const CvFont* font 2645 ('color', CvScalar, 1), # CvScalar color 2646 ) 2647 2648 # Retrieves width and height of text string 2649 cvGetTextSize = cfunc('cvGetTextSize', _cxDLL, None, 2650 ('text_string', c_char_p, 1), # const char* text_string 2651 ('font', POINTER(CvFont), 1), # const CvFont* font 2652 ('text_size', POINTER(CvSize), 1), # CvSize* text_size 2653 ('baseline', POINTER(c_int), 1), # int* baseline 2654 ) 2655 2656 # --- 3.3 Point Sets and Contours -------------------------------------------- 2657 2658 # Draws contour outlines or interiors in the image 2659 cvDrawContours = cfunc('cvDrawContours', _cxDLL, None, 2660 ('img', c_void_p, 1), # CvArr* img 2661 ('contour', c_void_p, 1), # CvSeq* contour 2662 ('external_color', CvScalar, 1), # CvScalar external_color 2663 ('hole_color', CvScalar, 1), # CvScalar hole_color 2664 ('max_level', c_int, 1), # int max_level 2665 ('thickness', c_int, 1, 1), # int thickness 2666 ('line_type', c_int, 1, 8), # int line_type 2667 ('offset', CvPoint, 1), # CvPoint offset 2668 ) 2669 2670 # Initializes line iterator 2671 cvInitLineIterator = cfunc('cvInitLineIterator', _cxDLL, c_int, 2672 ('image', c_void_p, 1), # const CvArr* image 2673 ('pt1', CvPoint, 1), # CvPoint pt1 2674 ('pt2', CvPoint, 1), # CvPoint pt2 2675 ('line_iterator', POINTER(CvLineIterator), 1), # CvLineIterator* line_iterator 2676 ('connectivity', c_int, 1, 8), # int connectivity 2677 ('left_to_right', c_int, 1, 0), # int left_to_right 2678 ) 2679 2680 # Clips the line against the image rectangle 2681 cvClipLine = cfunc('cvClipLine', _cxDLL, c_int, 2682 ('img_size', CvSize, 1), # CvSize img_size 2683 ('pt1', POINTER(CvPoint), 1), # CvPoint* pt1 2684 ('pt2', POINTER(CvPoint), 1), # CvPoint* pt2 2685 ) 2686 2687 # Approximates elliptic arc with polyline 2688 cvEllipse2Poly = cfunc('cvEllipse2Poly', _cxDLL, c_int, 2689 ('center', CvPoint, 1), # CvPoint center 2690 ('axes', CvSize, 1), # CvSize axes 2691 ('angle', c_int, 1), # int angle 2692 ('arc_start', c_int, 1), # int arc_start 2693 ('arc_end', c_int, 1), # int arc_end 2694 ('pts', POINTER(CvPoint), 1), # CvPoint* pts 2695 ('delta', c_int, 1), # int delta 2696 ) 2697 2698 # --- 4 Data Persistence and RTTI -------------------------------------------- 2699 2700 # --- 4.1 File Storage ------------------------------------------------------- 2701 2702 # Opens file storage for reading or writing data 2703 cvOpenFileStorage = cfunc('cvOpenFileStorage', _cxDLL, POINTER(CvFileStorage), 2704 ('filename', c_char_p, 1), # const char* filename 2705 ('memstorage', POINTER(CvMemStorage), 1), # CvMemStorage* memstorage 2706 ('flags', c_int, 1), # int flags 2707 ) 2708 2709 # Releases file storage 2710 cvReleaseFileStorage = cfunc('cvReleaseFileStorage', _cxDLL, None, 2711 ('fs', POINTER(POINTER(CvFileStorage)), 1), # CvFileStorage** fs 2712 ) 2713 2714 # --- 4.2 Writing Data ------------------------------------------------------- 2715 2716 # Starts writing a new structure 2717 cvStartWriteStruct = cfunc('cvStartWriteStruct', _cxDLL, None, 2718 ('fs', POINTER(CvFileStorage), 1), # CvFileStorage* fs 2719 ('name', c_char_p, 1), # const char* name 2720 ('struct_flags', c_int, 1), # int struct_flags 2721 ('type_name', c_char_p, 1, None), # const char* type_name 2722 ('attributes', CvAttrList, 1), # CvAttrList attributes 2723 ) 2724 2725 # Ends writing a structure 2726 cvEndWriteStruct = cfunc('cvEndWriteStruct', _cxDLL, None, 2727 ('fs', POINTER(CvFileStorage), 1), # CvFileStorage* fs 2728 ) 2729 2730 # Writes an integer value 2731 cvWriteInt = cfunc('cvWriteInt', _cxDLL, None, 2732 ('fs', POINTER(CvFileStorage), 1), # CvFileStorage* fs 2733 ('name', c_char_p, 1), # const char* name 2734 ('value', c_int, 1), # int value 2735 ) 2736 2737 # Writes a floating-point value 2738 cvWriteReal = cfunc('cvWriteReal', _cxDLL, None, 2739 ('fs', POINTER(CvFileStorage), 1), # CvFileStorage* fs 2740 ('name', c_char_p, 1), # const char* name 2741 ('value', c_double, 1), # double value 2742 ) 2743 2744 # Writes a text string 2745 cvWriteString = cfunc('cvWriteString', _cxDLL, None, 2746 ('fs', POINTER(CvFileStorage), 1), # CvFileStorage* fs 2747 ('name', c_char_p, 1), # const char* name 2748 ('str', c_char_p, 1), # const char* str 2749 ('quote', c_int, 1, 0), # int quote 2750 ) 2751 2752 # Writes comment 2753 cvWriteComment = cfunc('cvWriteComment', _cxDLL, None, 2754 ('fs', POINTER(CvFileStorage), 1), # CvFileStorage* fs 2755 ('comment', c_char_p, 1), # const char* comment 2756 ('eol_comment', c_int, 1), # int eol_comment 2757 ) 2758 2759 # Starts the next stream 2760 cvStartNextStream = cfunc('cvStartNextStream', _cxDLL, None, 2761 ('fs', POINTER(CvFileStorage), 1), # CvFileStorage* fs 2762 ) 2763 2764 # Writes user object 2765 cvWrite = cfunc('cvWrite', _cxDLL, None, 2766 ('fs', POINTER(CvFileStorage), 1), # CvFileStorage* fs 2767 ('name', c_char_p, 1), # const char* name 2768 ('ptr', c_void_p, 1), # const void* ptr 2769 ('attributes', CvAttrList, 1), # CvAttrList attributes 2770 ) 2771 2772 # Writes multiple numbers 2773 cvWriteRawData = cfunc('cvWriteRawData', _cxDLL, None, 2774 ('fs', POINTER(CvFileStorage), 1), # CvFileStorage* fs 2775 ('src', c_void_p, 1), # const void* src 2776 ('len', c_int, 1), # int len 2777 ('dt', c_char_p, 1), # const char* dt 2778 ) 2779 2780 # Writes file node to another file storage 2781 cvWriteFileNode = cfunc('cvWriteFileNode', _cxDLL, None, 2782 ('fs', POINTER(CvFileStorage), 1), # CvFileStorage* fs 2783 ('new_node_name', c_char_p, 1), # const char* new_node_name 2784 ('node', POINTER(CvFileNode), 1), # const CvFileNode* node 2785 ('embed', c_int, 1), # int embed 2786 ) 2787 2788 # --- 4.3 Reading Data ------------------------------------------------------- 2789 2790 # Retrieves one of top-level nodes of the file storage 2791 cvGetRootFileNode = cfunc('cvGetRootFileNode', _cxDLL, POINTER(CvFileNode), 2792 ('fs', POINTER(CvFileStorage), 1), # const CvFileStorage* fs 2793 ('stream_index', c_int, 1, 0), # int stream_index 2794 ) 2795 2796 # Finds node in the map or file storage 2797 cvGetFileNodeByName = cfunc('cvGetFileNodeByName', _cxDLL, POINTER(CvFileNode), 2798 ('fs', POINTER(CvFileStorage), 1), # const CvFileStorage* fs 2799 ('map', POINTER(CvFileNode), 1), # const CvFileNode* map 2800 ('name', c_char_p, 1), # const char* name 2801 ) 2802 2803 # Returns a unique pointer for given name 2804 cvGetHashedKey = cfunc('cvGetHashedKey', _cxDLL, POINTER(CvStringHashNode), 2805 ('fs', POINTER(CvFileStorage), 1), # CvFileStorage* fs 2806 ('name', c_char_p, 1), # const char* name 2807 ('len', c_int, 1), # int len 2808 ('create_missing', c_int, 1, 0), # int create_missing 2809 ) 2810 2811 # Finds node in the map or file storage 2812 cvGetFileNode = cfunc('cvGetFileNode', _cxDLL, POINTER(CvFileNode), 2813 ('fs', POINTER(CvFileStorage), 1), # CvFileStorage* fs 2814 ('map', POINTER(CvFileNode), 1), # CvFileNode* map 2815 ('key', POINTER(CvStringHashNode), 1), # const CvStringHashNode* key 2816 ('create_missing', c_int, 1, 0), # int create_missing 2817 ) 2818 2819 # Returns name of file node 2820 cvGetFileNodeName = cfunc('cvGetFileNodeName', _cxDLL, c_char_p, 2821 ('node', POINTER(CvFileNode), 1), # const CvFileNode* node 2822 ) 2823 2824 # Decodes object and returns pointer to it 2825 cvRead = cfunc('cvRead', _cxDLL, c_void_p, 2826 ('fs', POINTER(CvFileStorage), 1), # CvFileStorage* fs 2827 ('node', POINTER(CvFileNode), 1), # CvFileNode* node 2828 ('attributes', POINTER(CvAttrList), 1, None), # CvAttrList* attributes 2829 ) 2830 2831 # Reads multiple numbers 2832 cvReadRawData = cfunc('cvReadRawData', _cxDLL, None, 2833 ('fs', POINTER(CvFileStorage), 1), # const CvFileStorage* fs 2834 ('src', POINTER(CvFileNode), 1), # const CvFileNode* src 2835 ('dst', c_void_p, 1), # void* dst 2836 ('dt', c_char_p, 1), # const char* dt 2837 ) 2838 2839 # Initializes file node sequence reader 2840 cvStartReadRawData = cfunc('cvStartReadRawData', _cxDLL, None, 2841 ('fs', POINTER(CvFileStorage), 1), # const CvFileStorage* fs 2842 ('src', POINTER(CvFileNode), 1), # const CvFileNode* src 2843 ('reader', POINTER(CvSeqReader), 1), # CvSeqReader* reader 2844 ) 2845 2846 # Initializes file node sequence reader 2847 cvReadRawDataSlice = cfunc('cvReadRawDataSlice', _cxDLL, None, 2848 ('fs', POINTER(CvFileStorage), 1), # const CvFileStorage* fs 2849 ('reader', POINTER(CvSeqReader), 1), # CvSeqReader* reader 2850 ('count', c_int, 1), # int count 2851 ('dst', c_void_p, 1), # void* dst 2852 ('dt', c_char_p, 1), # const char* dt 2853 ) 2854 2855 # --- 4.4 RTTI and Generic Functions ----------------------------------------- 2856 2857 # Registers new type 2858 cvRegisterType = cfunc('cvRegisterType', _cxDLL, None, 2859 ('info', POINTER(CvTypeInfo), 1), # const CvTypeInfo* info 2860 ) 2861 2862 # Unregisters the type 2863 cvUnregisterType = cfunc('cvUnregisterType', _cxDLL, None, 2864 ('type_name', c_char_p, 1), # const char* type_name 2865 ) 2866 2867 # Returns the beginning of type list 2868 cvFirstType = cfunc('cvFirstType', _cxDLL, POINTER(CvTypeInfo), 2869 ) 2870 2871 # Finds type by its name 2872 cvFindType = cfunc('cvFindType', _cxDLL, POINTER(CvTypeInfo), 2873 ('type_name', c_char_p, 1), # const char* type_name 2874 ) 2875 2876 # Returns type of the object 2877 cvTypeOf = cfunc('cvTypeOf', _cxDLL, POINTER(CvTypeInfo), 2878 ('struct_ptr', c_void_p, 1), # const void* struct_ptr 2879 ) 2880 2881 # Releases the object 2882 cvRelease = cfunc('cvRelease', _cxDLL, None, 2883 ('struct_ptr', POINTER(c_void_p), 1), # void** struct_ptr 2884 ) 2885 2886 # Makes a clone of the object 2887 cvClone = cfunc('cvClone', _cxDLL, c_void_p, 2888 ('struct_ptr', c_void_p, 1), # const void* struct_ptr 2889 ) 2890 2891 # Saves object to file 2892 cvSave = cfunc('cvSave', _cxDLL, None, 2893 ('filename', c_char_p, 1), # const char* filename 2894 ('struct_ptr', c_void_p, 1), # const void* struct_ptr 2895 ('name', c_char_p, 1, None), # const char* name 2896 ('comment', c_char_p, 1, None), # const char* comment 2897 ('attributes', CvAttrList, 1), # CvAttrList attributes 2898 ) 2899 2900 # Loads object from file 2901 cvLoad = cfunc('cvLoad', _cxDLL, c_void_p, 2902 ('filename', c_char_p, 1), # const char* filename 2903 ('memstorage', POINTER(CvMemStorage), 1, None), # CvMemStorage* memstorage 2904 ('name', c_char_p, 1, None), # const char* name 2905 ('real_name', POINTER(c_char_p), 1, None), # const char** real_name 2906 ) 2907 # Load and cast to given type
2908 -def cvLoadCast(filename, ctype):
2909 '''Use cvLoad and then cast the result to ctype''' 2910 return ctypes.cast(cvLoad(filename), ctypes.POINTER(ctype))
2911 2912 2913 # --- 5 Miscellaneous Functions ---------------------------------------------- 2914 2915 # Checks every element of input array for invalid values 2916 cvCheckArr = cfunc('cvCheckArr', _cxDLL, c_int, 2917 ('arr', c_void_p, 1), # const CvArr* arr 2918 ('flags', c_int, 1, 0), # int flags 2919 ('min_val', c_double, 1, 0), # double min_val 2920 ('max_val', c_double, 1, 0), # double max_val 2921 ) 2922 2923 cvCheckArray = cvCheckArr 2924 2925 # Splits set of vectors by given number of clusters 2926 cvKMeans2 = cfunc('cvKMeans2', _cxDLL, None, 2927 ('samples', c_void_p, 1), # const CvArr* samples 2928 ('cluster_count', c_int, 1), # int cluster_count 2929 ('labels', c_void_p, 1), # CvArr* labels 2930 ('termcrit', CvTermCriteria, 1), # CvTermCriteria termcrit 2931 ) 2932 2933 # Splits sequence into equivalency classes 2934 cvSeqPartition = cfunc('cvSeqPartition', _cxDLL, c_int, 2935 ('seq', POINTER(CvSeq), 1), # const CvSeq* seq 2936 ('storage', POINTER(CvMemStorage), 1), # CvMemStorage* storage 2937 ('labels', POINTER(POINTER(CvSeq)), 1), # CvSeq** labels 2938 ('is_equal', CvCmpFunc, 1), # CvCmpFunc is_equal 2939 ('userdata', c_void_p, 1), # void* userdata 2940 ) 2941 2942 # --- 6 Error Handling and System Functions ---------------------------------- 2943 2944 # --- 6.1 Error Handling ----------------------------------------------------- 2945 2946 # Returns the current error status 2947 cvGetErrStatus = cfunc('cvGetErrStatus', _cxDLL, c_int, 2948 ) 2949 2950 # Sets the error status 2951 cvSetErrStatus = cfunc('cvSetErrStatus', _cxDLL, None, 2952 ('status', c_int, 1), # int status 2953 ) 2954 2955 # Returns the current error mode 2956 cvGetErrMode = cfunc('cvGetErrMode', _cxDLL, c_int, 2957 ) 2958 2959 # Sets the error mode 2960 CV_ErrModeLeaf = 0 2961 CV_ErrModeParent = 1 2962 CV_ErrModeSilent = 2 2963 2964 cvSetErrMode = cfunc('cvSetErrMode', _cxDLL, c_int, 2965 ('mode', c_int, 1), # int mode 2966 ) 2967 2968 # Raises an error 2969 cvError = cfunc('cvError', _cxDLL, c_int, 2970 ('status', c_int, 1), # int status 2971 ('func_name', c_char_p, 1), # const char* func_name 2972 ('err_msg', c_char_p, 1), # const char* err_msg 2973 ('file_name', c_char_p, 1), # const char* file_name 2974 ('line', c_int, 1), # int line 2975 ) 2976 2977 # Returns textual description of error status code 2978 cvErrorStr = cfunc('cvErrorStr', _cxDLL, c_char_p, 2979 ('status', c_int, 1), # int status 2980 ) 2981 2982 # Sets a new error handler 2983 CvErrorCallback = CFUNCTYPE(c_int, # int 2984 c_int, # int status 2985 c_char_p, # const char* func_name 2986 c_char_p, # const char* err_msg 2987 c_char_p, # const char* file_name 2988 c_int) # int line 2989 2990 cvRedirectError = cfunc('cvRedirectError', _cxDLL, CvErrorCallback, 2991 ('error_handler', CvErrorCallback, 1), # CvErrorCallback error_handler 2992 ('userdata', c_void_p, 1, None), # void* userdata 2993 ('prev_userdata', POINTER(c_void_p), 1, None), # void** prev_userdata 2994 ) 2995 2996 # Provide standard error handling 2997 cvNulDevReport = cfunc('cvNulDevReport', _cxDLL, c_int, 2998 ('status', c_int, 1), # int status 2999 ('func_name', c_char_p, 1), # const char* func_name 3000 ('err_msg', c_char_p, 1), # const char* err_msg 3001 ('file_name', c_char_p, 1), # const char* file_name 3002 ('line', c_int, 1), # int line 3003 ('userdata', c_void_p, 1), # void* userdata 3004 ) 3005 3006 cvStdErrReport = cfunc('cvStdErrReport', _cxDLL, c_int, 3007 ('status', c_int, 1), # int status 3008 ('func_name', c_char_p, 1), # const char* func_name 3009 ('err_msg', c_char_p, 1), # const char* err_msg 3010 ('file_name', c_char_p, 1), # const char* file_name 3011 ('line', c_int, 1), # int line 3012 ('userdata', c_void_p, 1), # void* userdata 3013 ) 3014 3015 cvGuiBoxReport = cfunc('cvGuiBoxReport', _cxDLL, c_int, 3016 ('status', c_int, 1), # int status 3017 ('func_name', c_char_p, 1), # const char* func_name 3018 ('err_msg', c_char_p, 1), # const char* err_msg 3019 ('file_name', c_char_p, 1), # const char* file_name 3020 ('line', c_int, 1), # int line 3021 ('userdata', c_void_p, 1), # void* userdata 3022 ) 3023 3024 # --- 6.2 System and Utility Functions --------------------------------------- 3025 3026 # Allocates memory buffer 3027 cvAlloc = cfunc('cvAlloc', _cxDLL, c_void_p, 3028 ('size', c_ulong, 1), # size_t size 3029 ) 3030 3031 # Deallocates memory buffer 3032 #cvFree = _cxDLL.cvFree 3033 #cvFree.restype = None # void 3034 #cvFree.argtypes = [ 3035 # c_void_p # void** ptr 3036 # ] 3037 3038 # Returns number of tics 3039 cvGetTickCount = cfunc('cvGetTickCount', _cxDLL, c_longlong, 3040 ) 3041 3042 # Returns number of tics per microsecond 3043 cvGetTickFrequency = cfunc('cvGetTickFrequency', _cxDLL, c_double, 3044 ) 3045 3046 # Registers another module 3047 cvRegisterModule = cfunc('cvRegisterModule', _cxDLL, c_int, 3048 ('module_info', POINTER(CvModuleInfo), 1), # const CvModuleInfo* module_info 3049 ) 3050 3051 # Retrieves information about the registered module(s) and plugins 3052 cvGetModuleInfo = cfunc('cvGetModuleInfo', _cxDLL, None, 3053 ('module_name', c_char_p, 1), # const char* module_name 3054 ('version', POINTER(c_char_p), 1), # const char** version 3055 ('loaded_addon_plugins', POINTER(c_char_p), 1), # const char** loaded_addon_plugins 3056 ) 3057 3058 # Switches between optimized/non-optimized modes 3059 cvUseOptimized = cfunc('cvUseOptimized', _cxDLL, c_int, 3060 ('on_off', c_int, 1), # int on_off 3061 ) 3062 3063 # Assings custom/default memory managing functions 3064 #CvAllocFunc = CFUNCTYPE(c_void_p, # void* 3065 # c_ulong, # size_t size 3066 # c_void_p) # void* userdata 3067 # 3068 #CvFreeFunc = CFUNCTYPE(c_int, # int 3069 # c_void_p, # void* pptr 3070 # c_void_p) # void* userdata 3071 3072 #cvSetMemoryManager = _cxDLL.cvSetMemoryManager 3073 #cvSetMemoryManager.restype = None # void 3074 #cvSetMemoryManager.argtypes = [ 3075 # CvAllocFunc, # CvAllocFunc alloc_func=NULL 3076 # CvFreeFunc, # CvFreeFunc free_func=NULL 3077 # c_void_p # void* userdata=NULL 3078 # ] 3079 3080 # --- 1 Image Processing ----------------------------------------------------- 3081 3082 # --- 1.1 Gradients, Edges and Corners --------------------------------------- 3083 3084 # Calculates first, second, third or mixed image derivatives using extended Sobel operator 3085 cvSobel = cfunc('cvSobel', _cvDLL, None, 3086 ('src', c_void_p, 1), # const CvArr* src 3087 ('dst', c_void_p, 1), # CvArr* dst 3088 ('xorder', c_int, 1), # int xorder 3089 ('yorder', c_int, 1), # int yorder 3090 ('aperture_size', c_int, 1, 3), # int aperture_size 3091 ) 3092 3093 # Calculates Laplacian of the image 3094 cvLaplace = cfunc('cvLaplace', _cvDLL, None, 3095 ('src', c_void_p, 1), # const CvArr* src 3096 ('dst', c_void_p, 1), # CvArr* dst 3097 ('aperture_size', c_int, 1, 3), # int aperture_size 3098 ) 3099 3100 # Implements Canny algorithm for edge detection 3101 cvCanny = cfunc('cvCanny', _cvDLL, None, 3102 ('image', c_void_p, 1), # const CvArr* image 3103 ('edges', c_void_p, 1), # CvArr* edges 3104 ('threshold1', c_double, 1), # double threshold1 3105 ('threshold2', c_double, 1), # double threshold2 3106 ('aperture_size', c_int, 1, 3), # int aperture_size 3107 ) 3108 3109 # Calculates feature map for corner detection 3110 cvPreCornerDetect = cfunc('cvPreCornerDetect', _cvDLL, None, 3111 ('image', c_void_p, 1), # const CvArr* image 3112 ('corners', c_void_p, 1), # CvArr* corners 3113 ('aperture_size', c_int, 1, 3), # int aperture_size 3114 ) 3115 3116 # Calculates eigenvalues and eigenvectors of image blocks for corner detection 3117 cvCornerEigenValsAndVecs = cfunc('cvCornerEigenValsAndVecs', _cvDLL, None, 3118 ('image', c_void_p, 1), # const CvArr* image 3119 ('eigenvv', c_void_p, 1), # CvArr* eigenvv 3120 ('block_size', c_int, 1), # int block_size 3121 ('aperture_size', c_int, 1, 3), # int aperture_size 3122 ) 3123 3124 # Calculates minimal eigenvalue of gradient matrices for corner detection 3125 cvCornerMinEigenVal = cfunc('cvCornerMinEigenVal', _cvDLL, None, 3126 ('image', c_void_p, 1), # const CvArr* image 3127 ('eigenval', c_void_p, 1), # CvArr* eigenval 3128 ('block_size', c_int, 1), # int block_size 3129 ('aperture_size', c_int, 1, 3), # int aperture_size 3130 ) 3131 3132 # Harris edge detector 3133 cvCornerHarris = cfunc('cvCornerHarris', _cvDLL, None, 3134 ('image', c_void_p, 1), # const CvArr* image 3135 ('harris_responce', c_void_p, 1), # CvArr* harris_responce 3136 ('block_size', c_int, 1), # int block_size 3137 ('aperture_size', c_int, 1, 3), # int aperture_size 3138 ('k', c_double, 1, 0), # double k 3139 ) 3140 3141 # Refines corner locations 3142 cvFindCornerSubPix = cfunc('cvFindCornerSubPix', _cvDLL, None, 3143 ('image', c_void_p, 1), # const CvArr* image 3144 ('corners', POINTER(CvPoint2D32f), 1), # CvPoint2D32f* corners 3145 ('count', c_int, 1), # int count 3146 ('win', CvSize, 1), # CvSize win 3147 ('zero_zone', CvSize, 1), # CvSize zero_zone 3148 ('criteria', CvTermCriteria, 1), # CvTermCriteria criteria 3149 ) 3150 3151 # Determines strong corners on image 3152 cvGoodFeaturesToTrack = cfunc('cvGoodFeaturesToTrack', _cvDLL, None, 3153 ('image', c_void_p, 1), # const CvArr* image 3154 ('eig_image', c_void_p, 1), # CvArr* eig_image 3155 ('temp_image', c_void_p, 1), # CvArr* temp_image 3156 ('corners', POINTER(CvPoint2D32f), 1), # CvPoint2D32f* corners 3157 ('corner_count', POINTER(c_int), 1), # int* corner_count 3158 ('quality_level', c_double, 1), # double quality_level 3159 ('min_distance', c_double, 1), # double min_distance 3160 ('mask', c_void_p, 1, None), # const CvArr* mask 3161 ('block_size', c_int, 1, 3), # int block_size 3162 ('use_harris', c_int, 1, 0), # int use_harris 3163 ('k', c_double, 1, 0), # double k 3164 ) 3165 3166 # --- 1.2 Sampling, Interpolation and Geometrical Transforms ----------------- 3167 3168 # Reads raster line to buffer 3169 cvSampleLine = cfunc('cvSampleLine', _cvDLL, c_int, 3170 ('image', c_void_p, 1), # const CvArr* image 3171 ('pt1', CvPoint, 1), # CvPoint pt1 3172 ('pt2', CvPoint, 1), # CvPoint pt2 3173 ('buffer', c_void_p, 1), # void* buffer 3174 ('connectivity', c_int, 1, 8), # int connectivity 3175 ) 3176 3177 # Retrieves pixel rectangle from image with sub-pixel accuracy 3178 cvGetRectSubPix = cfunc('cvGetRectSubPix', _cvDLL, None, 3179 ('src', c_void_p, 1), # const CvArr* src 3180 ('dst', c_void_p, 1), # CvArr* dst 3181 ('center', CvPoint2D32f, 1), # CvPoint2D32f center 3182 ) 3183 3184 # Retrieves pixel quadrangle from image with sub-pixel accuracy 3185 cvGetQuadrangleSubPix = cfunc('cvGetQuadrangleSubPix', _cvDLL, None, 3186 ('src', c_void_p, 1), # const CvArr* src 3187 ('dst', c_void_p, 1), # CvArr* dst 3188 ('map_matrix', POINTER(CvMat), 1), # const CvMat* map_matrix 3189 ) 3190 3191 # Resizes image 3192 cvResize = cfunc('cvResize', _cvDLL, None, 3193 ('src', c_void_p, 1), # const CvArr* src 3194 ('dst', c_void_p, 1), # CvArr* dst 3195 ('interpolation', c_int, 1), # int interpolation 3196 ) 3197 3198 # Applies affine transformation to the image 3199 cvWarpAffine = cfunc('cvWarpAffine', _cvDLL, None, 3200 ('src', c_void_p, 1), # const CvArr* src 3201 ('dst', c_void_p, 1), # CvArr* dst 3202 ('map_matrix', POINTER(CvMat), 1), # const CvMat* map_matrix 3203 ('flags', c_int, 1), # int flags 3204 ('fillval', CvScalar, 1), # CvScalar fillval 3205 ) 3206 3207 # Added by Minh-Tri Pham 3208 # Calculates affine transform from 3 corresponding points 3209 cvGetAffineTransform = cfunc('cvGetAffineTransform', _cvDLL, POINTER(CvMat), 3210 ('src', POINTER(CvPoint2D32f), 1), # const CvPoint2D32f* src 3211 ('dst', POINTER(CvPoint2D32f), 1), # const CvPoint2D32f* dst 3212 ('map_matrix', POINTER(CvMat), 1), # CvMat* map_matrix 3213 ) 3214 3215 # Calculates affine matrix of 2d rotation 3216 cv2DRotationMatrix = cfunc('cv2DRotationMatrix', _cvDLL, POINTER(CvMat), 3217 ('center', CvPoint2D32f, 1), # CvPoint2D32f center 3218 ('angle', c_double, 1), # double angle 3219 ('scale', c_double, 1), # double scale 3220 ('map_matrix', POINTER(CvMat), 1), # CvMat* map_matrix 3221 ) 3222 3223 # Applies perspective transformation to the image 3224 cvWarpPerspective = cfunc('cvWarpPerspective', _cvDLL, None, 3225 ('src', c_void_p, 1), # const CvArr* src 3226 ('dst', c_void_p, 1), # CvArr* dst 3227 ('map_matrix', POINTER(CvMat), 1), # const CvMat* map_matrix 3228 ('flags', c_int, 1), # int flags 3229 ('fillval', CvScalar, 1), # CvScalar fillval 3230 ) 3231 3232 # Calculates perspective transform from 4 corresponding points 3233 cvGetPerspectiveTransform = cfunc('cvGetPerspectiveTransform', _cvDLL, POINTER(CvMat), 3234 ('src', POINTER(CvPoint2D32f), 1), # const CvPoint2D32f* src 3235 ('dst', POINTER(CvPoint2D32f), 1), # const CvPoint2D32f* dst 3236 ('map_matrix', POINTER(CvMat), 1), # CvMat* map_matrix 3237 ) 3238 3239 # Applies generic geometrical transformation to the image 3240 cvRemap = cfunc('cvRemap', _cvDLL, None, 3241 ('src', c_void_p, 1), # const CvArr* src 3242 ('dst', c_void_p, 1), # CvArr* dst 3243 ('mapx', c_void_p, 1), # const CvArr* mapx 3244 ('mapy', c_void_p, 1), # const CvArr* mapy 3245 ('flags', c_int, 1), # int flags 3246 ('fillval', CvScalar, 1), # CvScalar fillval 3247 ) 3248 3249 # Remaps image to log-polar space 3250 cvLogPolar = cfunc('cvLogPolar', _cvDLL, None, 3251 ('src', c_void_p, 1), # const CvArr* src 3252 ('dst', c_void_p, 1), # CvArr* dst 3253 ('center', CvPoint2D32f, 1), # CvPoint2D32f center 3254 ('M', c_double, 1), # double M 3255 ('flags', c_int, 1), # int flags 3256 ) 3257 3258 # --- 1.3 Morphological Operations ------------------------------------------- 3259 3260 # Creates structuring element 3261 cvCreateStructuringElementEx = cfunc('cvCreateStructuringElementEx', _cvDLL, c_void_p, 3262 ('cols', c_int, 1), # int cols 3263 ('rows', c_int, 1), # int rows 3264 ('anchor_x', c_int, 1), # int anchor_x 3265 ('anchor_y', c_int, 1), # int anchor_y 3266 ('shape', c_int, 1), # int shape 3267 ('values', POINTER(c_int), 1, None), # int* values 3268 ) 3269 3270 # Deletes structuring element 3271 cvReleaseStructuringElement = cfunc('cvReleaseStructuringElement', _cvDLL, None, 3272 ('element', POINTER(POINTER(IplConvKernel)), 1), # IplConvKernel** element 3273 ) 3274 3275 # Erodes image by using arbitrary structuring element 3276 cvErode = cfunc('cvErode', _cvDLL, None, 3277 ('src', c_void_p, 1), # const CvArr* src 3278 ('dst', c_void_p, 1), # CvArr* dst 3279 ('element', POINTER(IplConvKernel), 1, None), # IplConvKernel* element 3280 ('iterations', c_int, 1, 1), # int iterations 3281 ) 3282 3283 # Dilates image by using arbitrary structuring element 3284 cvDilate = cfunc('cvDilate', _cvDLL, None, 3285 ('src', c_void_p, 1), # const CvArr* src 3286 ('dst', c_void_p, 1), # CvArr* dst 3287 ('element', POINTER(IplConvKernel), 1, None), # IplConvKernel* element 3288 ('iterations', c_int, 1, 1), # int iterations 3289 ) 3290 3291 # Performs advanced morphological transformations 3292 cvMorphologyEx = cfunc('cvMorphologyEx', _cvDLL, None, 3293 ('src', c_void_p, 1), # const CvArr* src 3294 ('dst', c_void_p, 1), # CvArr* dst 3295 ('temp', c_void_p, 1), # CvArr* temp 3296 ('element', POINTER(IplConvKernel), 1), # IplConvKernel* element 3297 ('operation', c_int, 1), # int operation 3298 ('iterations', c_int, 1, 1), # int iterations 3299 ) 3300 3301 # --- 1.4 Filters and Color Conversion --------------------------------------- 3302 3303 # Smooths the image in one of several ways 3304 cvSmooth = cfunc('cvSmooth', _cvDLL, None, 3305 ('src', c_void_p, 1), # const CvArr* src 3306 ('dst', c_void_p, 1), # CvArr* dst 3307 ('smoothtype', c_int, 1), # int smoothtype 3308 ('param1', c_int, 1, 3), # int param1 3309 ('param2', c_int, 1, 0), # int param2 3310 ('param3', c_double, 1, 0), # double param3 3311 ) 3312 3313 # Convolves image with the kernel 3314 cvFilter2D = cfunc('cvFilter2D', _cvDLL, None, 3315 ('src', c_void_p, 1), # const CvArr* src 3316 ('dst', c_void_p, 1), # CvArr* dst 3317 ('kernel', POINTER(CvMat), 1), # const CvMat* kernel 3318 ('anchor', CvPoint, 1), # CvPoint anchor 3319 ) 3320 3321 # Copies image and makes border around it 3322 cvCopyMakeBorder = cfunc('cvCopyMakeBorder', _cvDLL, None, 3323 ('src', c_void_p, 1), # const CvArr* src 3324 ('dst', c_void_p, 1), # CvArr* dst 3325 ('offset', CvPoint, 1), # CvPoint offset 3326 ('bordertype', c_int, 1), # int bordertype 3327 ('value', CvScalar, 1), # CvScalar value 3328 ) 3329 3330 # Calculates integral images 3331 cvIntegral = cfunc('cvIntegral', _cvDLL, None, 3332 ('image', c_void_p, 1), # const CvArr* image 3333 ('sum', c_void_p, 1), # CvArr* sum 3334 ('sqsum', c_void_p, 1, None), # CvArr* sqsum 3335 ('tilted_sum', c_void_p, 1, None), # CvArr* tilted_sum 3336 ) 3337 3338 3339 CV_BGR2BGRA = 0 3340 CV_RGB2RGBA = CV_BGR2BGRA 3341 3342 CV_BGRA2BGR = 1 3343 CV_RGBA2RGB = CV_BGRA2BGR 3344 3345 CV_BGR2RGBA = 2 3346 CV_RGB2BGRA = CV_BGR2RGBA 3347 3348 CV_RGBA2BGR = 3 3349 CV_BGRA2RGB = CV_RGBA2BGR 3350 3351 CV_BGR2RGB = 4 3352 CV_RGB2BGR = CV_BGR2RGB 3353 3354 CV_BGRA2RGBA = 5 3355 CV_RGBA2BGRA = CV_BGRA2RGBA 3356 3357 CV_BGR2GRAY = 6 3358 CV_RGB2GRAY = 7 3359 CV_GRAY2BGR = 8 3360 CV_GRAY2RGB = CV_GRAY2BGR 3361 CV_GRAY2BGRA = 9 3362 CV_GRAY2RGBA = CV_GRAY2BGRA 3363 CV_BGRA2GRAY = 10 3364 CV_RGBA2GRAY = 11 3365 3366 CV_BGR2BGR565 = 12 3367 CV_RGB2BGR565 = 13 3368 CV_BGR5652BGR = 14 3369 CV_BGR5652RGB = 15 3370 CV_BGRA2BGR565 = 16 3371 CV_RGBA2BGR565 = 17 3372 CV_BGR5652BGRA = 18 3373 CV_BGR5652RGBA = 19 3374 3375 CV_GRAY2BGR565 = 20 3376 CV_BGR5652GRAY = 21 3377 3378 CV_BGR2BGR555 = 22 3379 CV_RGB2BGR555 = 23 3380 CV_BGR5552BGR = 24 3381 CV_BGR5552RGB = 25 3382 CV_BGRA2BGR555 = 26 3383 CV_RGBA2BGR555 = 27 3384 CV_BGR5552BGRA = 28 3385 CV_BGR5552RGBA = 29 3386 3387 CV_GRAY2BGR555 = 30 3388 CV_BGR5552GRAY = 31 3389 3390 CV_BGR2XYZ = 32 3391 CV_RGB2XYZ = 33 3392 CV_XYZ2BGR = 34 3393 CV_XYZ2RGB = 35 3394 3395 CV_BGR2YCrCb = 36 3396 CV_RGB2YCrCb = 37 3397 CV_YCrCb2BGR = 38 3398 CV_YCrCb2RGB = 39 3399 3400 CV_BGR2HSV = 40 3401 CV_RGB2HSV = 41 3402 3403 CV_BGR2Lab = 44 3404 CV_RGB2Lab = 45 3405 3406 CV_BayerBG2BGR = 46 3407 CV_BayerGB2BGR = 47 3408 CV_BayerRG2BGR = 48 3409 CV_BayerGR2BGR = 49 3410 3411 CV_BayerBG2RGB = CV_BayerRG2BGR 3412 CV_BayerGB2RGB = CV_BayerGR2BGR 3413 CV_BayerRG2RGB = CV_BayerBG2BGR 3414 CV_BayerGR2RGB = CV_BayerGB2BGR 3415 3416 CV_BGR2Luv = 50 3417 CV_RGB2Luv = 51 3418 CV_BGR2HLS = 52 3419 CV_RGB2HLS = 53 3420 3421 CV_HSV2BGR = 54 3422 CV_HSV2RGB = 55 3423 3424 CV_Lab2BGR = 56 3425 CV_Lab2RGB = 57 3426 CV_Luv2BGR = 58 3427 CV_Luv2RGB = 59 3428 CV_HLS2BGR = 60 3429 CV_HLS2RGB = 61 3430 3431 3432 # Converts image from one color space to another 3433 cvCvtColor = cfunc('cvCvtColor', _cvDLL, None, 3434 ('src', c_void_p, 1), # const CvArr* src 3435 ('dst', c_void_p, 1), # CvArr* dst 3436 ('code', c_int, 1), # int code 3437 ) 3438 3439 # Applies fixed-level threshold to array elements 3440 cvThreshold = cfunc('cvThreshold', _cvDLL, None, 3441 ('src', c_void_p, 1), # const CvArr* src 3442 ('dst', c_void_p, 1), # CvArr* dst 3443 ('threshold', c_double, 1), # double threshold 3444 ('max_value', c_double, 1), # double max_value 3445 ('threshold_type', c_int, 1), # int threshold_type 3446 ) 3447 3448 # Applies adaptive threshold to array 3449 cvAdaptiveThreshold = cfunc('cvAdaptiveThreshold', _cvDLL, None, 3450 ('src', c_void_p, 1), # const CvArr* src 3451 ('dst', c_void_p, 1), # CvArr* dst 3452 ('max_value', c_double, 1), # double max_value 3453 ('adaptive_method', c_int, 1), # int adaptive_method 3454 ('threshold_type', c_int, 1), # int threshold_type 3455 ('block_size', c_int, 1, 3), # int block_size 3456 ('param1', c_double, 1, 5), # double param1 3457 ) 3458 3459 # --- 1.5 Pyramids and the Applications -------------------------------------- 3460 3461 # Downsamples image 3462 cvPyrDown = cfunc('cvPyrDown', _cvDLL, None, 3463 ('src', c_void_p, 1), # const CvArr* src 3464 ('dst', c_void_p, 1), # CvArr* dst 3465 ('filter', c_int, 1), # int filter 3466 ) 3467 3468 # Upsamples image 3469 cvPyrUp = cfunc('cvPyrUp', _cvDLL, None, 3470 ('src', c_void_p, 1), # const CvArr* src 3471 ('dst', c_void_p, 1), # CvArr* dst 3472 ('filter', c_int, 1), # int filter 3473 ) 3474 3475 # Implements image segmentation by pyramids 3476 cvPyrSegmentation = cfunc('cvPyrSegmentation', _cvDLL, None, 3477 ('src', POINTER(IplImage), 1), # IplImage* src 3478 ('dst', POINTER(IplImage), 1), # IplImage* dst 3479 ('storage', POINTER(CvMemStorage), 1), # CvMemStorage* storage 3480 ('comp', POINTER(POINTER(CvSeq)), 1), # CvSeq** comp 3481 ('level', c_int, 1), # int level 3482 ('threshold1', c_double, 1), # double threshold1 3483 ('threshold2', c_double, 1), # double threshold2 3484 ) 3485 3486 # --- 1.6 Connected Components ----------------------------------------------- 3487 3488 3489 # Fills a connected component with given color 3490 cvFloodFill = cfunc('cvFloodFill', _cvDLL, None, 3491 ('image', c_void_p, 1), # CvArr* image 3492 ('seed_point', CvPoint, 1), # CvPoint seed_point 3493 ('new_val', CvScalar, 1), # CvScalar new_val 3494 ('lo_diff', CvScalar, 1), # CvScalar lo_diff 3495 ('up_diff', CvScalar, 1), # CvScalar up_diff 3496 ('comp', POINTER(CvConnectedComp), 1, None), # CvConnectedComp* comp 3497 ('flags', c_int, 1, 4), # int flags 3498 ('mask', c_void_p, 1, None), # CvArr* mask 3499 ) 3500 3501 CV_FLOODFILL_FIXED_RANGE = 1 << 16 3502 CV_FLOODFILL_MASK_ONLY = 1 << 17 3503 3504 # Finds contours in binary image 3505 cvFindContours = cfunc('cvFindContours', _cvDLL, c_int, 3506 ('image', c_void_p, 1), # CvArr* image 3507 ('storage', POINTER(CvMemStorage), 1), # CvMemStorage* storage 3508 ('first_contour', POINTER(POINTER(CvSeq)), 1), # CvSeq** first_contour 3509 ('header_size', c_int, 1), # int header_size 3510 ('mode', c_int, 1), # int mode 3511 ('method', c_int, 1), # int method 3512 ('offset', CvPoint, 1), # CvPoint offset 3513 ) 3514 3515 # Initializes contour scanning process 3516 cvStartFindContours = cfunc('cvStartFindContours', _cvDLL, CvContourScanner, 3517 ('image', c_void_p, 1), # CvArr* image 3518 ('storage', POINTER(CvMemStorage), 1), # CvMemStorage* storage 3519 ('header_size', c_int, 1), # int header_size 3520 ('mode', c_int, 1), # int mode 3521 ('method', c_int, 1), # int method 3522 ('offset', CvPoint, 1), # CvPoint offset 3523 ) 3524 3525 # Finds next contour in the image 3526 cvFindNextContour = cfunc('cvFindNextContour', _cvDLL, POINTER(CvSeq), 3527 ('scanner', CvContourScanner, 1), # CvContourScanner scanner 3528 ) 3529 3530 # Replaces retrieved contour 3531 cvSubstituteContour = cfunc('cvSubstituteContour', _cvDLL, None, 3532 ('scanner', CvContourScanner, 1), # CvContourScanner scanner 3533 ('new_contour', POINTER(CvSeq), 1), # CvSeq* new_contour 3534 ) 3535 3536 # Finishes scanning process 3537 cvEndFindContours = cfunc('cvEndFindContours', _cvDLL, POINTER(CvSeq), 3538 ('scanner', POINTER(CvContourScanner), 1), # CvContourScanner* scanner 3539 ) 3540 3541 # --- 1.7 Image and Contour moments ------------------------------------------ 3542 3543 # Calculates all moments up to third order of a polygon or rasterized shape 3544 cvMoments = cfunc('cvMoments', _cvDLL, None, 3545 ('arr', c_void_p, 1), # const CvArr* arr 3546 ('moments', POINTER(CvMOMENTS), 1), # CvMoments* moments 3547 ('binary', c_int, 1, 0), # int binary 3548 ) 3549 3550 # Retrieves spatial moment from moment state structure 3551 cvGetSpatialMoment = cfunc('cvGetSpatialMoment', _cvDLL, c_double, 3552 ('moments', POINTER(CvMOMENTS), 1), # CvMoments* moments 3553 ('x_order', c_int, 1), # int x_order 3554 ('y_order', c_int, 1), # int y_order 3555 ) 3556 3557 # Retrieves central moment from moment state structure 3558 cvGetCentralMoment = cfunc('cvGetCentralMoment', _cvDLL, c_double, 3559 ('moments', POINTER(CvMOMENTS), 1), # CvMoments* moments 3560 ('x_order', c_int, 1), # int x_order 3561 ('y_order', c_int, 1), # int y_order 3562 ) 3563 3564 # Retrieves normalized central moment from moment state structure 3565 cvGetNormalizedCentralMoment = cfunc('cvGetNormalizedCentralMoment', _cvDLL, c_double, 3566 ('moments', POINTER(CvMOMENTS), 1), # CvMoments* moments 3567 ('x_order', c_int, 1), # int x_order 3568 ('y_order', c_int, 1), # int y_order 3569 ) 3570 3571 # Calculates seven Hu invariants 3572 cvGetHuMoments = cfunc('cvGetHuMoments', _cvDLL, None, 3573 ('moments', POINTER(CvMOMENTS), 1), # CvMoments* moments 3574 ('hu_moments', POINTER(CvHuMoments), 1), # CvHuMoments* hu_moments 3575 ) 3576 3577 # --- 1.8 Special Image Transforms ------------------------------------------- 3578 3579 # Finds lines in binary image using Hough transform 3580 cvHoughLines2 = cfunc('cvHoughLines2', _cvDLL, POINTER(CvSeq), 3581 ('image', c_void_p, 1), # CvArr* image 3582 ('line_storage', c_void_p, 1), # void* line_storage 3583 ('method', c_int, 1), # int method 3584 ('rho', c_double, 1), # double rho 3585 ('theta', c_double, 1), # double theta 3586 ('threshold', c_int, 1), # int threshold 3587 ('param1', c_double, 1, 0), # double param1 3588 ('param2', c_double, 1, 0), # double param2 3589 ) 3590 3591 # Finds circles in grayscale image using Hough transform 3592 cvHoughCircles = cfunc('cvHoughCircles', _cvDLL, POINTER(CvSeq), 3593 ('image', c_void_p, 1), # CvArr* image 3594 ('circle_storage', c_void_p, 1), # void* circle_storage 3595 ('method', c_int, 1), # int method 3596 ('dp', c_double, 1), # double dp 3597 ('min_dist', c_double, 1), # double min_dist 3598 ('param1', c_double, 1, 100), # double param1 3599 ('param2', c_double, 1, 100), # double param2 3600 ) 3601 3602 # Calculates distance to closest zero pixel for all non-zero pixels of source image 3603 cvDistTransform = cfunc('cvDistTransform', _cvDLL, None, 3604 ('src', c_void_p, 1), # const CvArr* src 3605 ('dst', c_void_p, 1), # CvArr* dst 3606 ('distance_type', c_int, 1), # int distance_type 3607 ('mask_size', c_int, 1, 3), # int mask_size 3608 ('mask', POINTER(c_float), 1, None), # const float* mask 3609 ('labels', c_void_p, 1, None), # CvArr* labels 3610 ) 3611 3612 # --- 1.9 Histograms --------------------------------------------------------- 3613 CV_HIST_ARRAY = 0 3614 CV_HIST_SPARSE = 1 3615 3616 # Creates histogram 3617 cvCreateHist = cfunc('cvCreateHist', _cvDLL, POINTER(CvHistogram), 3618 ('dims', c_int, 1), # int dims 3619 ('sizes', ListPOINTER(c_int), 1), # int* sizes 3620 ('type', c_int, 1), # int type 3621 ('ranges', ListPOINTER2(c_float), 1, None), # float** ranges=NULL 3622 ('uniform', c_int, 1, 1), # int uniform=1 3623 ) 3624 3625 # Sets bounds of histogram bins 3626 cvSetHistBinRanges = cfunc('cvSetHistBinRanges', _cvDLL, None, 3627 ('hist', POINTER(CvHistogram), 1), # CvHistogram* hist 3628 ('ranges', ListPOINTER2(c_float), 1), # float** ranges 3629 ('uniform', c_int, 1, 1), # int uniform 3630 ) 3631 3632 # Releases histogram 3633 cvReleaseHist = cfunc('cvReleaseHist', _cvDLL, None, 3634 ('hist', ByRefArg(POINTER(CvHistogram)), 1), # CvHistogram** hist 3635 ) 3636 3637 # Clears histogram 3638 cvClearHist = cfunc('cvClearHist', _cvDLL, None, 3639 ('hist', POINTER(CvHistogram), 1), # CvHistogram* hist 3640 ) 3641 3642 # Makes a histogram out of array 3643 cvMakeHistHeaderForArray = cfunc('cvMakeHistHeaderForArray', _cvDLL, POINTER(CvHistogram), 3644 ('dims', c_int, 1), # int dims 3645 ('sizes', POINTER(c_int), 1), # int* sizes 3646 ('hist', POINTER(CvHistogram), 1), # CvHistogram* hist 3647 ('data', POINTER(c_float), 1), # float* data 3648 ('ranges', ListPOINTER2(c_float), 1, None), # float** ranges 3649 ('uniform', c_int, 1, 1), # int uniform 3650 ) 3651 3652 # Finds minimum and maximum histogram bins 3653 cvGetMinMaxHistValue = cfunc('cvGetMinMaxHistValue', _cvDLL, None, 3654 ('hist', POINTER(CvHistogram), 1), # const CvHistogram* hist 3655 ('min_value', POINTER(c_float), 2), # float* min_value 3656 ('max_value', POINTER(c_float), 2), # float* max_value 3657 ('min_idx', POINTER(c_int), 2), # int* min_idx 3658 ('max_idx', POINTER(c_int), 2), # int* max_idx 3659 ) 3660 3661 # Normalizes histogram 3662 cvNormalizeHist = cfunc('cvNormalizeHist', _cvDLL, None, 3663 ('hist', POINTER(CvHistogram), 1), # CvHistogram* hist 3664 ('factor', c_double, 1), # double factor 3665 ) 3666 3667 # Thresholds histogram 3668 cvThreshHist = cfunc('cvThreshHist', _cvDLL, None, 3669 ('hist', POINTER(CvHistogram), 1), # CvHistogram* hist 3670 ('threshold', c_double, 1), # double threshold 3671 ) 3672 3673 CV_COMP_CORREL = 0 3674 CV_COMP_CHISQR = 1 3675 CV_COMP_INTERSECT = 2 3676 CV_COMP_BHATTACHARYYA= 3 3677 3678 # Compares two dense histograms 3679 cvCompareHist = cfunc('cvCompareHist', _cvDLL, c_double, 3680 ('hist1', POINTER(CvHistogram), 1), # const CvHistogram* hist1 3681 ('hist2', POINTER(CvHistogram), 1), # const CvHistogram* hist2 3682 ('method', c_int, 1), # int method 3683 ) 3684 3685 # Copies histogram 3686 cvCopyHist = cfunc('cvCopyHist', _cvDLL, None, 3687 ('src', POINTER(CvHistogram), 1), # const CvHistogram* src 3688 ('dst', POINTER(POINTER(CvHistogram)), 1), # CvHistogram** dst 3689 ) 3690 3691 # Calculate the histogram 3692 cvCalcHist = cfunc('cvCalcArrHist', _cvDLL, None, 3693 ('image', ListPOINTER(POINTER(IplImage)), 1), # IplImage** image 3694 ('hist', POINTER(CvHistogram), 1), # CvHistogram* hist 3695 ('accumulate', c_int, 1, 0), # int accumulate 3696 ('mask', c_void_p, 1, None), # CvArr* mask 3697 ) 3698 3699 # Calculates back projection 3700 cvCalcBackProject = cfunc('cvCalcArrBackProject', _cvDLL, None, 3701 ('image', ListPOINTER(POINTER(IplImage)), 1), # IplImage** image 3702 ('back_project', POINTER(IplImage), 1), # IplImage* back_project 3703 ('hist', POINTER(CvHistogram), 1), # CvHistogram* hist 3704 ) 3705 3706 # Divides one histogram by another 3707 cvCalcProbDensity = cfunc('cvCalcProbDensity', _cvDLL, None, 3708 ('hist1', POINTER(CvHistogram), 1), # const CvHistogram* hist1 3709 ('hist2', POINTER(CvHistogram), 1), # const CvHistogram* hist2 3710 ('dst_hist', POINTER(CvHistogram), 1), # CvHistogram* dst_hist 3711 ('scale', c_double, 1, 255), # double scale 3712 ) 3713
3714 -def QueryHistValue_1D(hist, i1, i2):
3715 return cvGetReal1D(hist[0].bins, i1)
3716
3717 -def QueryHistValue_2D(hist, i1, i2):
3718 return cvGetReal2D(hist[0].bins, i1, i2)
3719
3720 -def QueryHistValue_3D(hist, i1, i2, i3):
3721 return cvGetReal2D(hist[0].bins, i1, i2, i3)
3722 3723 # Equalizes histogram of grayscale image 3724 cvEqualizeHist = cfunc('cvEqualizeHist', _cvDLL, None, 3725 ('src', c_void_p, 1), # const CvArr* src 3726 ('dst', c_void_p, 1), # CvArr* dst 3727 ) 3728 3729 # --- 1.10 Matching ---------------------------------------------------------- 3730 3731 # Compares template against overlapped image regions 3732 cvMatchTemplate = cfunc('cvMatchTemplate', _cvDLL, None, 3733 ('image', c_void_p, 1), # const CvArr* image 3734 ('templ', c_void_p, 1), # const CvArr* templ 3735 ('result', c_void_p, 1), # CvArr* result 3736 ('method', c_int, 1), # int method 3737 ) 3738 3739 # Compares two shapes 3740 cvMatchShapes = cfunc('cvMatchShapes', _cvDLL, c_double, 3741 ('object1', c_void_p, 1), # const void* object1 3742 ('object2', c_void_p, 1), # const void* object2 3743 ('method', c_int, 1), # int method 3744 ('parameter', c_double, 1, 0), # double parameter 3745 ) 3746 3747 # Computes "minimal work" distance between two weighted point configurations 3748 CvDistanceFunction = CFUNCTYPE(c_float, # float 3749 c_void_p, # const float* f1 3750 c_void_p, # const float* f2 3751 c_void_p) # void* userdata 3752 3753 cvCalcEMD2 = cfunc('cvCalcEMD2', _cvDLL, c_float, 3754 ('signature1', c_void_p, 1), # const CvArr* signature1 3755 ('signature2', c_void_p, 1), # const CvArr* signature2 3756 ('distance_type', c_int, 1), # int distance_type 3757 ('distance_func', CvDistanceFunction, 1, None), # CvDistanceFunction distance_func 3758 ('cost_matrix', c_void_p, 1, None), # const CvArr* cost_matrix 3759 ('flow', c_void_p, 1, None), # CvArr* flow 3760 ('lower_bound', POINTER(c_float), 1, None), # float* lower_bound 3761 ('userdata', c_void_p, 1, None), # void* userdata 3762 ) 3763 3764 # --- 2 Structural Analysis -------------------------------------------------- 3765 3766 # --- 2.1 Contour Processing Functions --------------------------------------- 3767 3768 # Approximates Freeman chain(s) with polygonal curve 3769 cvApproxChains = cfunc('cvApproxChains', _cvDLL, POINTER(CvSeq), 3770 ('src_seq', POINTER(CvSeq), 1), # CvSeq* src_seq 3771 ('storage', POINTER(CvMemStorage), 1), # CvMemStorage* storage 3772 ('method', c_int, 1), # int method 3773 ('parameter', c_double, 1, 0), # double parameter 3774 ('minimal_perimeter', c_int, 1, 0), # int minimal_perimeter 3775 ('recursive', c_int, 1, 0), # int recursive 3776 ) 3777 3778 # Initializes chain reader 3779 cvStartReadChainPoints = cfunc('cvStartReadChainPoints', _cvDLL, None, 3780 ('chain', POINTER(CvChain), 1), # CvChain* chain 3781 ('reader', POINTER(CvChainPtReader), 1), # CvChainPtReader* reader 3782 ) 3783 3784 # Gets next chain point 3785 cvReadChainPoint = cfunc('cvReadChainPoint', _cvDLL, CvPoint, 3786 ('reader', POINTER(CvChainPtReader), 1), # CvChainPtReader* reader 3787 ) 3788 3789 # Approximates polygonal curve(s) with desired precision 3790 cvApproxPoly = cfunc('cvApproxPoly', _cvDLL, POINTER(CvSeq), 3791 ('src_seq', c_void_p, 1), # const void* src_seq 3792 ('header_size', c_int, 1), # int header_size 3793 ('storage', POINTER(CvMemStorage), 1), # CvMemStorage* storage 3794 ('method', c_int, 1), # int method 3795 ('parameter', c_double, 1), # double parameter 3796 ('parameter2', c_int, 1, 0), # int parameter2 3797 ) 3798 3799 # Calculates up-right bounding rectangle of point set 3800 cvBoundingRect = cfunc('cvBoundingRect', _cvDLL, CvRect, 3801 ('points', c_void_p, 1), # CvArr* points 3802 ('update', c_int, 1, 0), # int update 3803 ) 3804 3805 # Calculates area of the whole contour or contour section 3806 cvContourArea = cfunc('cvContourArea', _cvDLL, c_double, 3807 ('contour', c_void_p, 1), # const CvArr* contour 3808 ('slice', CvSlice, 1), # CvSlice slice 3809 ) 3810 3811 # Calculates contour perimeter or curve length 3812 cvArcLength = cfunc('cvArcLength', _cvDLL, c_double, 3813 ('curve', c_void_p, 1), # const void* curve 3814 ('slice', CvSlice, 1), # CvSlice slice 3815 ('is_closed', c_int, 1), # int is_closed 3816 ) 3817 3818 # Creates hierarchical representation of contour 3819 cvCreateContourTree = cfunc('cvCreateContourTree', _cvDLL, POINTER(CvContourTree), 3820 ('contour', POINTER(CvSeq), 1), # const CvSeq* contour 3821 ('storage', POINTER(CvMemStorage), 1), # CvMemStorage* storage 3822 ('threshold', c_double, 1), # double threshold 3823 ) 3824 3825 # Restores contour from tree 3826 cvContourFromContourTree = cfunc('cvContourFromContourTree', _cvDLL, POINTER(CvSeq), 3827 ('tree', POINTER(CvContourTree), 1), # const CvContourTree* tree 3828 ('storage', POINTER(CvMemStorage), 1), # CvMemStorage* storage 3829 ('criteria', CvTermCriteria, 1), # CvTermCriteria criteria 3830 ) 3831 3832 # Compares two contours using their tree representations 3833 cvMatchContourTrees = cfunc('cvMatchContourTrees', _cvDLL, c_double, 3834 ('tree1', POINTER(CvContourTree), 1), # const CvContourTree* tree1 3835 ('tree2', POINTER(CvContourTree), 1), # const CvContourTree* tree2 3836 ('method', c_int, 1), # int method 3837 ('threshold', c_double, 1), # double threshold 3838 ) 3839 3840 # --- 2.2 Computational Geometry --------------------------------------------- 3841 3842 # Finds bounding rectangle for two given rectangles 3843 cvMaxRect = cfunc('cvMaxRect', _cvDLL, CvRect, 3844 ('rect1', POINTER(CvRect), 1), # const CvRect* rect1 3845 ('rect2', POINTER(CvRect), 1), # const CvRect* rect2 3846 ) 3847 3848 # Initializes point sequence header from a point vector 3849 cvPointSeqFromMat = cfunc('cvPointSeqFromMat', _cvDLL, POINTER(CvSeq), 3850 ('seq_kind', c_int, 1), # int seq_kind 3851 ('mat', c_void_p, 1), # const CvArr* mat 3852 ('contour_header', POINTER(CvContour), 1), # CvContour* contour_header 3853 ('block', POINTER(CvSeqBlock), 1), # CvSeqBlock* block 3854 ) 3855 3856 # Finds box vertices 3857 cvBoxPoints = cfunc('cvBoxPoints', _cvDLL, None, 3858 ('box', CvBox2D, 1), # CvBox2D box 3859 ('pt', CvPoint2D32f, 1), # CvPoint2D32f pt 3860 ) 3861 3862 # Fits ellipse to set of 2D points 3863 cvFitEllipse2 = cfunc('cvFitEllipse2', _cvDLL, CvBox2D, 3864 ('points', c_void_p, 1), # const CvArr* points 3865 ) 3866 3867 # Fits line to 2D or 3D point set 3868 cvFitLine = cfunc('cvFitLine', _cvDLL, None, 3869 ('points', c_void_p, 1), # const CvArr* points 3870 ('dist_type', c_int, 1), # int dist_type 3871 ('param', c_double, 1), # double param 3872 ('reps', c_double, 1), # double reps 3873 ('aeps', c_double, 1), # double aeps 3874 ('line', POINTER(c_float), 1), # float* line 3875 ) 3876 3877 # Finds convex hull of point set 3878 cvConvexHull2 = cfunc('cvConvexHull2', _cvDLL, POINTER(CvSeq), 3879 ('input', c_void_p, 1), # const CvArr* input 3880 ('hull_storage', c_void_p, 1, None), # void* hull_storage 3881 ('orientation', c_int, 1), # int orientation 3882 ('return_points', c_int, 1, 0), # int return_points 3883 ) 3884 3885 # Tests contour convex 3886 cvCheckContourConvexity = cfunc('cvCheckContourConvexity', _cvDLL, c_int, 3887 ('contour', c_void_p, 1), # const CvArr* contour 3888 ) 3889 3890 # Finds convexity defects of contour 3891 cvConvexityDefects = cfunc('cvConvexityDefects', _cvDLL, POINTER(CvSeq), 3892 ('contour', c_void_p, 1), # const CvArr* contour 3893 ('convexhull', c_void_p, 1), # const CvArr* convexhull 3894 ('storage', POINTER(CvMemStorage), 1, None), # CvMemStorage* storage 3895 ) 3896 3897 # Point in contour test 3898 cvPointPolygonTest = cfunc('cvPointPolygonTest', _cvDLL, c_double, 3899 ('contour', c_void_p, 1), # const CvArr* contour 3900 ('pt', CvPoint2D32f, 1), # CvPoint2D32f pt 3901 ('measure_dist', c_int, 1), # int measure_dist 3902 ) 3903 3904 # Finds circumscribed rectangle of minimal area for given 2D point set 3905 cvMinAreaRect2 = cfunc('cvMinAreaRect2', _cvDLL, CvBox2D, 3906 ('points', c_void_p, 1), # const CvArr* points 3907 ('storage', POINTER(CvMemStorage), 1, None), # CvMemStorage* storage 3908 ) 3909 3910 # Finds circumscribed circle of minimal area for given 2D point set 3911 cvMinEnclosingCircle = cfunc('cvMinEnclosingCircle', _cvDLL, c_int, 3912 ('points', c_void_p, 1), # const CvArr* points 3913 ('center', POINTER(CvPoint2D32f), 1), # CvPoint2D32f* center 3914 ('radius', POINTER(c_float), 1), # float* radius 3915 ) 3916 3917 # Calculates pair-wise geometrical histogram for contour 3918 cvCalcPGH = cfunc('cvCalcPGH', _cvDLL, None, 3919 ('contour', POINTER(CvSeq), 1), # const CvSeq* contour 3920 ('hist', POINTER(CvHistogram), 1), # CvHistogram* hist 3921 ) 3922 3923 # --- 2.3 Planar Subdivisions ------------------------------------------------ 3924 3925 # Inserts a single point to Delaunay triangulation 3926 cvSubdivDelaunay2DInsert = cfunc('cvSubdivDelaunay2DInsert', _cvDLL, POINTER(CvSubdiv2DPoint), 3927 ('subdiv', POINTER(CvSubdiv2D), 1), # CvSubdiv2D* subdiv 3928 ('pt', CvPoint2D32f, 1), # CvPoint2D32f pt 3929 ) 3930 3931 # Inserts a single point to Delaunay triangulation 3932 cvSubdiv2DLocate = cfunc('cvSubdiv2DLocate', _cvDLL, CvSubdiv2DPointLocation, 3933 ('subdiv', POINTER(CvSubdiv2D), 1), # CvSubdiv2D* subdiv 3934 ('pt', CvPoint2D32f, 1), # CvPoint2D32f pt 3935 ('edge', POINTER(CvSubdiv2DEdge), 1), # CvSubdiv2DEdge* edge 3936 ('vertex', POINTER(POINTER(CvSubdiv2DPoint)), 1, None), # CvSubdiv2DPoint** vertex 3937 ) 3938 3939 # Finds the closest subdivision vertex to given point 3940 cvFindNearestPoint2D = cfunc('cvFindNearestPoint2D', _cvDLL, POINTER(CvSubdiv2DPoint), 3941 ('subdiv', POINTER(CvSubdiv2D), 1), # CvSubdiv2D* subdiv 3942 ('pt', CvPoint2D32f, 1), # CvPoint2D32f pt 3943 ) 3944 3945 # Calculates coordinates of Voronoi diagram cells 3946 cvCalcSubdivVoronoi2D = cfunc('cvCalcSubdivVoronoi2D', _cvDLL, None, 3947 ('subdiv', POINTER(CvSubdiv2D), 1), # CvSubdiv2D* subdiv 3948 ) 3949 3950 # Removes all virtual points 3951 cvClearSubdivVoronoi2D = cfunc('cvClearSubdivVoronoi2D', _cvDLL, None, 3952 ('subdiv', POINTER(CvSubdiv2D), 1), # CvSubdiv2D* subdiv 3953 ) 3954 3955 # --- 3 Motion Analysis and Object Tracking ---------------------------------- 3956 3957 # --- 3.1 Accumulation of Background Statistics ------------------------------ 3958 3959 # Adds frame to accumulator 3960 cvAcc = cfunc('cvAcc', _cvDLL, None, 3961 ('image', c_void_p, 1), # const CvArr* image 3962 ('sum', c_void_p, 1), # CvArr* sum 3963 ('mask', c_void_p, 1, None), # const CvArr* mask 3964 ) 3965 3966 # Adds the square of source image to accumulator 3967 cvSquareAcc = cfunc('cvSquareAcc', _cvDLL, None, 3968 ('image', c_void_p, 1), # const CvArr* image 3969 ('sqsum', c_void_p, 1), # CvArr* sqsum 3970 ('mask', c_void_p, 1, None), # const CvArr* mask 3971 ) 3972 3973 # Adds product of two input images to accumulator 3974 cvMultiplyAcc = cfunc('cvMultiplyAcc', _cvDLL, None, 3975 ('image1', c_void_p, 1), # const CvArr* image1 3976 ('image2', c_void_p, 1), # const CvArr* image2 3977 ('acc', c_void_p, 1), # CvArr* acc 3978 ('mask', c_void_p, 1, None), # const CvArr* mask 3979 ) 3980 3981 # Updates running average 3982 cvRunningAvg = cfunc('cvRunningAvg', _cvDLL, None, 3983 ('image', c_void_p, 1), # const CvArr* image 3984 ('acc', c_void_p, 1), # CvArr* acc 3985 ('alpha', c_double, 1), # double alpha 3986 ('mask', c_void_p, 1, None), # const CvArr* mask 3987 ) 3988 3989 # --- 3.2 Motion Templates --------------------------------------------------- 3990 3991 # Updates motion history image by moving silhouette 3992 cvUpdateMotionHistory = cfunc('cvUpdateMotionHistory', _cvDLL, None, 3993 ('silhouette', c_void_p, 1), # const CvArr* silhouette 3994 ('mhi', c_void_p, 1), # CvArr* mhi 3995 ('timestamp', c_double, 1), # double timestamp 3996 ('duration', c_double, 1), # double duration 3997 ) 3998 3999 # Calculates gradient orientation of motion history image 4000 cvCalcMotionGradient = cfunc('cvCalcMotionGradient', _cvDLL, None, 4001 ('mhi', c_void_p, 1), # const CvArr* mhi 4002 ('mask', c_void_p, 1), # CvArr* mask 4003 ('orientation', c_void_p, 1), # CvArr* orientation 4004 ('delta1', c_double, 1), # double delta1 4005 ('delta2', c_double, 1), # double delta2 4006 ('aperture_size', c_int, 1, 3), # int aperture_size 4007 ) 4008 4009 # Calculates global motion orientation of some selected region 4010 cvCalcGlobalOrientation = cfunc('cvCalcGlobalOrientation', _cvDLL, c_double, 4011 ('orientation', c_void_p, 1), # const CvArr* orientation 4012 ('mask', c_void_p, 1), # const CvArr* mask 4013 ('mhi', c_void_p, 1), # const CvArr* mhi 4014 ('timestamp', c_double, 1), # double timestamp 4015 ('duration', c_double, 1), # double duration 4016 ) 4017 4018 # Segments whole motion into separate moving parts 4019 cvSegmentMotion = cfunc('cvSegmentMotion', _cvDLL, POINTER(CvSeq), 4020 ('mhi', c_void_p, 1), # const CvArr* mhi 4021 ('seg_mask', c_void_p, 1), # CvArr* seg_mask 4022 ('storage', POINTER(CvMemStorage), 1), # CvMemStorage* storage 4023 ('timestamp', c_double, 1), # double timestamp 4024 ('seg_thresh', c_double, 1), # double seg_thresh 4025 ) 4026 4027 # --- 3.3 Object Tracking ---------------------------------------------------- 4028 4029 # Finds object center on back projection 4030 cvMeanShift = cfunc('cvMeanShift', _cvDLL, c_int, 4031 ('prob_image', c_void_p, 1), # const CvArr* prob_image 4032 ('window', CvRect, 1), # CvRect window 4033 ('criteria', CvTermCriteria, 1), # CvTermCriteria criteria 4034 ('comp', POINTER(CvConnectedComp), 1), # CvConnectedComp* comp 4035 ) 4036 4037 # Finds object center, size, and orientation 4038 cvCamShift = cfunc('cvCamShift', _cvDLL, c_int, 4039 ('prob_image', c_void_p, 1), # const CvArr* prob_image 4040 ('window', CvRect, 1), # CvRect window 4041 ('criteria', CvTermCriteria, 1), # CvTermCriteria criteria 4042 ('comp', POINTER(CvConnectedComp), 2), # CvConnectedComp* comp 4043 ('box', POINTER(CvBox2D), 2), # CvBox2D* box 4044 ) 4045 4046 # Changes contour position to minimize its energy 4047 cvSnakeImage = cfunc('cvSnakeImage', _cvDLL, None, 4048 ('image', POINTER(IplImage), 1), # const IplImage* image 4049 ('points', POINTER(CvPoint), 1), # CvPoint* points 4050 ('length', c_int, 1), # int length 4051 ('alpha', POINTER(c_float), 1), # float* alpha 4052 ('beta', POINTER(c_float), 1), # float* beta 4053 ('gamma', POINTER(c_float), 1), # float* gamma 4054 ('coeff_usage', c_int, 1), # int coeff_usage 4055 ('win', CvSize, 1), # CvSize win 4056 ('criteria', CvTermCriteria, 1), # CvTermCriteria criteria 4057 ('calc_gradient', c_int, 1, 1), # int calc_gradient 4058 ) 4059 4060 # --- 3.4 Optical Flow ------------------------------------------------------- 4061 4062 # Calculates optical flow for two images 4063 cvCalcOpticalFlowHS = cfunc('cvCalcOpticalFlowHS', _cvDLL, None, 4064 ('prev', c_void_p, 1), # const CvArr* prev 4065 ('curr', c_void_p, 1), # const CvArr* curr 4066 ('use_previous', c_int, 1), # int use_previous 4067 ('velx', c_void_p, 1), # CvArr* velx 4068 ('vely', c_void_p, 1), # CvArr* vely 4069 ('lambda', c_double, 1), # double lambda 4070 ('criteria', CvTermCriteria, 1), # CvTermCriteria criteria 4071 ) 4072 4073 # Calculates optical flow for two images 4074 cvCalcOpticalFlowLK = cfunc('cvCalcOpticalFlowLK', _cvDLL, None, 4075 ('prev', c_void_p, 1), # const CvArr* prev 4076 ('curr', c_void_p, 1), # const CvArr* curr 4077 ('win_size', CvSize, 1), # CvSize win_size 4078 ('velx', c_void_p, 1), # CvArr* velx 4079 ('vely', c_void_p, 1), # CvArr* vely 4080 ) 4081 4082 # Calculates optical flow for two images by block matching method 4083 cvCalcOpticalFlowBM = cfunc('cvCalcOpticalFlowBM', _cvDLL, None, 4084 ('prev', c_void_p, 1), # const CvArr* prev 4085 ('curr', c_void_p, 1), # const CvArr* curr 4086 ('block_size', CvSize, 1), # CvSize block_size 4087 ('shift_size', CvSize, 1), # CvSize shift_size 4088 ('max_range', CvSize, 1), # CvSize max_range 4089 ('use_previous', c_int, 1), # int use_previous 4090 ('velx', c_void_p, 1), # CvArr* velx 4091 ('vely', c_void_p, 1), # CvArr* vely 4092 ) 4093 4094 # Calculates optical flow for a sparse feature set using iterative Lucas-Kanade method in pyramids 4095 cvCalcOpticalFlowPyrLK = cfunc('cvCalcOpticalFlowPyrLK', _cvDLL, None, 4096 ('prev', c_void_p, 1), # const CvArr* prev 4097 ('curr', c_void_p, 1), # const CvArr* curr 4098 ('prev_pyr', c_void_p, 1), # CvArr* prev_pyr 4099 ('curr_pyr', c_void_p, 1), # CvArr* curr_pyr 4100 ('prev_features', POINTER(CvPoint2D32f), 1), # const CvPoint2D32f* prev_features 4101 ('curr_features', POINTER(CvPoint2D32f), 1), # CvPoint2D32f* curr_features 4102 ('count', c_int, 1), # int count 4103 ('win_size', CvSize, 1), # CvSize win_size 4104 ('level', c_int, 1), # int level 4105 ('status', c_char_p, 1), # char* status 4106 ('track_error', POINTER(c_float), 1), # float* track_error 4107 ('criteria', CvTermCriteria, 1), # CvTermCriteria criteria 4108 ('flags', c_int, 1), # int flags 4109 ) 4110 4111 # --- 3.5 Estimators --------------------------------------------------------- 4112 4113 # Allocates Kalman filter structure 4114 cvCreateKalman = cfunc('cvCreateKalman', _cvDLL, POINTER(CvKalman), 4115 ('dynam_params', c_int, 1), # int dynam_params 4116 ('measure_params', c_int, 1), # int measure_params 4117 ('control_params', c_int, 1, 0), # int control_params 4118 ) 4119 4120 # Deallocates Kalman filter structure 4121 cvReleaseKalman = cfunc('cvReleaseKalman', _cvDLL, None, 4122 ('kalman', POINTER(POINTER(CvKalman)), 1), # CvKalman** kalman 4123 ) 4124 4125 # Estimates subsequent model state 4126 cvKalmanPredict = cfunc('cvKalmanPredict', _cvDLL, POINTER(CvMat), 4127 ('kalman', POINTER(CvKalman), 1), # CvKalman* kalman 4128 ('control', POINTER(CvMat), 1, None), # const CvMat* control 4129 ) 4130 4131 cvKalmanUpdateByTime = cvKalmanPredict 4132 4133 # Adjusts model state 4134 cvKalmanCorrect = cfunc('cvKalmanCorrect', _cvDLL, POINTER(CvMat), 4135 ('kalman', POINTER(CvKalman), 1), # CvKalman* kalman 4136 ('measurement', POINTER(CvMat), 1), # const CvMat* measurement 4137 ) 4138 4139 cvKalmanUpdateByMeasurement = cvKalmanCorrect 4140 4141 # Allocates ConDensation filter structure 4142 cvCreateConDensation = cfunc('cvCreateConDensation', _cvDLL, POINTER(CvConDensation), 4143 ('dynam_params', c_int, 1), # int dynam_params 4144 ('measure_params', c_int, 1), # int measure_params 4145 ('sample_count', c_int, 1), # int sample_count 4146 ) 4147 4148 # Deallocates ConDensation filter structure 4149 cvReleaseConDensation = cfunc('cvReleaseConDensation', _cvDLL, None, 4150 ('condens', POINTER(POINTER(CvConDensation)), 1), # CvConDensation** condens 4151 ) 4152 4153 # Initializes sample set for ConDensation algorithm 4154 cvConDensInitSampleSet = cfunc('cvConDensInitSampleSet', _cvDLL, None, 4155 ('condens', POINTER(CvConDensation), 1), # CvConDensation* condens 4156 ('lower_bound', POINTER(CvMat), 1), # CvMat* lower_bound 4157 ('upper_bound', POINTER(CvMat), 1), # CvMat* upper_bound 4158 ) 4159 4160 # Estimates subsequent model state 4161 cvConDensUpdateByTime = cfunc('cvConDensUpdateByTime', _cvDLL, None, 4162 ('condens', POINTER(CvConDensation), 1), # CvConDensation* condens 4163 ) 4164 4165 # --- 4 Pattern Recognition -------------------------------------------------- 4166 4167 # --- 4.1 Object Detection --------------------------------------------------- 4168 4169 # Loads a trained cascade classifier from file or the classifier database embedded in OpenCV 4170 cvLoadHaarClassifierCascade = cfunc('cvLoadHaarClassifierCascade', _cvDLL, POINTER(CvHaarClassifierCascade), 4171 ('directory', c_char_p, 1), # const char* directory 4172 ('orig_window_size', CvSize, 1), # CvSize orig_window_size 4173 ) 4174 4175 # Releases haar classifier cascade 4176 cvReleaseHaarClassifierCascade = cfunc('cvReleaseHaarClassifierCascade', _cvDLL, None, 4177 ('cascade', POINTER(POINTER(CvHaarClassifierCascade)), 1), # CvHaarClassifierCascade** cascade 4178 ) 4179 4180 # Detects objects in the image 4181 cvHaarDetectObjects = cfunc('cvHaarDetectObjects', _cvDLL, POINTER(CvSeq), 4182 ('image', c_void_p, 1), # const CvArr* image 4183 ('cascade', POINTER(CvHaarClassifierCascade), 1), # CvHaarClassifierCascade* cascade 4184 ('storage', POINTER(CvMemStorage), 1), # CvMemStorage* storage 4185 ('scale_factor', c_double, 1, 1), # double scale_factor 4186 ('min_neighbors', c_int, 1, 3), # int min_neighbors 4187 ('flags', c_int, 1, 0), # int flags 4188 ('min_size', CvSize, 1), # CvSize min_size 4189 )
4190 -def ChangeCvSeqToCvRect(result, func, args):
4191 '''Handle the casting to extract a list of Rects from the Seq returned''' 4192 res = [] 4193 for i in xrange(result[0].total): 4194 f = cvGetSeqElem(result, i) 4195 r = ctypes.cast(f, ctypes.POINTER(CvRect))[0] 4196 res.append(r) 4197 return res
4198 cvHaarDetectObjects.errcheck = ChangeCvSeqToCvRect 4199 4200 4201 # Assigns images to the hidden cascade 4202 cvSetImagesForHaarClassifierCascade = cfunc('cvSetImagesForHaarClassifierCascade', _cvDLL, None, 4203 ('cascade', POINTER(CvHaarClassifierCascade), 1), # CvHaarClassifierCascade* cascade 4204 ('sum', c_void_p, 1), # const CvArr* sum 4205 ('sqsum', c_void_p, 1), # const CvArr* sqsum 4206 ('tilted_sum', c_void_p, 1), # const CvArr* tilted_sum 4207 ('scale', c_double, 1), # double scale 4208 ) 4209 4210 # Runs cascade of boosted classifier at given image location 4211 cvRunHaarClassifierCascade = cfunc('cvRunHaarClassifierCascade', _cvDLL, c_int, 4212 ('cascade', POINTER(CvHaarClassifierCascade), 1), # CvHaarClassifierCascade* cascade 4213 ('pt', CvPoint, 1), # CvPoint pt 4214 ('start_stage', c_int, 1, 0), # int start_stage 4215 ) 4216 4217 # --- 5 Camera Calibration and 3D Reconstruction ----------------------------- 4218 4219 # --- 5.1 Camera Calibration ------------------------------------------------- 4220 4221 # Projects 3D points to image plane 4222 cvProjectPoints2 = cfunc('cvProjectPoints2', _cvDLL, None, 4223 ('object_points', POINTER(CvMat), 1), # const CvMat* object_points 4224 ('rotation_vector', POINTER(CvMat), 1), # const CvMat* rotation_vector 4225 ('translation_vector', POINTER(CvMat), 1), # const CvMat* translation_vector 4226 ('intrinsic_matrix', POINTER(CvMat), 1), # const CvMat* intrinsic_matrix 4227 ('distortion_coeffs', POINTER(CvMat), 1), # const CvMat* distortion_coeffs 4228 ('image_points', POINTER(CvMat), 1), # CvMat* image_points 4229 ('dpdrot', POINTER(CvMat), 1, None), # CvMat* dpdrot 4230 ('dpdt', POINTER(CvMat), 1, None), # CvMat* dpdt 4231 ('dpdf', POINTER(CvMat), 1, None), # CvMat* dpdf 4232 ('dpdc', POINTER(CvMat), 1, None), # CvMat* dpdc 4233 ('dpddist', POINTER(CvMat), 1, None), # CvMat* dpddist 4234 ) 4235 4236 # Finds perspective transformation between two planes 4237 cvFindHomography = cfunc('cvFindHomography', _cvDLL, None, 4238 ('src_points', POINTER(CvMat), 1), # const CvMat* src_points 4239 ('dst_points', POINTER(CvMat), 1), # const CvMat* dst_points 4240 ('homography', POINTER(CvMat), 1), # CvMat* homography 4241 ) 4242 4243 # Finds intrinsic and extrinsic camera parameters using calibration pattern 4244 cvCalibrateCamera2 = cfunc('cvCalibrateCamera2', _cvDLL, None, 4245 ('object_points', POINTER(CvMat), 1), # const CvMat* object_points 4246 ('image_points', POINTER(CvMat), 1), # const CvMat* image_points 4247 ('point_counts', POINTER(CvMat), 1), # const CvMat* point_counts 4248 ('image_size', CvSize, 1), # CvSize image_size 4249 ('intrinsic_matrix', POINTER(CvMat), 1), # CvMat* intrinsic_matrix 4250 ('distortion_coeffs', POINTER(CvMat), 1), # CvMat* distortion_coeffs 4251 ('rotation_vectors', POINTER(CvMat), 1, None), # CvMat* rotation_vectors 4252 ('translation_vectors', POINTER(CvMat), 1, None), # CvMat* translation_vectors 4253 ('flags', c_int, 1, 0), # int flags 4254 ) 4255 4256 # Finds extrinsic camera parameters for particular view 4257 cvFindExtrinsicCameraParams2 = cfunc('cvFindExtrinsicCameraParams2', _cvDLL, None, 4258 ('object_points', POINTER(CvMat), 1), # const CvMat* object_points 4259 ('image_points', POINTER(CvMat), 1), # const CvMat* image_points 4260 ('intrinsic_matrix', POINTER(CvMat), 1), # const CvMat* intrinsic_matrix 4261 ('distortion_coeffs', POINTER(CvMat), 1), # const CvMat* distortion_coeffs 4262 ('rotation_vector', POINTER(CvMat), 1), # CvMat* rotation_vector 4263 ('translation_vector', POINTER(CvMat), 1), # CvMat* translation_vector 4264 ) 4265 4266 # Converts rotation matrix to rotation vector or vice versa 4267 cvRodrigues2 = cfunc('cvRodrigues2', _cvDLL, c_int, 4268 ('src', POINTER(CvMat), 1), # const CvMat* src 4269 ('dst', POINTER(CvMat), 1), # CvMat* dst 4270 ('jacobian', POINTER(CvMat), 1, 0), # CvMat* jacobian 4271 ) 4272 4273 # Transforms image to compensate lens distortion 4274 cvUndistort2 = cfunc('cvUndistort2', _cvDLL, None, 4275 ('src', c_void_p, 1), # const CvArr* src 4276 ('dst', c_void_p, 1), # CvArr* dst 4277 ('intrinsic_matrix', POINTER(CvMat), 1), # const CvMat* intrinsic_matrix 4278 ('distortion_coeffs', POINTER(CvMat), 1), # const CvMat* distortion_coeffs 4279 ) 4280 4281 # Computes undistorion map 4282 cvInitUndistortMap = cfunc('cvInitUndistortMap', _cvDLL, None, 4283 ('intrinsic_matrix', POINTER(CvMat), 1), # const CvMat* intrinsic_matrix 4284 ('distortion_coeffs', POINTER(CvMat), 1), # const CvMat* distortion_coeffs 4285 ('mapx', c_void_p, 1), # CvArr* mapx 4286 ('mapy', c_void_p, 1), # CvArr* mapy 4287 ) 4288 4289 # Finds positions of internal corners of the chessboard 4290 cvFindChessboardCorners = cfunc('cvFindChessboardCorners', _cvDLL, c_int, 4291 ('image', c_void_p, 1), # const void* image 4292 ('pattern_size', CvSize, 1), # CvSize pattern_size 4293 ('corners', POINTER(CvPoint2D32f), 1), # CvPoint2D32f* corners 4294 ('corner_count', POINTER(c_int), 1, None), # int* corner_count 4295 ('flags', c_int, 1), # int flags 4296 ) 4297 4298 # Renders the detected chessboard corners 4299 cvDrawChessboardCorners = cfunc('cvDrawChessboardCorners', _cvDLL, None, 4300 ('image', c_void_p, 1), # CvArr* image 4301 ('pattern_size', CvSize, 1), # CvSize pattern_size 4302 ('corners', POINTER(CvPoint2D32f), 1), # CvPoint2D32f* corners 4303 ('count', c_int, 1), # int count 4304 ('pattern_was_found', c_int, 1), # int pattern_was_found 4305 ) 4306 4307 # --- 5.2 Pose Estimation ---------------------------------------------------- 4308 4309 # Initializes structure containing object information 4310 cvCreatePOSITObject = cfunc('cvCreatePOSITObject', _cvDLL, POINTER(CvPOSITObject), 4311 ('points', POINTER(CvPoint3D32f), 1), # CvPoint3D32f* points 4312 ('point_count', c_int, 1), # int point_count 4313 ) 4314 4315 # Implements POSIT algorithm 4316 cvPOSIT = cfunc('cvPOSIT', _cvDLL, None, 4317 ('posit_object', POINTER(CvPOSITObject), 1), # CvPOSITObject* posit_object 4318 ('image_points', POINTER(CvPoint2D32f), 1), # CvPoint2D32f* image_points 4319 ('focal_length', c_double, 1), # double focal_length 4320 ('criteria', CvTermCriteria, 1), # CvTermCriteria criteria 4321 ('rotation_matrix', CvMatr32f, 1), # CvMatr32f rotation_matrix 4322 ('translation_vector', CvVect32f, 1), # CvVect32f translation_vector 4323 ) 4324 4325 # Deallocates 3D object structure 4326 cvReleasePOSITObject = cfunc('cvReleasePOSITObject',