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 if show: ocv.cvShowImage ('Track', target) # Break if ESC if ocv.cvWaitKey (5) & 255 == 27: break
# 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) ocv.cvScale(grayfloat,grayfloat,255.0) # Scale back to 0-255 # Convert back to int ocv.cvConvert(grayfloat,gray) #ocv.cvMerge(gray,gray,gray,0,output) # Show on output #Find the "lightest" things in the image #TODO: find "dip" inbetween #ocv.cvEqualizeHist(gray,gray) thresholdat = 70 #30 # Threshold frame #ocv.cvAdaptiveThreshold(