2

我正在开发一个 Android 视频稳定应用程序!我遇到了一些与 goodfeaturestotrack 和 calcOpticalFlowPyrLK 函数相关的问题,因为最终输出是相同的点!我用谷歌搜索了每一个关于这个的网站,但我无法解决它!我的代码有什么问题?

mRgba1 = new Mat(height, width, CvType.CV_8UC4);
mRgba2 = new Mat(height, width, CvType.CV_8UC4);
mGray1 = new Mat(mRgba1.size(), CvType.CV_8UC1);
mGray2 = new Mat(mRgba2.size(), CvType.CV_8UC1);
mView = new Mat(height, width, CvType.CV_8UC4);
initial = new MatOfPoint();
status = new MatOfByte();
err = new MatOfFloat();
mask = new Mat(mRgba1.size(), CvType.CV_8UC1);
prevPts = new MatOfPoint2f();
nextPts = new MatOfPoint2f();
Imgproc.goodFeaturesToTrack(mGray1, initial, maxCorners, 0.01, 0.01);
initial.convertTo(prevPts, CvType.CV_32FC2);
Video.calcOpticalFlowPyrLK(mGray1, mGray2, prevPts, nextPts, status, err, winSize, 5, optical_flow_termination_criteria, 0, 1);

然后,当我向他们展示时:

Point[] pointp = prevPts.toArray();
Point[] pointn = nextPts.toArray();
for (Point px : pointp) 
{ Core.circle(mView, px, 15, circleColor); }
for (Point py : pointn) 
{ Core.circle(mView, py, 5, line_color); }

我在同一个位置有 2 个不同的圆圈,这不好:(

4

1 回答 1

1

我认为问题在于视频捕获一遍又一遍地传递相同的图像。您是否尝试克隆视频捕捉垫!另外要尝试的另一件事是,calcOpticalFlowPyrLK 有 3 种不同的调用方式。我建议使用这个

Video.calcOpticalFlowPyrLK(prevImg, nextImg, prevPts, nextPts, status, err, winSize, maxLevel)

:D

TermCriteria termcrit = new TermCriteria(TermCriteria.MAX_ITER|TermCriteria.EPS,25,0.03);
        Video.calcOpticalFlowPyrLK(temp3, temp2, prevPts, nextPts, status, err, winSize, 5);
        //Video.calcOpticalFlowPyrLK(prevImg, nextImg, prevPts, nextPts, status, err)
        //Video.calcOpticalFlowPyrLK(temp3, temp2, prevPts, nextPts, status, err, winSize, 5, termcrit, 0, 1);
于 2012-12-23T17:45:32.303 回答