]> rtime.felk.cvut.cz Git - opencv.git/commitdiff
- fix extract_aliases.py: record alias if define-line ends with whitespace
authorbaeuml <baeuml@73c94f0f-984f-4a5f-82bc-2d8db8d8ee08>
Tue, 2 Jun 2009 15:14:46 +0000 (15:14 +0000)
committerbaeuml <baeuml@73c94f0f-984f-4a5f-82bc-2d8db8d8ee08>
Tue, 2 Jun 2009 15:14:46 +0000 (15:14 +0000)
- update python demo applications: (thanks to Tim Faudot for the patch)
  - make demos run with most current version of the wrappers
  - clean up: remove many unnecessary semicolons

git-svn-id: https://code.ros.org/svn/opencv/trunk@1806 73c94f0f-984f-4a5f-82bc-2d8db8d8ee08

opencv/interfaces/swig/python/pytypemaps.i
opencv/samples/python/dft.py
opencv/samples/python/facedetect.py
opencv/samples/python/inpaint.py
opencv/samples/python/kalman.py
opencv/samples/python/kmeans.py
opencv/samples/python/laplace.py
opencv/samples/python/lkdemo.py
opencv/samples/python/minidemo.py
opencv/samples/python/motempl.py
opencv/utils/extract_aliases.py

index 9cd4c22c6ad96fcbbc1d7a4061f5b3f1faa0d531..23d96a80f30b5d1e7418bbe3d526fc864a449397 100644 (file)
     
     // use the macro we have to expand a single entry
     TUPLE_OR_TYPE (item, *element, typename, number, description, __VA_ARGS__)
-//*corner, "ff", & corner->x, & corner->y
+    // *corner, "ff", & corner->x, & corner->y
   }
   
   // these are the arguments passed to the OpenCV function
index 5bb3e26701d2c52d4fb32e126c8bbd2e842bbc6c..13be2f7f7c336dd93b6cc780b0fee9d9d788e87a 100755 (executable)
@@ -8,100 +8,100 @@ import sys
 # src & dst arrays of equal size & type
 def cvShiftDFT(src_arr, dst_arr ):
 
-    size = cvGetSize(src_arr);
-    dst_size = cvGetSize(dst_arr);
+    size = cvGetSize(src_arr)
+    dst_size = cvGetSize(dst_arr)
 
     if(dst_size.width != size.width or 
             dst_size.height != size.height) :
-        cvError( CV_StsUnmatchedSizes, "cvShiftDFT", "Source and Destination arrays must have equal sizes", __FILE__, __LINE__ );    
+        cvError( CV_StsUnmatchedSizes, "cvShiftDFT", "Source and Destination arrays must have equal sizes", __FILE__, __LINE__ )    
 
     if(src_arr is dst_arr):
-        tmp = cvCreateMat(size.height/2, size.width/2, cvGetElemType(src_arr));
+        tmp = cvCreateMat(size.height/2, size.width/2, cvGetElemType(src_arr))
     
-    cx = size.width/2;
-    cy = size.height/2; # image center
-
-    q1 = cvGetSubRect( src_arr, cvRect(0,0,cx, cy) );
-    q2 = cvGetSubRect( src_arr, cvRect(cx,0,cx,cy) );
-    q3 = cvGetSubRect( src_arr, cvRect(cx,cy,cx,cy) );
-    q4 = cvGetSubRect( src_arr, cvRect(0,cy,cx,cy) );
-    d1 = cvGetSubRect( src_arr, cvRect(0,0,cx,cy) );
-    d2 = cvGetSubRect( src_arr, cvRect(cx,0,cx,cy) );
-    d3 = cvGetSubRect( src_arr, cvRect(cx,cy,cx,cy) );
-    d4 = cvGetSubRect( src_arr, cvRect(0,cy,cx,cy) );
+    cx = size.width/2
+    cy = size.height/2 # image center
+
+    q1 = cvGetSubRect( src_arr, cvRect(0,0,cx, cy) )
+    q2 = cvGetSubRect( src_arr, cvRect(cx,0,cx,cy) )
+    q3 = cvGetSubRect( src_arr, cvRect(cx,cy,cx,cy) )
+    q4 = cvGetSubRect( src_arr, cvRect(0,cy,cx,cy) )
+    d1 = cvGetSubRect( src_arr, cvRect(0,0,cx,cy) )
+    d2 = cvGetSubRect( src_arr, cvRect(cx,0,cx,cy) )
+    d3 = cvGetSubRect( src_arr, cvRect(cx,cy,cx,cy) )
+    d4 = cvGetSubRect( src_arr, cvRect(0,cy,cx,cy) )
 
     if(src_arr is not dst_arr):
         if( not CV_ARE_TYPES_EQ( q1, d1 )):
-            cvError( CV_StsUnmatchedFormats, "cvShiftDFT", "Source and Destination arrays must have the same format", __FILE__, __LINE__ );    
+            cvError( CV_StsUnmatchedFormats, "cvShiftDFT", "Source and Destination arrays must have the same format", __FILE__, __LINE__ )    
         
-        cvCopy(q3, d1);
-        cvCopy(q4, d2);
-        cvCopy(q1, d3);
-        cvCopy(q2, d4);
+        cvCopy(q3, d1)
+        cvCopy(q4, d2)
+        cvCopy(q1, d3)
+        cvCopy(q2, d4)
     
     else:
-        cvCopy(q3, tmp);
-        cvCopy(q1, q3);
-        cvCopy(tmp, q1);
-        cvCopy(q4, tmp);
-        cvCopy(q2, q4);
-        cvCopy(tmp, q2);
+        cvCopy(q3, tmp)
+        cvCopy(q1, q3)
+        cvCopy(tmp, q1)
+        cvCopy(q4, tmp)
+        cvCopy(q2, q4)
+        cvCopy(tmp, q2)
 
 if __name__ == "__main__":
     
-    im = cvLoadImage( sys.argv[1], CV_LOAD_IMAGE_GRAYSCALE);
+    im = cvLoadImage( sys.argv[1], CV_LOAD_IMAGE_GRAYSCALE)
 
