本文整理汇总了Java中org.opencv.video.Video.calcOpticalFlowPyrLK方法的典型用法代码示例。如果您正苦于以下问题:Java Video.calcOpticalFlowPyrLK方法的具体用法?Java Video.calcOpticalFlowPyrLK怎么用?Java Video.calcOpticalFlowPyrLK使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.opencv.video.Video
的用法示例。
在下文中一共展示了Video.calcOpticalFlowPyrLK方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: onCameraFrame
import org.opencv.video.Video; //导入方法依赖的package包/类
public Mat onCameraFrame(CvCameraViewFrame inputFrame) {
final int viewMode = mViewMode;
switch (viewMode) {
case VIEW_MODE_OPTICAL_FLOW:
mGray = inputFrame.gray();
if(features.toArray().length==0){
int rowStep = 50, colStep = 100;
int nRows = mGray.rows()/rowStep, nCols = mGray.cols()/colStep;
// Log.d(TAG, "\nRows: "+nRows+"\nCols: "+nCols+"\n");
Point points[] = new Point[nRows*nCols];
for(int i=0; i<nRows; i++){
for(int j=0; j<nCols; j++){
points[i*nCols+j]=new Point(j*colStep, i*rowStep);
// Log.d(TAG, "\nRow: "+i*rowStep+"\nCol: "+j*colStep+"\n: ");
}
}
features.fromArray(points);
prevFeatures.fromList(features.toList());
mPrevGray = mGray.clone();
break;
}
nextFeatures.fromArray(prevFeatures.toArray());
Video.calcOpticalFlowPyrLK(mPrevGray, mGray, prevFeatures, nextFeatures, status, err);
List<Point> prevList=features.toList(), nextList=nextFeatures.toList();
Scalar color = new Scalar(255);
for(int i = 0; i<prevList.size(); i++){
// Core.circle(mGray, prevList.get(i), 5, color);
Imgproc.line(mGray, prevList.get(i), nextList.get(i), color);
}
mPrevGray = mGray.clone();
break;
case VIEW_MODE_KLT_TRACKER:
mGray = inputFrame.gray();
if(features.toArray().length==0){
Imgproc.goodFeaturesToTrack(mGray, features, 10, 0.01, 10);
Log.d(TAG, features.toList().size()+"");
prevFeatures.fromList(features.toList());
mPrevGray = mGray.clone();
// prevFeatures.fromList(nextFeatures.toList());
break;
}
// OpticalFlow(mPrevGray.getNativeObjAddr(), mGray.getNativeObjAddr(), prevFeatures.getNativeObjAddr(), nextFeatures.getNativeObjAddr());
Video.calcOpticalFlowPyrLK(mPrevGray, mGray, prevFeatures, nextFeatures, status, err);
List<Point> drawFeature = nextFeatures.toList();
// Log.d(TAG, drawFeature.size()+"");
for(int i = 0; i<drawFeature.size(); i++){
Point p = drawFeature.get(i);
Imgproc.circle(mGray, p, 5, new Scalar(255));
}
mPrevGray = mGray.clone();
prevFeatures.fromList(nextFeatures.toList());
break;
default: mViewMode = VIEW_MODE_KLT_TRACKER;
}
return mGray;
}
示例2: track
import org.opencv.video.Video; //导入方法依赖的package包/类
/**
* @return Pair of new, FILTERED, last and current POINTS, or null if it hasn't managed to track anything.
*/
Pair<Point[], Point[]> track(final Mat lastImg, final Mat currentImg, Point[] lastPoints){
final int size = lastPoints.length;
final MatOfPoint2f currentPointsMat = new MatOfPoint2f();
final MatOfPoint2f pointsFBMat = new MatOfPoint2f();
final MatOfByte statusMat = new MatOfByte();
final MatOfFloat errSimilarityMat = new MatOfFloat();
final MatOfByte statusFBMat = new MatOfByte();
final MatOfFloat errSimilarityFBMat = new MatOfFloat();
//Forward-Backward tracking
Video.calcOpticalFlowPyrLK(lastImg, currentImg, new MatOfPoint2f(lastPoints), currentPointsMat,
statusMat, errSimilarityMat, WINDOW_SIZE, MAX_LEVEL, termCriteria, 0, LAMBDA);
Video.calcOpticalFlowPyrLK(currentImg, lastImg, currentPointsMat, pointsFBMat,
statusFBMat, errSimilarityFBMat, WINDOW_SIZE, MAX_LEVEL, termCriteria, 0, LAMBDA);
final byte[] status = statusMat.toArray();
float[] errSimilarity = new float[lastPoints.length];
//final byte[] statusFB = statusFBMat.toArray();
final float[] errSimilarityFB = errSimilarityFBMat.toArray();
// compute the real FB error (relative to LAST points not the current ones...
final Point[] pointsFB = pointsFBMat.toArray();
for(int i = 0; i < size; i++){
errSimilarityFB[i] = Util.norm(pointsFB[i], lastPoints[i]);
}
final Point[] currPoints = currentPointsMat.toArray();
// compute real similarity error
errSimilarity = normCrossCorrelation(lastImg, currentImg, lastPoints, currPoints, status);
//TODO errSimilarityFB has problem != from C++
// filter out points with fwd-back error > the median AND points with similarity error > median
return filterPts(lastPoints, currPoints, errSimilarity, errSimilarityFB, status);
}