title: What's the fastest way to iterate over a CvMat in Python using OpenCV?
body: <p>I'm using OpenCV with Python to process a video stream. I'd like to implement my own algorithm, so I need to iterate over each frame.</p>
  
  <p>What I have so far works, but way too slow to be real-time. I know that Python isn't the most efficient programming language, but I believe it can do much better than this, considering, that the built in image transformation functions are very fast. Numpy may be the way to go, but I'm not yet familiar with it.</p>
  
  <pre><code>import cv, numpy
  vidFile = cv.CaptureFromFile( 'sample.avi' )
  nFrames = int(  cv.GetCaptureProperty( vidFile, cv.CV_CAP_PROP_FRAME_COUNT ) )
  for f in xrange( nFrames ):
    frameImg = cv.QueryFrame( vidFile )
    frameMat=cv.GetMat(frameImg)
    print "mat ", mat[3,1]
    for x in xrange(frameMat.cols):
      for y in xrange(frameMat.rows):
          # just an example, multiply all 3 components by 0.5
          frameMat[y, x] = tuple(c*0.5 for c in frameMat[y, x])
    cv.ShowImage( "My Video Window",  frameMat )
    if cv.WaitKey( waitPerFrameInMillisec  ) == 27:
      break
  </code></pre>
  
  <p>How can I speed up the process?
  Thanks, b_m</p>