-    realInput = cvCreateImage( cvGetSize(im), IPL_DEPTH_64F, 1);
-    imaginaryInput = cvCreateImage( cvGetSize(im), IPL_DEPTH_64F, 1);
-    complexInput = cvCreateImage( cvGetSize(im), IPL_DEPTH_64F, 2);
+    realInput = cvCreateImage( cvGetSize(im), IPL_DEPTH_64F, 1)
+    imaginaryInput = cvCreateImage( cvGetSize(im), IPL_DEPTH_64F, 1)
+    complexInput = cvCreateImage( cvGetSize(im), IPL_DEPTH_64F, 2)
 
-    cvScale(im, realInput, 1.0, 0.0);
-    cvZero(imaginaryInput);
-    cvMerge(realInput, imaginaryInput, None, None, complexInput);
+    cvScale(im, realInput, 1.0, 0.0)
+    cvZero(imaginaryInput)
+    cvMerge(realInput, imaginaryInput, None, None, complexInput)
 
-    dft_M = cvGetOptimalDFTSize( im.height - 1 );
-    dft_N = cvGetOptimalDFTSize( im.width - 1 );
+    dft_M = cvGetOptimalDFTSize( im.height - 1 )
+    dft_N = cvGetOptimalDFTSize( im.width - 1 )
 
-    dft_A = cvCreateMat( dft_M, dft_N, CV_64FC2 );
-    image_Re = cvCreateImage( cvSize(dft_N, dft_M), IPL_DEPTH_64F, 1);
-    image_Im = cvCreateImage( cvSize(dft_N, dft_M), IPL_DEPTH_64F, 1);
+    dft_A = cvCreateMat( dft_M, dft_N, CV_64FC2 )
+    image_Re = cvCreateImage( cvSize(dft_N, dft_M), IPL_DEPTH_64F, 1)
+    image_Im = cvCreateImage( cvSize(dft_N, dft_M), IPL_DEPTH_64F, 1)
 
     # copy A to dft_A and pad dft_A with zeros
-    tmp = cvGetSubRect( dft_A, cvRect(0,0, im.width, im.height));
-    cvCopy( complexInput, tmp, None );
+    tmp = cvGetSubRect( dft_A, cvRect(0,0, im.width, im.height))
+    cvCopy( complexInput, tmp, None )
     if(dft_A.width > im.width):
-        tmp = cvGetSubRect( dft_A, cvRect(im.width,0, dft_N - im.width, im.height));
-        cvZero( tmp );
+        tmp = cvGetSubRect( dft_A, cvRect(im.width,0, dft_N - im.width, im.height))
+        cvZero( tmp )
 
     # no need to pad bottom part of dft_A with zeros because of
     # use nonzero_rows parameter in cvDFT() call below
 
-    cvDFT( dft_A, dft_A, CV_DXT_FORWARD, complexInput.height );
+    cvDFT( dft_A, dft_A, CV_DXT_FORWARD, complexInput.height )
 
-    cvNamedWindow("win", 0);
-    cvNamedWindow("magnitude", 0);
-    cvShowImage("win", im);
+    cvNamedWindow("win", 0)
+    cvNamedWindow("magnitude", 0)
+    cvShowImage("win", im)
 
     # Split Fourier in real and imaginary parts
-    cvSplit( dft_A, image_Re, image_Im, None, None );
+    cvSplit( dft_A, image_Re, image_Im, None, None )
 
     # Compute the magnitude of the spectrum Mag = sqrt(Re^2 + Im^2)
-    cvPow( image_Re, image_Re, 2.0);
-    cvPow( image_Im, image_Im, 2.0);
-    cvAdd( image_Re, image_Im, image_Re, None);
-    cvPow( image_Re, image_Re, 0.5 );
+    cvPow( image_Re, image_Re, 2.0)
+    cvPow( image_Im, image_Im, 2.0)
+    cvAdd( image_Re, image_Im, image_Re, None)
+    cvPow( image_Re, image_Re, 0.5 )
 
     # Compute log(1 + Mag)
-    cvAddS( image_Re, cvScalarAll(1.0), image_Re, None ); # 1 + Mag
-    cvLog( image_Re, image_Re ); # log(1 + Mag)
+    cvAddS( image_Re, cvScalarAll(1.0), image_Re, None ) # 1 + Mag
+    cvLog( image_Re, image_Re ) # log(1 + Mag)
 
 
     # Rearrange the quadrants of Fourier image so that the origin is at
     # the image center
-    cvShiftDFT( image_Re, image_Re );
+    cvShiftDFT( image_Re, image_Re )
 
-    min, max = cvMinMaxLoc(image_Re);
-    cvScale(image_Re, image_Re, 1.0/(max-min), 1.0*(-min)/(max-min));
-    cvShowImage("magnitude", image_Re);
+    min, max, pt1, pt2 = cvMinMaxLoc(image_Re)
+    cvScale(image_Re, image_Re, 1.0/(max-min), 1.0*(-min)/(max-min))
+    cvShowImage("magnitude", image_Re)
 
-    cvWaitKey(-1);
+    cvWaitKey(0)
index c8b1d484e0071fd132fbcb61a2b3cb0d87e2d1ba..73eef6e18b78b638730b98e4b6cc974b0bf546ed 100755 (executable)
@@ -33,26 +33,26 @@ haar_flags = 0
 
 def detect_and_draw( img ):
     # allocate temporary images
-    gray = cvCreateImage( cvSize(img.width,img.height), 8, 1 );
-    small_img = cvCreateImage( cvSize( cvRound (img.width/image_scale),
-                                                              cvRound (img.height/image_scale)), 8, 1 );
+    gray = cvCreateImage( cvSize(img.width,img.height), 8, 1 )
+    small_img = cvCreateImage((cvRound(img.width/image_scale),
+                              cvRound (img.height/image_scale)), 8, 1 )
 
     # convert color input image to grayscale
-    cvCvtColor( img, gray, CV_BGR2GRAY );
+    cvCvtColor( img, gray, CV_BGR2GRAY )
 
     # scale input image for faster processing
-    cvResize( gray, small_img, CV_INTER_LINEAR );
+    cvResize( gray, small_img, CV_INTER_LINEAR )
 
