在slam里,光流跟踪判断图像中某一物体的动态性,主要包括3个函数:
作用:提取输入图像中像素级别的角点,支持harris角点和Shi Tomasi角点。
函数原型:
void goodFeaturesToTrack( InputArray image, OutputArray corners,
int maxCorners, double qualityLevel, double minDistance,
InputArray mask=noArray(), int blockSize=3,
bool useHarrisDetector=false, double k=0.04 );
参数说明:
作用:由于goodFeaturesToTrack函数提取的角点是像素级别,在slam等一些情况里应用像素级别的角点不满足精度要求,cornerSubPix()函数能将像素级角点作进一步的优化计算,使之达到亚像素级别。
函数原型:
void cornerSubPix(InputArray image,
InputOutputArray corners,
Size winSize,
Size zeroZone,
TermCriteria criteria)
参数说明:
作用:基于图像金字塔的LK光流跟踪
函数原型:
void cv::calcOpticalFlowPyrLK (
InputArray prevImg,
InputArray nextImg,
InputArray prevPts,
InputOutputArray nextPts,
OutputArray status,
OutputArray err,
Size winSize = Size(21, 21),
int maxLevel = 3,
TermCriteria criteria = TermCriteria(TermCriteria::COUNT+TermCriteria::EPS, 30, 0.01),
)
参数说明:
实例:
cv::goodFeaturesToTrack(
mImGrayPre,
lastFramePoints,
1000,
0.01,
8,
cv::Mat(),
3,
false,
0.04);
cv::cornerSubPix(
mImGrayPre,
lastFramePoints,
cv::Size(5, 5),
cv::Size(-1, -1),
cv::TermCriteria(CV_TERMCRIT_ITER | CV_TERMCRIT_EPS, 30, 0.01));
cv::calcOpticalFlowPyrLK(
mImGrayPre,
imGray,
lastFramePoints,
trackedPoints,
state,
err,
cv::Size(21, 21),
3,
cv::TermCriteria(CV_TERMCRIT_ITER | CV_TERMCRIT_EPS, 30, 0.01));