« Return to Thread: C++ interface for CvCapture, CvVideoWriter?

Re: Small change proposal foricvCalcOpticalFlowPyrLK_8uC1R

by Pisarevsky, Vadim :: Rate this Message:

Reply to Author | View in Thread

Some parts of this message have been removed. Learn more about Nabble's security policy.

Adi,

 

I think, such a change will be useful.

Regarding possible optimizations. Because of the covariation matrix properties you do not need to compute both eigen values and choose min. It will be just:

 

double smallEig = (Gxx + Gyy – sqrt((Gxx – Gyy)*(Gxx – Gyy) + Gxy*Gxy)))*0.5;

 

Regards,

Vadim

 

From: opencvlibrary-devel-bounces@... [mailto:opencvlibrary-devel-bounces@...] On Behalf Of Adi Shavit
Sent: Sunday, May 04, 2008 1:44 PM
Cc: opencvlibrary-devel@...
Subject: [Opencvlibrary-devel] Small change proposal foricvCalcOpticalFlowPyrLK_8uC1R

 

Hi,

  For a project I've been working on, I needed to know the confidence of the LK tracker result.
Although the status vector gives a binary answer, it is not always enough.

One way to know if the tracked point is not on a corner but on an e.g. is by checking the eigenvals of the 2x2 derivative matrix.
A small eigenvalue means that the matrix is badly conditioned and that either this is an edge (a single small eigenval == aperture effect), or that this is a smooth featureless region (2 small eigen vals).

These situation can happen when the points are not from GoodFeaturesToTrack (which is heavy) or after tracking point over a long time period where drift can happen.

I made a small non-API breaking change to cvlkpyramid.cpp:

*** cvlkpyramid.new.cpp Wed Apr 30 14:10:31 2008
--- cvlkpyramid.org.cpp Thu Aug 31 19:14:36 2006
***************
*** 541,561 ****
                      }

                      D = Gxx * Gyy - Gxy * Gxy;
-
                      if( D < DBL_EPSILON )
                      {
                          pt_status = 0;
                          break;
                      }
-
-                     //////////////////////////////////////////////////////////////////////////
-                     // Adi Shavit - 2008.04
-                     double smallEig  = MIN( -(sqrt(Gyy*Gyy-2*Gxx*Gyy+4*Gxy*Gxy+Gxx*Gxx)-Gyy-Gxx)/2,
-                                              (sqrt(Gyy*Gyy-2*Gxx*Gyy+4*Gxy*Gxy+Gxx*Gxx)+Gyy+Gxx)/2);
-
-                     pt_status = MAX(1,cvRound(smallEig/(jsz.height*jsz.width)));
-                     //////////////////////////////////////////////////////////////////////////
-
                      D = 1. / D;

                      prev_minJ = minJ;
--- 541,551 ----
***************
*** 582,594 ****
              }

              featuresB[i] = v;
!
!             //////////////////////////////////////////////////////////////////////////
!             // Adi Shavit - 2008.04
!             status[i] = (char)MIN(pt_status,255);
!             // status[i] = (char)pt_status; // original line
!             //////////////////////////////////////////////////////////////////////////
!
              if( l == 0 && error && pt_status )
              {
                  /* calc error */
--- 572,578 ----
              }

              featuresB[i] = v;
!             status[i] = (char)pt_status;
              if( l == 0 && error && pt_status )
              {
                  /* calc error */

It calculates the closed form solution for the 2x2 eigenvalues, when the Det != 0, and chooses the smaller value.
It then normalizes the eigval by the window size.
This allows the value to fit relatively comfortably in the status var which is (unfortunately) of type char.

The status char now returns 0 for bad tracking and non-zero value when the tracing succeeds as before.
However, the actual value of status is the normalized smallest eigenval.

The code can be a bit more optimized, but I'd like to know if this kind of change would be acceptible here?

What do you think?

Thanks,
Adi




--------------------------------------------------------------------
Closed Joint Stock Company Intel A/O
Registered legal address: Krylatsky Hills Business Park, 
17 Krylatskaya Str., Bldg 4, Moscow 121614, 
Russian Federation

This e-mail and any attachments may contain confidential material for
the sole use of the intended recipient(s). Any review or distribution
by others is strictly prohibited. If you are not the intended
recipient, please contact the sender and delete all copies.

-------------------------------------------------------------------------
This SF.net email is sponsored by the 2008 JavaOne(SM) Conference
Don't miss this year's exciting event. There's still time to save $100.
Use priority code J8TL2D2.
http://ad.doubleclick.net/clk;198757673;13503038;p?http://java.sun.com/javaone
_______________________________________________
Opencvlibrary-devel mailing list
Opencvlibrary-devel@...
https://lists.sourceforge.net/lists/listinfo/opencvlibrary-devel

 « Return to Thread: C++ interface for CvCapture, CvVideoWriter?

LightInTheBox - Buy quality products at wholesale price!