Repository: opencv
Issue: Need another calcOpticalFlowPyrLK Java signature taking input List<Mat> pyramid
Labels: auto-transferred,priority: normal,feature,category: java bindings

Transferred from http://code.opencv.org/issues/3508

```
|| Xin Guo on 2014-01-28 19:18
|| Priority: Normal
|| Affected: None
|| Category: java bindings
|| Tracker: Feature
|| Difficulty: Medium
|| PR: 
|| Platform: None / None
```
## Need another calcOpticalFlowPyrLK Java signature taking input List<Mat> pyramid

```
The function of @buildOpticalFlowPyramid@ and @calcOpticalFlowPyrLK@ in OpenCV-2.4.8-android-sdk is:

<pre>
public static int buildOpticalFlowPyramid(Mat img, List<Mat> pyramid, Size winSize, int maxLevel)

public static void calcOpticalFlowPyrLK(Mat prevImg, Mat nextImg, MatOfPoint2f prevPts, MatOfPoint2f nextPts, MatOfByte status, MatOfFloat err, Size winSize, int maxLevel, TermCriteria criteria, int flags, double minEigThreshold)
</pre>

If I just use the image as the input of @calcOpticalFlowPyrLK@, not using pyramid, it works well. But If I use @buildOpticalFlowPyramid@ to build a pyramid as input of @calcOpticalFlowPyrLK@. The @List<Mat> pyramid@ is not applicable for @Mat prevImg@. 

If I declare the pyramid as @vector<Mat>@, @buildOpticalFlowPyramid@  works well, but the app will be forced to stop whenever call @calcOpticalFlowPyrLK@.

Here is parts of the code.

<pre>
MatOfByte status = new MatOfByte();
int maxlevel=2;

Mat prev = new Mat(mRgba.size(),CvType.CV_8UC1);
Mat curr = new Mat(mRgba.size(),CvType.CV_8UC1);
List<Mat> pyramid1= new ArrayList<Mat>(maxlevel);
List<Mat> pyramid2= new ArrayList<Mat>(maxlevel);

Mat pyramid3 = new Mat();
Mat pyramid4 = new Mat();

MatOfPoint2f featurestracked = new MatOfPoint2f();
MatOfFloat err = new MatOfFloat();

int i,count;
TermCriteria optical_flow_termination_criteria =new TermCriteria();

optical_flow_termination_criteria.epsilon =.03;
optical_flow_termination_criteria.maxCount = 20;
Size winSize = new Size(21,21);



Imgproc.cvtColor(hp.TrackingFrame, prev, Imgproc.COLOR_RGBA2GRAY,0);

Imgproc.cvtColor(mRgba, curr, Imgproc.COLOR_RGBA2GRAY,0);

//Build pyramid
int level1= Video.buildOpticalFlowPyramid(prev, pyramid1, winSize, maxlevel);
int level2 = Video.buildOpticalFlowPyramid(curr, pyramid2, winSize, maxlevel);

pyramid3 = Converters.vector_Mat_to_Mat(pyramid1);
pyramid4 = Converters.vector_Mat_to_Mat(pyramid2);

MatOfPoint2f features_next2f = new MatOfPoint2f(hp.features_next.toArray());

Video.calcOpticalFlowPyrLK(pyramid3, pyramid4,features_next2f,featurestracked,status,err, winSize,maxlevel,optical_flow_termination_criteria, 0, 0.001);
</pre>
```
## History
##### Vladislav Vinogradov on 2014-01-29 07:47

```
-   Description changed from The function of buildOpticalFlowPyramid and
    calcOpticalFlowPyrLK in OpenCV-2.... to The function of
    buildOpticalFlowPyramid and calcOpticalFlowPyrLK in OpenCV-2....
    More
```
##### Vladislav Vinogradov on 2014-01-29 07:49

```
-   Description changed from The function of buildOpticalFlowPyramid and
    calcOpticalFlowPyrLK in OpenCV-2.... to The function of
    @buildOpticalFlowPyramid@ and @calcOpticalFlowPyrLK@ in OpenC...
    More
```
##### Vladislav Vinogradov on 2014-01-29 07:52

```
-   Status changed from New to Open
-   Category changed from android to java bindings
```
##### Alexander Smorkalov on 2014-01-29 12:45

```
@Andrey Pavlenko, can you comment the issue?
```
##### Xin Guo on 2014-01-29 17:55

```
FYI：when I declare the pyramid as vector<Mat>, I use the Converters.vector_Mat_to_Mat(Pyramid) as the input of calcOpticalFlowPyrLK. 
Thank you very much.
```
##### Xin Guo on 2014-02-02 20:43

```
Could you please comment this issue? Or give me some info about how to do about it? Thank you. 

Alexander Smorkalov wrote:
> @Andrey Pavlenko, can you comment the issue?
```
##### Andrey Pavlenko on 2014-02-04 15:56

```
Java version of this function doesn't support pyramid as input.
This is actually a feature request on adding one more @calcOpticalFlowPyrLK@ signature taking @List<Mat>@ (we don't have @InputArray@ in Java).
```
##### Andrey Pavlenko on 2014-02-04 15:59

```
-   Subject changed from can not input a List<Mat> pyramid into
    calcOpticalFlowPyrLK (OpenCV-2.4.8-android-sdk) to Need another
    calcOpticalFlowPyrLK Java signature taking input List<Mat> pyramid
-   Difficulty set to Medium
-   Tracker changed from Bug to Feature
```
##### Xin Guo on 2014-02-11 15:43

```
Thank you.
Andrey Pavlenko wrote:
> Java version of this function doesn't support pyramid as input.
> This is actually a feature request on adding one more @calcOpticalFlowPyrLK@ signature taking @List<Mat>@ (we don't have @InputArray@ in Java).
```
##### Alexander Smorkalov on 2014-03-28 22:20

```
-   Target version set to 3.0-alpha
```
##### Maksim Shabunin on 2015-04-27 09:11

```
-   Target version changed from 3.0-alpha to 3.0
```