-    cvEqualizeHist( small_img, small_img );
+    cvEqualizeHist( small_img, small_img )
     
-    cvClearMemStorage( storage );
+    cvClearMemStorage( storage )
 
     if( cascade ):
-        t = cvGetTickCount();
+        t = cvGetTickCount()
         faces = cvHaarDetectObjects( small_img, cascade, storage,
-                                     haar_scale, min_neighbors, haar_flags, min_size );
-        t = cvGetTickCount() - t;
-        print "detection time = %gms" % (t/(cvGetTickFrequency()*1000.));
+                                     haar_scale, min_neighbors, haar_flags, min_size )
+        t = cvGetTickCount() - t
+        print "detection time = %gms" % (t/(cvGetTickFrequency()*1000.))
         if faces:
             for face_rect in faces:
                 # the input to cvHaarDetectObjects was resized, so scale the 
@@ -60,9 +60,9 @@ def detect_and_draw( img ):
                 pt1 = cvPoint( int(face_rect.x*image_scale), int(face_rect.y*image_scale))
                 pt2 = cvPoint( int((face_rect.x+face_rect.width)*image_scale),
                                int((face_rect.y+face_rect.height)*image_scale) )
-                cvRectangle( img, pt1, pt2, CV_RGB(255,0,0), 3, 8, 0 );
+                cvRectangle( img, pt1, pt2, CV_RGB(255,0,0), 3, 8, 0 )
 
-    cvShowImage( "result", img );
+    cvShowImage( "result", img )
 
 
 if __name__ == '__main__':
@@ -75,7 +75,7 @@ if __name__ == '__main__':
                 input_name = sys.argv[2]
 
         elif sys.argv[1] == "--help" or sys.argv[1] == "-h":
-            print "Usage: facedetect --cascade=\"<cascade_path>\" [filename|camera_index]\n" ;
+            print "Usage: facedetect --cascade=\"<cascade_path>\" [filename|camera_index]\n" 
             sys.exit(-1)
 
         else:
@@ -84,7 +84,7 @@ if __name__ == '__main__':
     # the OpenCV API says this function is obsolete, but we can't
     # cast the output of cvLoad to a HaarClassifierCascade, so use this anyways
     # the size parameter is ignored
-    cascade = cvLoadHaarClassifierCascade( cascade_name, cvSize(1,1) );
+    cascade = cvLoadHaarClassifierCascade( cascade_name, cvSize(1,1) )
     
     if not cascade:
         print "ERROR: Could not load classifier cascade"
@@ -94,35 +94,35 @@ if __name__ == '__main__':
     if input_name.isdigit():
         capture = cvCreateCameraCapture( int(input_name) )
     else:
-        capture = cvCreateFileCapture( input_name ); 
+        capture = cvCreateFileCapture( input_name ) 
 
-    cvNamedWindow( "result", 1 );
+    cvNamedWindow( "result", 1 )
 
-    if( capture ):
+    if capture:
         frame_copy = None
-        while True: 
-            frame = cvQueryFrame( capture );
-            if( not frame ):
-                break;
-            if( not frame_copy ):
+        while True:
+            frame = cvQueryFrame( capture )
+            if not frame:
+                cvWaitKey(0)
+                break
+            if not frame_copy:
                 frame_copy = cvCreateImage( cvSize(frame.width,frame.height),
-                                            IPL_DEPTH_8U, frame.nChannels );
-            if( frame.origin == IPL_ORIGIN_TL ):
-                cvCopy( frame, frame_copy );
+                                            IPL_DEPTH_8U, frame.nChannels )
+            if frame.origin == IPL_ORIGIN_TL:
+                cvCopy( frame, frame_copy )
             else:
-                cvFlip( frame, frame_copy, 0 );
+                cvFlip( frame, frame_copy, 0 )
             
-            detect_and_draw( frame_copy );
+            detect_and_draw( frame_copy )
 
             if( cvWaitKey( 10 ) >= 0 ):
-                break;
+                break
 
     else:
-        image = cvLoadImage( input_name, 1 );
+        image = cvLoadImage( input_name, 1 )
 
-        if( image ):
-            
-            detect_and_draw( image );
-            cvWaitKey(0);
-    
-    cvDestroyWindow("result");
+        if image:
+            detect_and_draw( image )
+            cvWaitKey(0)
+
+    cvDestroyWindow("result")
index dccd03c2b8eb6120ce0c1248e0969fc84a026e17..51d004cef554e68efe04b92d3b81a1db864eb124 100755 (executable)
@@ -3,39 +3,39 @@ from opencv.cv import *
 from opencv.highgui import *
 import sys
 
-inpaint_mask = None;
-img0 = None;
-img = None;
-inpainted = None;
-prev_pt = cvPoint(-1,-1);
+inpaint_mask = None
+img0 = None
+img = None
+inpainted = None
+prev_pt = cvPoint(-1,-1)
 
 def on_mouse( event, x, y, flags, param ):
     global prev_pt
-    if not img :
-        return;
+    if not img:
+        return
 
     if event == CV_EVENT_LBUTTONUP or not (flags & CV_EVENT_FLAG_LBUTTON):
-        prev_pt = cvPoint(-1,-1);
+        prev_pt = cvPoint(-1,-1)
     elif event == CV_EVENT_LBUTTONDOWN:
-        prev_pt = cvPoint(x,y);
+        prev_pt = cvPoint(x,y)
     elif event == CV_EVENT_MOUSEMOVE and (flags & CV_EVENT_FLAG_LBUTTON) :
-        pt = cvPoint(x,y);
+        pt = cvPoint(x,y)
         if prev_pt.x < 0:
-            prev_pt = pt;
-        cvLine( inpaint_mask, prev_pt, pt, cvScalarAll(255), 5, 8, 0 );
-        cvLine( img, prev_pt, pt, cvScalarAll(255), 5, 8, 0 );
-        prev_pt = pt;
-        cvShowImage( "image", img );
+            prev_pt = pt
+        cvLine( inpaint_mask, prev_pt, pt, cvScalarAll(255), 5, 8, 0 )
+        cvLine( img, prev_pt, pt, cvScalarAll(255), 5, 8, 0 )
+        prev_pt = pt
+        cvShowImage( "image", img )
 
 if __name__=="__main__":
