我正在使用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个不同的圈子,但这并不好:(
答案 0 :(得分:1)
我认为问题是视频捕捉一遍又一遍地传递相同的图像。 你有没有尝试克隆视频捕捉垫! 另外还有一件事,calcOpticalFlowPyrLK有三种不同的方式可以调用。我建议使用这个
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);