开发者

Subtraction of subsequent frames in EmguCV 2.2 (cvAbsDiff)

I am using two QueryFrame commands one after the other to obtain to frames and calculate their differences using CvInvoke.cvAbsDiff. The difference image is always black, although there are visible changes from frame to f开发者_开发技巧rame in my video.

I tried skipping up to five frames (by using consecutive QueryFrame commands) and always get a black frame.

If I equalize the histogram of one of the two frames, the AbsDiff does return a result. Hence I assume that the QueryFrame returns the same frame.

How can I obtain two consecutive frames? Any ideas?


Sorry about the comments... here comes the solution I found useful:

 private Capture myCapture;
 private Image<Bgr, Byte> frame1;
 private Image<Bgr, byte> frame2;

 private void myFunction1() 
 {
   myCapture = new Capture(@"AnyVideoFileName");
   frame1 = myCapture.QueryFrame();
  }

 private void myEventMethod(object sender, EventArgs e) 
 {
   Application.Idle += myFunction2;
 }

 private void myFunction2(object sender, EventArgs e)
 {
   frame2 = myCapture.QueryFrame();


   Image<Gray, Byte> frame1g = frame1.Convert<Gray,Byte>();
   Image<Gray, Byte> frame2g = frame2.Convert<Gray,Byte>();
   Image<Gray, Byte> diffFrame = frame2g.Clone();

   CvInvoke.cvAbsDiff(frame1g, frame2g, diffFrame);

   frame1 = frame2.Clone();
 }

The above code is just to give you an idea of how it is done. There is no exception handling included, no checks, no optimizations.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