我正在尝试开发一个跟踪车牌的程序。我需要跟踪印版并用ID号标记它们,这样我就可以只为每个印版调用一次识别程序。我有跟踪问题。一旦我成功检测到牌照区域,我就创建了掩模,仅从板上提取特征,然后在整个图像上跟踪它们。我使用goodFeaturesToTrack()
并使用calcOpticalFlowPyrLK()
计算光流量。这是我的算法:
代码(仅限部分):
bool licensePlate = false;
while(1)
{
frame = cvQueryFrame(cap);
if(frame.empty())
break;
cvtColor(frame, frame, CV_BGR2GRAY);
// We have license plate area
if (licensePlate)
{
frame.copyTo(image_next);
goodFeaturesToTrack(image_next, next_features, 50, 0.01, 0.1);
calcOpticalFlowPyrLK( image_previous, image_next, features, next_features, features_found, err );
swap(features, next_features);
}
// We try to obtain license plate area
if (!licensePlate)
{
squares = findLicensePlate(image);
if (!squares.empty())
{
// We have found license plate area
licensePlate = true;
frame.copyTo(image_previous);
Mat roi (mask, Rect(bb.x, bb.y, bb.width, bb.height));
roi.setTo(255);
goodFeaturesToTrack(image_previous, features, 50, 0.01, 0.1, mask);
mask.setTo(0);
}
}
}
输出是:
绿点是以前的功能,红点是实际功能。
正如你所看到的,它们在某种程度上被追踪得很好,但看起来它们已经缩放并远离车牌。我只想从车牌中提取一次功能,然后只从帧中提取功能。 我的逻辑错了。这可能是个问题?