cv::InputOutputArray corners, // Guesses in, and results out
cv::Size winSize, // Area is NXN; N=(winSize*2+1)
cv::Size zeroZone, // Size(-1,-1) to ignore
cv::TermCriteria criteria // When to stop refinement
);
参数
描述
image
计算角点的原始图像
corners
角点位置的初始值(从cv::goodFeaturesToTrack获得)
winSize
指定将生成方程的窗口大小
zeroZone
Size(-1,-1) to ignore
criteria
终止条件
亚像素精度原理
p在q的邻域内,向量qp绕着q旋转360°. q向着∑<∇I(p),q−p>=0的方向修正
In Figure 16-2, we assume a starting corner location q that is near the actual subpixel corner location. We examine vectors starting at point q and ending at p. When p is in a nearby uniform or “flat” region, the gradient there is 0. On the other hand, if the vector q-p aligns with an edge, then the gradient at p on that edge is orthogonal to the vector q-p. In either case, the dot product between the gradient at p and the vector qp is 0. We can assemble many such pairs of the gradient at a nearby point p and the associated vector q-p, set their dot product to 0, and solve this assemblage as a system of equations; the solution will yield a more accurate subpixel location for q, the exact location of the corner.
调用金字塔LK算法
源码
cv::calcOpticalFlowPyrLK(
imgA, // Previous image
imgB, // Next image
cornersA, // Previous set of corners (from imgA)
cornersB, // Next set of corners (from imgB)
features_found, // Output vector, each is 1 for tracked
cv::InputArray nextImg, // Next image (t), CV_8UC1
cv::InputArray prevPts, // Vector of 2d start points (CV_32F)
cv::InputOutputArray nextPts, // Results: 2d end points (CV_32F)
cv::OutputArray status, // For each point, found=1, else=0
cv::OutputArray err, // Error measure for found points
cv::Size winSize = Size(15,15), // size of search window
int maxLevel = 3, // Pyramid layers to add
cv::TermCriteria criteria = TermCriteria( // How to end search
cv::TermCriteria::COUNT | cv::TermCriteria::EPS,
30,
0.01
),
int flags = 0, // use guesses, and/or eigenvalues
double minEigThreshold = 1e-4// for spatial gradient matrix
);
参数
描述
prevImg,nextImg
连续的两帧图像
prevPts,nextPts
两帧图像对应的特征点
status
两帧图像的对应特征点匹配,status[i] = 1
err
对应特征点的错误度量
winSize
卷积核的大小
maxLevel
金字塔深度
criteria
终止条件
flags
终止条件用到的参数
minEigThreshold
类似cv::goodFeaturesToTrack的qualityLevel
The argument flags can have one or both of the following values:
cv::OPTFLOW_LK_GET_MIN_EIGENVALS
Set this flag for a somewhat more detailed error measure. The default error meas‐
ure for the error output is the average per-pixel change in intensity between the
window around the previous corner and the window around the new corner.
With this flag set to true, that error is replaced with the minimum eigenvalue of
the Harris matrix associated with the corner.8
cv::OPTFLOW_USE_INITIAL_FLOW
Use when the array nextPts already contains an initial guess for the feature’s
coordinates when the routine is called. (If this flag
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步