-    filename = "../c/fruits.jpg";
-    if len(sys.argv)>=2:
+    filename = "../c/fruits.jpg"
+    if len(sys.argv) >= 2:
        filename = sys.argv[1]
 
     img0 = cvLoadImage(filename,-1)
     if not img0:
        print "Can't open image '%s'" % filename
-        sys.exit(1);
+        sys.exit(1)
 
     print "Hot keys:"
     print "\tESC - quit the program"
@@ -43,30 +43,31 @@ if __name__=="__main__":
     print "\ti or ENTER - run inpainting algorithm"
     print "\t\t(before running it, paint something on the image)"
     
-    cvNamedWindow( "image", 1 );
+    cvNamedWindow( "image", 1 )
 
-    img = cvCloneImage( img0 );
-    inpainted = cvCloneImage( img0 );
-    inpaint_mask = cvCreateImage( cvGetSize(img), 8, 1 );
+    img = cvCloneImage( img0 )
+    inpainted = cvCloneImage( img0 )
+    inpaint_mask = cvCreateImage( cvGetSize(img), 8, 1 )
 
-    cvZero( inpaint_mask );
-    cvZero( inpainted );
-    cvShowImage( "image", img );
-    cvShowImage( "watershed transform", inpainted );
-    cvSetMouseCallback( "image", on_mouse, None );
+    cvZero( inpaint_mask )
+    cvZero( inpainted )
+    cvShowImage( "image", img )
+    cvShowImage( "watershed transform", inpainted )
+    cvSetMouseCallback( "image", on_mouse, None )
 
     while True:
-        c = cvWaitKey(0);
+        c = cvWaitKey(0)
 
-        if( c == '\x1b' or c=='q'):
-            break;
+        if c == '\x1b' or c == 'q':
+            break
 
-        if( c == 'r' ):
-            cvZero( inpaint_mask );
-            cvCopy( img0, img );
-            cvShowImage( "image", img );
+        if c == 'r':
+            cvZero( inpaint_mask )
+            cvCopy( img0, img )
+            cvShowImage( "image", img )
+
+        if c == 'i' or c == '\012':
+            cvNamedWindow( "inpainted image", 1 )
+            cvInpaint( img, inpaint_mask, inpainted, 3, CV_INPAINT_TELEA )
+            cvShowImage( "inpainted image", inpainted )
 
-        if( c == 'i' or c == '\012' ):
-            cvNamedWindow( "inpainted image", 1 );
-            cvInpaint( img, inpaint_mask, inpainted, 3, CV_INPAINT_TELEA );
-            cvShowImage( "inpainted image", inpainted );
index fb68cfa4250f781bbada25bafd26fe400749741f..99d9bf39c3925760e13801820d97cd12250eea73 100755 (executable)
@@ -16,28 +16,28 @@ from opencv.highgui import *
 from math import cos, sin, sqrt
 
 if __name__ == "__main__":
-    A = [ [1, 1], [0, 1] ];
+    A = [ [1, 1], [0, 1] ]
     
-    img = cvCreateImage( cvSize(500,500), 8, 3 );
-    kalman = cvCreateKalman( 2, 1, 0 );
-    state = cvCreateMat( 2, 1, CV_32FC1 );  # (phi, delta_phi)
-    process_noise = cvCreateMat( 2, 1, CV_32FC1 );
-    measurement = cvCreateMat( 1, 1, CV_32FC1 );
-    rng = cvRNG(-1);
-    code = -1;
+    img = cvCreateImage( cvSize(500,500), 8, 3 )
+    kalman = cvCreateKalman( 2, 1, 0 )
+    state = cvCreateMat( 2, 1, CV_32FC1 )  # (phi, delta_phi)
+    process_noise = cvCreateMat( 2, 1, CV_32FC1 )
+    measurement = cvCreateMat( 1, 1, CV_32FC1 )
+    rng = cvRNG(-1)
+    code = -1L
 
-    cvZero( measurement );
-    cvNamedWindow( "Kalman", 1 );
+    cvZero( measurement )
+    cvNamedWindow( "Kalman", 1 )
 
     while True:
-        cvRandArr( rng, state, CV_RAND_NORMAL, cvRealScalar(0), cvRealScalar(0.1) );
+        cvRandArr( rng, state, CV_RAND_NORMAL, cvRealScalar(0), cvRealScalar(0.1) )
         
-        kalman.transition_matrix[:] = A;
-        cvSetIdentity( kalman.measurement_matrix, cvRealScalar(1) );
-        cvSetIdentity( kalman.process_noise_cov, cvRealScalar(1e-5) );
-        cvSetIdentity( kalman.measurement_noise_cov, cvRealScalar(1e-1) );
-        cvSetIdentity( kalman.error_cov_post, cvRealScalar(1));
-        cvRandArr( rng, kalman.state_post, CV_RAND_NORMAL, cvRealScalar(0), cvRealScalar(0.1) );
+        kalman.transition_matrix[:] = A
+        cvSetIdentity( kalman.measurement_matrix, cvRealScalar(1) )
+        cvSetIdentity( kalman.process_noise_cov, cvRealScalar(1e-5) )
+        cvSetIdentity( kalman.measurement_noise_cov, cvRealScalar(1e-1) )
+        cvSetIdentity( kalman.error_cov_post, cvRealScalar(1))
+        cvRandArr( rng, kalman.state_post, CV_RAND_NORMAL, cvRealScalar(0), cvRealScalar(0.1) )
         
         while True:
             def calc_point(angle):
@@ -45,48 +45,48 @@ if __name__ == "__main__":
                          cvRound(img.height/2 - img.width/3*sin(angle))) 
 
             state_angle = state[0] 
-            state_pt = calc_point(state_angle);
+            state_pt = calc_point(state_angle)
             
-            prediction = cvKalmanPredict( kalman );
+            prediction = cvKalmanPredict( kalman )
             predict_angle = prediction[0,0] 
