コード例 #1
0
  if max_frames:
    if t > max_frames:
      break
  # capture the next frame
  frame = ocv.cvQueryFrame(cap)
  # if we've reached the end of the video
  if frame is None:
    break

  if t>=(max_frames-NUM_FRAMES):
 
    # Convert to floating point
    ocv.cvConvert(frame,working)
 
    # Smooth it to remove artifacts
    ocv.cvSmooth(working,working,ocv.CV_GAUSSIAN,3,3,0.5)

    # Add to accumulator
    ocv.cvAcc(working,accumulator)

    # Divide accumulator my number of frames for mean background
    ocv.cvDiv(accumulator,ones,background,1.0/n)

    # Convert background to target (for viewing/saving)
    ocv.cvConvert(background,target)
 
    # Increment accumulator divisor
    n += 1

  # Increment frame
  t += 1
コード例 #2
0
ファイル: track.py プロジェクト: mikedewar/CourtshipIndex
  if frame is None:
    break
  # update outputs to the new frame
  ocv.cvCopy(frame,output)

  # Mask - if you do this here you get edge artifacts
  #ocv.cvCopy(frame,m_frame,mask)

  # Convert frame to grayscale
  ocv.cvConvertImage(frame,gray)

  # Convert grayscale to float
  ocv.cvConvert(gray,grayfloat)

  # Smooth - CRITICAL to remove codec artifacts
  ocv.cvSmooth(grayfloat,grayfloat,ocv.CV_GAUSSIAN,3,3,0.5)
  #ocv.cvSmooth(gray,gray,ocv.CV_MEDIAN)

  # Subtract current frame from background model
  ocv.cvAbsDiff(grayfloat, background, grayfloat);

  # Normalise image
  ocv.cvSet(ones,ocv.cvScalar(1.0,0,0,0),0) 
  minval = ocv.cvMinMaxLoc(grayfloat,True,False)
  maxval = ocv.cvMinMaxLoc(grayfloat,False,True)
  #print min,max
  ocv.cvSubS(grayfloat,ocv.cvScalar(minval,0,0,0),grayfloat,0)
  if ((maxval-minval)!=0): #Stop divide by zero
    ocv.cvDiv(grayfloat,ones,grayfloat,1.0/(maxval-minval))
  else:
    cvZero(grayfloat)