如何在CamShift中平滑跟踪

问题描述:

我正在使用OpenCV库函数进行项目跟踪。通过使用 Camshift()功能,我可以跟踪我的手,但它并不稳定,即使我的手保持稳定,跟踪也没有什么动静。所以我无法在正确的位置执行鼠标点击操作。有人请帮我解决这个问题。

I'm Doing Project on hand Tracking using OpenCV library function. By using Camshift() function I could able to track my hands but it wasn't not stable, even I make my hand stable there is little movement in tracking. So I couldn't able to perform mouse click operation at correct position. Someone please help me to figure out this.

void TrackingObjects::drawRectangle(CvRect objectLocation){
CvPoint p1, p2,mou;
CvRect crop;
p1.x = objectLocation.x;
p2.x = objectLocation.x + objectLocation.width;

p1.y = objectLocation.y;
p2.y = objectLocation.y + objectLocation.height;

cvRectangle(image,p1,p2,CV_RGB(0,255,0),1,CV_AA,0);

mou.x=(p2.x-p1.x)/2;
mou.x=p1.x+mou.x;
mou.y=(p2.y-p1.y)/2;
mou.y=p1.y+mou.y;

SetCursorPos(mou.x,mou.y);

}

在上面的代码中,我通过 obectLocation 参数,我在被跟踪区域上绘制了矩形。
通过获得它的中心我做了鼠标移动。

In above code I get the tracked object location by obectLocation parameter and I've drawn rectangle over the tracked region. By getting its center I did mouse movement.

关闭手掌以便做 MouseDown 事件,被跟踪对象的位置已被更改。

While closing the palm in order to do MouseDown event, the position of tracked object has being changed.

答案是卡尔曼滤波器。
您可以使用这个代码。如下图所示,过滤后的结果(绿线)忽略了跟踪器的突然位移(青色描绘了原始跟踪结果)。

The answer is Kalman filters. You can use this code. As you can see in the figure below, the filtered results (green line) ignore tracker's sudden displacements (where cyan depicts the original tracking results).