-            predict_pt = calc_point(predict_angle);
+            predict_pt = calc_point(predict_angle)
 
             cvRandArr( rng, measurement, CV_RAND_NORMAL, cvRealScalar(0),
-                       cvRealScalar(sqrt(kalman.measurement_noise_cov[0,0])) );
+                       cvRealScalar(sqrt(kalman.measurement_noise_cov[0,0])) )
 
             # generate measurement 
-            cvMatMulAdd( kalman.measurement_matrix, state, measurement, measurement );
+            cvMatMulAdd( kalman.measurement_matrix, state, measurement, measurement )
 
-            measurement_angle = measurement[0,0];
-            measurement_pt = calc_point(measurement_angle);
+            measurement_angle = measurement[0,0]
+            measurement_pt = calc_point(measurement_angle)
             
             # plot points 
             def draw_cross( center, color, d ):                                 
                 cvLine( img, cvPoint( center.x - d, center.y - d ),                
-                             cvPoint( center.x + d, center.y + d ), color, 1, CV_AA, 0); 
+                             cvPoint( center.x + d, center.y + d ), color, 1, CV_AA, 0) 
                 cvLine( img, cvPoint( center.x + d, center.y - d ),                
                              cvPoint( center.x - d, center.y + d ), color, 1, CV_AA, 0 )
 
-            cvZero( img );
-            draw_cross( state_pt, CV_RGB(255,255,255), 3 );
-            draw_cross( measurement_pt, CV_RGB(255,0,0), 3 );
-            draw_cross( predict_pt, CV_RGB(0,255,0), 3 );
-            cvLine( img, state_pt, measurement_pt, CV_RGB(255,0,0), 3, CV_AA, 0 );
-            cvLine( img, state_pt, predict_pt, CV_RGB(255,255,0), 3, CV_AA, 0 );
+            cvZero( img )
+            draw_cross( state_pt, CV_RGB(255,255,255), 3 )
+            draw_cross( measurement_pt, CV_RGB(255,0,0), 3 )
+            draw_cross( predict_pt, CV_RGB(0,255,0), 3 )
+            cvLine( img, state_pt, measurement_pt, CV_RGB(255,0,0), 3, CV_AA, 0 )
+            cvLine( img, state_pt, predict_pt, CV_RGB(255,255,0), 3, CV_AA, 0 )
             
-            cvKalmanCorrect( kalman, measurement );
+            cvKalmanCorrect( kalman, measurement )
 
             cvRandArr( rng, process_noise, CV_RAND_NORMAL, cvRealScalar(0),
-                       cvRealScalar(sqrt(kalman.process_noise_cov[0,0])));
-            cvMatMulAdd( kalman.transition_matrix, state, process_noise, state );
+                       cvRealScalar(sqrt(kalman.process_noise_cov[0,0])))
+            cvMatMulAdd( kalman.transition_matrix, state, process_noise, state )
 
-            cvShowImage( "Kalman", img );
-            code = cvWaitKey( 100 );
+            cvShowImage( "Kalman", img )
             
-            if( code > 0 ):
-                break;
+            code = str(cvWaitKey( 100 ))
+            if( code != '-1'):
+                break
             
         if( code == '\x1b' or code == 'q' or code == 'Q' ):
-            break;
+            break
     
-    cvDestroyWindow("Kalman");
+    cvDestroyWindow("Kalman")
index 30bd0321424d4ab45787f67dc5e17f42f55c72ad..75261c656e08cd583b71a383a00b522c5c21b236 100755 (executable)
@@ -2,7 +2,7 @@
 from opencv.cv import *
 from opencv.highgui import *
 from random import randint
-MAX_CLUSTERS=5
+MAX_CLUSTERS = 5
 
 if __name__ == "__main__":
 
@@ -11,23 +11,23 @@ if __name__ == "__main__":
         CV_RGB(0,255,0),
         CV_RGB(100,100,255),
         CV_RGB(255,0,255),
-        CV_RGB(255,255,0)];
-    img = cvCreateImage( cvSize( 500, 500 ), 8, 3 );
-    rng = cvRNG(-1);
+        CV_RGB(255,255,0)]
+    img = cvCreateImage( cvSize( 500, 500 ), 8, 3 )
+    rng = cvRNG(-1)
 
-    cvNamedWindow( "clusters", 1 );
+    cvNamedWindow( "clusters", 1 )
         
     while True:
         cluster_count = randint(2, MAX_CLUSTERS)
         sample_count = randint(1, 1000)
-        points = cvCreateMat( sample_count, 1, CV_32FC2 );
-        clusters = cvCreateMat( sample_count, 1, CV_32SC1 );
+        points = cvCreateMat( sample_count, 1, CV_32FC2 )
+        clusters = cvCreateMat( sample_count, 1, CV_32SC1 )
         
         # generate random sample from multigaussian distribution
         for k in range(cluster_count):
-            center = CvPoint();
-            center.x = cvRandInt(rng)%img.width;
-            center.y = cvRandInt(rng)%img.height;
+            center = CvPoint()
+            center.x = cvRandInt(rng)%img.width
+            center.y = cvRandInt(rng)%img.height
             first = k*sample_count/cluster_count
             last = sample_count
             if k != cluster_count:
@@ -37,28 +37,30 @@ if __name__ == "__main__":
                         
             cvRandArr( rng, point_chunk, CV_RAND_NORMAL,
                        cvScalar(center.x,center.y,0,0),
-                       cvScalar(img.width*0.1,img.height*0.1,0,0));
+                       cvScalar(img.width*0.1,img.height*0.1,0,0))
         
 
         # shuffle samples 
         cvRandShuffle( points, rng )
 
         cvKMeans2( points, cluster_count, clusters,
-                   cvTermCriteria( CV_TERMCRIT_EPS+CV_TERMCRIT_ITER, 10, 1.0 ));
+                   cvTermCriteria( CV_TERMCRIT_EPS+CV_TERMCRIT_ITER, 10, 1.0 ))
 
-        cvZero( img );
+        cvZero( img )
 
         for i in range(sample_count):
             cluster_idx = clusters[i]
