Forums - Optical Flow Lucas Kanade fcvTrackLKOpticalFlowu8

11 posts / 0 new
Last post
Optical Flow Lucas Kanade fcvTrackLKOpticalFlowu8
AriKaspari
Join Date: 9 Feb 13
Posts: 4
Posted: Sun, 2013-02-10 03:55
Hello, has anybody written some example code for Lucas Kanade Flow, yet? At the moment i use fcvCornerFast9u8 to detect Feature and now i wll use fcvTrackLKOpticalFlowu8 to calculate the position of the features in the second image. Sadly i can find nowhere some example code for fastCV Lucas Kanade. The are much more parameters than in OpenCV :-( Best regards Ari Kaspari
  • Up0
  • Down0
jeff4s Moderator
Join Date: 4 Nov 12
Posts: 106
Posted: Sun, 2013-02-10 23:19

Hope the following snippet helps. By the way, there are some fixes for fcvTrackLKOpticalFlowu8 in the upcoming FastCV 1.2.0 release to improve tracking performance. The release should come out very soon.

//Initialize pyramid structures
src1Pyr = new fcvPyramidLevel[nPyramidLevels];
src2Pyr = new fcvPyramidLevel[nPyramidLevels];
dx1Pyr = new fcvPyramidLevel[nPyramidLevels];
dy1Pyr = new fcvPyramidLevel[nPyramidLevels];

fcvPyramidAllocate( src1Pyr, width, height, 4, nPyramidLevels, 0 );
fcvPyramidAllocate( src2Pyr, width, height, 4, nPyramidLevels, 0 );
fcvPyramidAllocate( dx1Pyr, width, height, 4, nPyramidLevels, 1 );
fcvPyramidAllocate( dy1Pyr, width, height, 4, nPyramidLevels, 1 );

fcvPyramidCreateu8( src1, width, height, nPyramidLevels, src1Pyr );
fcvPyramidCreateu8( src2, width, height, nPyramidLevels, src2Pyr );

fcvPyramidSobelGradientCreatei8( src1Pyr, dx1Pyr, dy1Pyr, nPyramidLevels );

fcvTrackLKOpticalFlowu8(
src1, src2, width, height,
src1Pyr, src2Pyr,
dx1Pyr, dy1Pyr,
(float *) featureXY_in.Ptr(),
(float *) featureXY_out.Ptr(),
(int32_t*)featureStatus_in.Ptr(),
featureXY_in.Shape().height,
windowWidth, windowHeight,
maxIterations, nPyramidLevels,
maxResidue, minDisplacement, 0, 0 );

  • Up0
  • Down0
AriKaspari
Join Date: 9 Feb 13
Posts: 4
Posted: Mon, 2013-02-11 01:22
Please, can you show me the declaration of "featureXY_in" Best regards Ari
  • Up0
  • Down0
sagiv
Join Date: 2 Sep 12
Posts: 12
Posted: Mon, 2013-02-11 01:59
I think its a float array of size = 2 * numberOfFeatures featureXY[0] = feature_1_x featureXY[1] = feature_1_y featureXY[2] = feature_2_x featureXY[3] = feature_2_y . . . featureXY[2*numberOfFeatures] = feature_numberOfFeatures_x featureXY[2*numberOfFeatures + 1] = feature_numberOfFeatures_y
  • Up0
  • Down0
AriKaspari
Join Date: 9 Feb 13
Posts: 4
Posted: Mon, 2013-02-11 05:29
Does anybody can send me a complete Android FastCV Lukas Kanade Optical Flow example for testing? My Example will not run correct. The number of my found features (fcvCornerFast9u8 ) is nearly constant while my matched features are in the beginning equal than the found features but get less and less.
  • Up0
  • Down0
sagiv
Join Date: 2 Sep 12
Posts: 12
Posted: Mon, 2013-02-11 05:47

Try to set each featureStatus[i] to '0' before calling fcvTrackLKOpticalFlowu8
I found that fcvTrackLKOpticalFlowu8 doesn't operate on features[i] where featureStatus[i] < 1
I guess that featureStatus is an in AND out parameter, meaning that it works in both directions, so if a some featureStatus[i] gets '-5' for large_residual it (feature number i) will never get processed again unless you set it's status before calling LK.
It took me almost 3 days to figure this out, but I'm still not sure whether it's a bug or feature. The doc doesn't say if it's an input or/and output parameter.

  • Up0
  • Down0
AriKaspari
Join Date: 9 Feb 13
Posts: 4
Posted: Mon, 2013-02-11 06:46
That's it! Thank you very much!
  • Up0
  • Down0
xzhong
Join Date: 7 Feb 13
Posts: 4
Posted: Mon, 2013-02-11 11:56
Sagiv is right. I tried cleaning all the fcvStatus before calling fcvTrackLKOpticalFlowu8(), everything worked fine. The status will return with 1 for success, and 0 or negative values for failures (type of failure defined in fastcv.h) I don't think all the parameters are required. Latest documents stated dx1Pyr, dy1Pyr can be NULL, and the following 4 parameters can all be 0. float maxResidue, float minDisplacement, float minEigenvalue, int lightingNormalized best regards, Xin
  • Up0
  • Down0
Lubos Omelina
Join Date: 20 Feb 13
Posts: 3
Posted: Tue, 2013-03-12 18:27

Hi guys,

I guess I'm confused a bit. Is the  featureXY_in the result from fcvCornerFast9u8() hardcasted from (uint32_t *) to (float *)?

  • Up0
  • Down0
sourav3515
Join Date: 9 Jan 13
Posts: 6
Posted: Wed, 2014-08-20 06:57

Hi Everyone, 

I awant to track some key points, from a reference src in a current src.

I am first extracting keypoints from reference src using fcvCornerHarrisu8, getting corner's array, and passing refrence src, current src, extracted corner's array, in fcvTrackLKOpticalFlowu8, in which i expect that the other array which i passed will get filled for the matched key points in the current frame.

I am not getting the correct result, by feature status is coming negative, what is the significance of this corner status?

Does it require that the src1 and src2 have to be of same width and height?

Is the array filled for current frame have one-t-one correspondence from the array passed for the refrence frame.

Please help in getting my doubt cleared.

 

thanks

Sourav

  • Up0
  • Down0
jeff4s Moderator
Join Date: 4 Nov 12
Posts: 106
Posted: Wed, 2014-08-20 10:41

src1 and src2 have the same dimension. The parameter list has been cleaned up and made more clear in fcvTrackLKOpticalFlowu8_v2, please use that version and make sure inputs are filled properly.

 

  • Up0
  • Down0
or Register

Opinions expressed in the content posted here are the personal opinions of the original authors, and do not necessarily reflect those of Qualcomm Incorporated or its subsidiaries (“Qualcomm”). The content is provided for informational purposes only and is not meant to be an endorsement or representation by Qualcomm or any other party. This site may also provide links or references to non-Qualcomm sites and resources. Qualcomm makes no representations, warranties, or other commitments whatsoever about any non-Qualcomm sites or third-party resources that may be referenced, accessible from, or linked to this site.