-            pt = points[i]
-            cvCircle( img, pt, 2, color_tab[cluster_idx], CV_FILLED, CV_AA, 0 );
-        
+            # a multi channel matrix access returns a scalar of
+            #dimension 4,0, which is not considerate a cvPoint
+            #we have to create a tuple with the first two elements
+            pt = (cvRound(points[i][0]), cvRound(points[i][1]))
+            cvCircle( img, pt, 2, color_tab[cluster_idx], CV_FILLED, CV_AA, 0 )
 
-        cvShowImage( "clusters", img );
+        cvShowImage( "clusters", img )
 
         key = cvWaitKey(0)
         if( key == 27 or key == 'q' or key == 'Q' ): # 'ESC'
-            break;
+            break
     
     
-    cvDestroyWindow( "clusters" );
+    cvDestroyWindow( "clusters" )
index af6f651422abea1b5d0bf44abec8d6febe195aeb..70c10dbf288d9d4580aa1f52be3b4c1147d51c59 100755 (executable)
@@ -6,7 +6,7 @@ import sys
 if __name__ == "__main__":
     laplace = None
     colorlaplace = None
-    planes = [ None, None, None ];
+    planes = [ None, None, None ]
     capture = None
     
     if len(sys.argv)==1:
@@ -14,36 +14,36 @@ if __name__ == "__main__":
     elif len(sys.argv)==2 and sys.argv[1].isdigit():
         capture = cvCreateCameraCapture( int(sys.argv[1]) )
     elif len(sys.argv)==2:
-        capture = cvCreateFileCapture( sys.argv[1] ); 
+        capture = cvCreateFileCapture( sys.argv[1] ) 
 
     if not capture:
         print "Could not initialize capturing..."
         sys.exit(-1)
         
-    cvNamedWindow( "Laplacian", 1 );
+    cvNamedWindow( "Laplacian", 1 )
 
     while True:
-        frame = cvQueryFrame( capture );
+        frame = cvQueryFrame( capture )
         if not frame:
+            cvWaitKey(0)
             break
 
         if not laplace:
             for i in range( len(planes) ):
-                planes[i] = cvCreateImage( cvSize(frame.width,frame.height), 8, 1 );
-            laplace = cvCreateImage( cvSize(frame.width,frame.height), IPL_DEPTH_16S, 1 );
-            colorlaplace = cvCreateImage( cvSize(frame.width,frame.height), 8, 3 );
+                planes[i] = cvCreateImage( cvSize(frame.width,frame.height), 8, 1 )
+            laplace = cvCreateImage( cvSize(frame.width,frame.height), IPL_DEPTH_16S, 1 )
+            colorlaplace = cvCreateImage( cvSize(frame.width,frame.height), 8, 3 )
 
-        cvSplit( frame, planes[0], planes[1], planes[2], None );
+        cvSplit( frame, planes[0], planes[1], planes[2], None )
         for plane in planes:
-            cvLaplace( plane, laplace, 3 );
-            cvConvertScaleAbs( laplace, plane, 1, 0 );
+            cvLaplace( plane, laplace, 3 )
+            cvConvertScaleAbs( laplace, plane, 1, 0 )
 
-        cvMerge( planes[0], planes[1], planes[2], None, colorlaplace );
-        colorlaplace.origin = frame.origin;
+        cvMerge( planes[0], planes[1], planes[2], None, colorlaplace )
 
-        cvShowImage("Laplacian", colorlaplace );
+        cvShowImage("Laplacian", colorlaplace )
 
         if cvWaitKey(10) != -1:
-            break;
+            break
 
-    cvDestroyWindow("Laplacian");
+    cvDestroyWindow("Laplacian")
index 205cfc75d7ab20477650229ec67de348fa47b08f..e47defc06ff922726e6ec242cb1b0012e837f7df 100755 (executable)
@@ -23,6 +23,9 @@ add_remove_pt = False
 flags = 0
 night_mode = False
 need_to_init = False
+# the default parameters
+quality = 0.01
+min_distance = 10
 
 #############################################################################
 # the mouse callback
@@ -38,10 +41,6 @@ def on_mouse (event, x, y, flags, param):
         # not initialized, so skip
         return
 
-    if image.origin != 0:
-        # different origin
-        y = image.height - y
-
     if event == highgui.CV_EVENT_LBUTTONDOWN:
         # user has click, so memorize it
         pt = cv.cvPoint (x, y)
@@ -102,11 +101,12 @@ if __name__ == '__main__':
         if image is None:
             # create the images we need
             image = cv.cvCreateImage (cv.cvGetSize (frame), 8, 3)
-            image.origin = frame.origin
             grey = cv.cvCreateImage (cv.cvGetSize (frame), 8, 1)
             prev_grey = cv.cvCreateImage (cv.cvGetSize (frame), 8, 1)
             pyramid = cv.cvCreateImage (cv.cvGetSize (frame), 8, 1)
             prev_pyramid = cv.cvCreateImage (cv.cvGetSize (frame), 8, 1)
+            eig = cv.cvCreateImage (cv.cvGetSize (frame), cv.IPL_DEPTH_32F, 1)
+            temp = cv.cvCreateImage (cv.cvGetSize (frame), cv.IPL_DEPTH_32F, 1)
             points = [[], []]
 
         # copy the frame, so we can draw on it
@@ -121,21 +121,14 @@ if __name__ == '__main__':
 
         if need_to_init:
             # we want to search all the good points
-
             # create the wanted images
-            eig = cv.cvCreateImage (cv.cvGetSize (grey), 32, 1)
-            temp = cv.cvCreateImage (cv.cvGetSize (grey), 32, 1)
-
-            # the default parameters
-            quality = 0.01
-            min_distance = 10
-
+            
             # search the good points
             points [1] = cv.cvGoodFeaturesToTrack (
                 grey, eig, temp,
                 MAX_COUNT,
                 quality, min_distance, None, 3, 0, 0.04)
-
+            
             # refine the corner locations
             cv.cvFindCornerSubPix (
                 grey,
@@ -143,25 +136,21 @@ if __name__ == '__main__':
                 cv.cvSize (win_size, win_size), cv.cvSize (-1, -1),
                 cv.cvTermCriteria (cv.CV_TERMCRIT_ITER | cv.CV_TERMCRIT_EPS,
                                    20, 0.03))
-
-            # release the temporary images
-            cv.cvReleaseImage (eig)
-            cv.cvReleaseImage (temp)
                                                
         elif len (points [0]) > 0:
             # we have points, so display them
 
             # calculate the optical flow
-            points [1], status = cv.cvCalcOpticalFlowPyrLK (
+            [points [1], status], something = cv.cvCalcOpticalFlowPyrLK (
                 prev_grey, grey, prev_pyramid, pyramid,
                 points [0], len (points [0]),
-                cv.cvSize (win_size, win_size), 3,
+                (win_size, win_size), 3,
                 len (points [0]),
                 None,
                 cv.cvTermCriteria (cv.CV_TERMCRIT_ITER|cv.CV_TERMCRIT_EPS,
                                    20, 0.03),
                 flags)
-
+            
             # initializations
             point_counter = -1
             new_points = []
@@ -188,10 +177,10 @@ if __name__ == '__main__':
 
                 # this point is a correct point
                 new_points.append (the_point)
-                
+
                 # draw the current point
                 cv.cvCircle (image,
-                             [the_point.x, the_point.y],
+                             cv.cvPointFrom32f(the_point),
                              3, cv.cvScalar (0, 255, 0, 0),
                              -1, 8, 0)
 
index 15687e204e157ee42512cc7d89c81748d223ca0b..589997d568417bc5f48161657a1a04c292dfecd5 100755 (executable)
@@ -1,17 +1,14 @@
+#! /usr/bin/env python
+
 import opencv
 from opencv import highgui
 
-highgui.cvNamedWindow("win", highgui.CV_WINDOW_AUTOSIZE)
-cap = highgui.cvCaptureFromFile("/home/asbach/Source/ObjectDetection/older/avi/table.avi")
+cap = highgui.cvCreateFileCapture("../c/tree.avi")
 img = highgui.cvQueryFrame(cap)
-
-print img
 print "Got frame of dimensions (", img.width, " x ", img.height, " )"
 
+highgui.cvNamedWindow("win", highgui.CV_WINDOW_AUTOSIZE)
 highgui.cvShowImage("win", img)
 highgui.cvMoveWindow("win", 200, 200)
 highgui.cvWaitKey(0)
 
-pilimg = opencv.Ipl2PIL(img)
-print pilimg
-
index 9ee79eef9be6944c4111528ac481d1d17f5b59f0..d0493abbfd69d4dddc8a7a0a7423c4fd0ae559d7 100755 (executable)
@@ -6,17 +6,17 @@ import time
 from math import cos,sin
 
 CLOCKS_PER_SEC = 1.0
-MHI_DURATION = 1;
-MAX_TIME_DELTA = 0.5;
-MIN_TIME_DELTA = 0.05;
-N = 4;
+MHI_DURATION = 1
+MAX_TIME_DELTA = 0.5
+MIN_TIME_DELTA = 0.05
+N = 4
 buf = range(10) 
-last = 0;
-mhi = None; # MHI
-orient = None; # orientation
-mask = None; # valid orientation mask
-segmask = None; # motion segmentation map
-storage = None; # temporary storage
+last = 0
+mhi = None # MHI
+orient = None # orientation
+mask = None # valid orientation mask
+segmask = None # motion segmentation map
+storage = None # temporary storage
 
 def update_mhi( img, dst, diff_threshold ):
     global last
@@ -25,89 +25,89 @@ def update_mhi( img, dst, diff_threshold ):
     global mask
     global orient
     global segmask
-    timestamp = time.clock()/CLOCKS_PER_SEC; # get current time in seconds
-    size = cvSize(img.width,img.height); # get current frame size
-    idx1 = last;
+    timestamp = time.clock()/CLOCKS_PER_SEC # get current time in seconds
+    size = cvSize(img.width,img.height) # get current frame size
+    idx1 = last
     if not mhi or mhi.width != size.width or mhi.height != size.height: 
         for i in range( N ):
-            buf[i] = cvCreateImage( size, IPL_DEPTH_8U, 1 );
-            cvZero( buf[i] );
-        mhi = cvCreateImage( size, IPL_DEPTH_32F, 1 );
-        cvZero( mhi ); # clear MHI at the beginning
-        orient = cvCreateImage( size, IPL_DEPTH_32F, 1 );
-        segmask = cvCreateImage( size, IPL_DEPTH_32F, 1 );
-        mask = cvCreateImage( size, IPL_DEPTH_8U, 1 );
-
-    cvCvtColor( img, buf[last], CV_BGR2GRAY ); # convert frame to grayscale
-    idx2 = (last + 1) % N; # index of (last - (N-1))th frame
-    last = idx2;
-    silh = buf[idx2];
-    cvAbsDiff( buf[idx1], buf[idx2], silh ); # get difference between frames
-    cvThreshold( silh, silh, diff_threshold, 1, CV_THRESH_BINARY ); # and threshold it
-    cvUpdateMotionHistory( silh, mhi, timestamp, MHI_DURATION ); # update MHI
+            buf[i] = cvCreateImage( size, IPL_DEPTH_8U, 1 )
+            cvZero( buf[i] )
+        mhi = cvCreateImage( size, IPL_DEPTH_32F, 1 )
+        cvZero( mhi ) # clear MHI at the beginning
+        orient = cvCreateImage( size, IPL_DEPTH_32F, 1 )
+        segmask = cvCreateImage( size, IPL_DEPTH_32F, 1 )
+        mask = cvCreateImage( size, IPL_DEPTH_8U, 1 )
+    
+    cvCvtColor( img, buf[last], CV_BGR2GRAY ) # convert frame to grayscale
+    idx2 = (last + 1) % N # index of (last - (N-1))th frame
+    last = idx2
+    silh = buf[idx2]
+    cvAbsDiff( buf[idx1], buf[idx2], silh ) # get difference between frames
+    cvThreshold( silh, silh, diff_threshold, 1, CV_THRESH_BINARY ) # and threshold it
+    cvUpdateMotionHistory( silh, mhi, timestamp, MHI_DURATION ) # update MHI
     cvCvtScale( mhi, mask, 255./MHI_DURATION,
-                (MHI_DURATION - timestamp)*255./MHI_DURATION );
-    cvZero( dst );
-    cvMerge( mask, None, None, None, dst );
-    cvCalcMotionGradient( mhi, mask, orient, MAX_TIME_DELTA, MIN_TIME_DELTA, 3 );
+                (MHI_DURATION - timestamp)*255./MHI_DURATION )
+    cvZero( dst )
+    cvMerge( mask, None, None, None, dst )
+    cvCalcMotionGradient( mhi, mask, orient, MAX_TIME_DELTA, MIN_TIME_DELTA, 3 )
     if( not storage ):
-        storage = cvCreateMemStorage(0);
+        storage = cvCreateMemStorage(0)
     else:
-        cvClearMemStorage(storage);
-    seq = cvSegmentMotion( mhi, segmask, storage, timestamp, MAX_TIME_DELTA );
+        cvClearMemStorage(storage)
+    seq = cvSegmentMotion( mhi, segmask, storage, timestamp, MAX_TIME_DELTA )
     for i in range(-1, seq.total):
         if( i < 0 ):  # case of the whole image
-            comp_rect = cvRect( 0, 0, size.width, size.height );
-            color = CV_RGB(255,255,255);
-            magnitude = 100.;
+            comp_rect = cvRect( 0, 0, size.width, size.height )
+            color = CV_RGB(255,255,255)
+            magnitude = 100.
         else:  # i-th motion component
             comp_rect = seq[i].rect 
             if( comp_rect.width + comp_rect.height < 100 ): # reject very small components
-                continue;
-            color = CV_RGB(255,0,0);
-            magnitude = 30.;
-        silh_roi = cvGetSubRect(silh, comp_rect);
-        mhi_roi = cvGetSubRect( mhi, comp_rect );
-        orient_roi = cvGetSubRect( orient, comp_rect );
-        mask_roi = cvGetSubRect( mask, comp_rect );
-        angle = cvCalcGlobalOrientation( orient_roi, mask_roi, mhi_roi, timestamp, MHI_DURATION);
-        angle = 360.0 - angle;  # adjust for images with top-left origin
-        count = cvNorm( silh_roi, None, CV_L1, None ); # calculate number of points within silhouette ROI
+                continue
+            color = CV_RGB(255,0,0)
+            magnitude = 30.
+        silh_roi = cvGetSubRect(silh, comp_rect)
+        mhi_roi = cvGetSubRect( mhi, comp_rect )
+        orient_roi = cvGetSubRect( orient, comp_rect )
+        mask_roi = cvGetSubRect( mask, comp_rect )
+        angle = cvCalcGlobalOrientation( orient_roi, mask_roi, mhi_roi, timestamp, MHI_DURATION)
+        angle = 360.0 - angle  # adjust for images with top-left origin
+        count = cvNorm( silh_roi, None, CV_L1, None ) # calculate number of points within silhouette ROI
         if( count < comp_rect.width * comp_rect.height * 0.05 ):
-            continue;
+            continue
         center = cvPoint( (comp_rect.x + comp_rect.width/2),
-                          (comp_rect.y + comp_rect.height/2) );
-        cvCircle( dst, center, cvRound(magnitude*1.2), color, 3, CV_AA, 0 );
+                          (comp_rect.y + comp_rect.height/2) )
+        cvCircle( dst, center, cvRound(magnitude*1.2), color, 3, CV_AA, 0 )
         cvLine( dst, center, cvPoint( cvRound( center.x + magnitude*cos(angle*CV_PI/180)),
-                cvRound( center.y - magnitude*sin(angle*CV_PI/180))), color, 3, CV_AA, 0 );
+                cvRound( center.y - magnitude*sin(angle*CV_PI/180))), color, 3, CV_AA, 0 )
 
 if __name__ == "__main__":
-    motion = 0;
-    capture = 0;
+    motion = 0
+    capture = 0
 
     if len(sys.argv)==1:
         capture = cvCreateCameraCapture( 0 )
     elif len(sys.argv)==2 and sys.argv[1].isdigit():
         capture = cvCreateCameraCapture( int(sys.argv[1]) )
     elif len(sys.argv)==2:
-        capture = cvCreateFileCapture( sys.argv[1] ); 
+        capture = cvCreateFileCapture( sys.argv[1] ) 
 
     if not capture:
         print "Could not initialize capturing..."
         sys.exit(-1)
         
-    cvNamedWindow( "Motion", 1 );
+    cvNamedWindow( "Motion", 1 )
     while True:
-        image = cvQueryFrame( capture );
+        image = cvQueryFrame( capture )
         if( image ):
             if( not motion ):
-                    motion = cvCreateImage( cvSize(image.width,image.height), 8, 3 );
-                    cvZero( motion );
-                    motion.origin = image.origin;
-            update_mhi( image, motion, 30 );
-            cvShowImage( "Motion", motion );
+                    motion = cvCreateImage( cvSize(image.width,image.height), 8, 3 )
+                    cvZero( motion )
+                    #motion.origin = image.origin
+            update_mhi( image, motion, 30 )
+            cvShowImage( "Motion", motion )
             if( cvWaitKey(10) != -1 ):
-                break;
+                break
         else:
             break
-    cvDestroyWindow( "Motion" );
+    cvDestroyWindow( "Motion" )
index 5cbf811cb6add199bcd5f964bfcae3fffc67b1f8..edf32d4bd9522bdf9e24891ae4d8bf8692b1f8dd 100755 (executable)
@@ -20,7 +20,7 @@ for fn in sys.argv[1:]:
     f = open( fn, "r" )
     in_define = 0
     for l in f.xreadlines():
-        m = re.match( r"^#define\s+((?:CV_|IPL_|cv)\w+)\s+((?:CV|IPL|cv)\w*)$", l )
+        m = re.match( r"^#define\s+((?:CV_|IPL_|cv)\w+)\s+((?:CV|IPL|cv)\w*)\s*$", l )
         if m and not l.endswith( "\\\n" ) and not EXCLUDE.has_key(m.group(1)):
             print "%s=%s" % (m.group(1), m.group(2))
     f.close()