使用Kalman滤波器来filt噪声,而不会延迟OpenCV C
Use Kalman Filter to filt noise without delay opencv c++
我的任务是在视频中检测一个橙色球。我通过HSV Colorspace和边界框上的阈值图像检测到。然后,我的球中心和半径为单位是像素。
当球静态时,我希望中锋和半径也将是静态的,但是现实,它具有噪音。我使用Kalman Filter
来过滤噪声,并且效果很好。但是它实时延迟。我尝试优化协方差参数,但行不通。
那么,当球静态并且毫不延迟时,谁能帮助我static
中心和半径?
您确定是卡尔曼过滤器女巫正在造成延迟。否则,您只能尝试这种懒惰的滤镜女巫是噪声拒绝,但速度非常快。但是我的怀疑是HSV转换。
class noiseFilter
{
private:
cv::Point2f ptLast;
float ptMaxTol;
public:
noiseFilter(float maxTol = 1.5f)
{
ptMaxTol = maxTol * maxTol; // we do the pow(2) here so we don't have to do a square root on every update
ptLast = cv::Point2f(0.0f, 0.0f);
}
cv::Point2f update(cv::Point2f &ptNew) // update filter with new found point
{
float dist = pDistance2(ptLast, ptNew);
if (dist > ptMaxTol) ptLast = ptNew; // update only if distance is more than threshold
return ptLast;
}
cv::Point2f getResult() // get result of filter
{
return ptLast;
}
private:
// calculate distance between 2 point without doing a sqrt
float pDistance2(cv::Point2f &p1, cv::Point2f &p2)
{
float dx = p1.x - p2.x;
float dy = p1.y - p2.y;
return (dx * dx + dy * dy);
}
};
int main()
{
cv::Point2f pt;
noiseFilter filter(2.1f); // initialize filter wit max 2.1 pixels noise rejection.
int x = 100, y = 120;
for (int i = 0; i < 100; i++)
{
// generate some noise with 2 pixels variation
pt.x = ((rand() % 200) - 100) * 0.01f + x;
pt.y = ((rand() % 200) - 100) * 0.01f + y;
cv::Point2f pts = filter.update(pt);
printf("input x=%6.2f y=%6.2f output x=%6.2f y=%6.2frn", pt.x, pt.y, pts.x, pts.y);
// do som random big update on random intervals
if ((rand() % 50) == 1) {
x += 15;
printf("big update on Xrn");
}
if ((rand() % 50) == 1){
y += 25;
printf("big update on Yrn");
}
}
return 0;
}
在平滑的噪声过滤器下方。在慢速和快速移动的对象上工作。
class noiseFilterSmooth
{
private:
static const int maxHist = 10;
cv::Point2f ptLast;
float ptMaxTol;
cv::Point2f hist[maxHist];
int histHead,histSize;
public:
noiseFilterSmooth(float maxTol = 1.5f)
{
histHead = histSize = 0;
ptMaxTol = maxTol * maxTol; // we do the pow(2) here so we don't have to do a square root on every update
ptLast = cv::Point2f(0.0f, 0.0f);
}
cv::Point2f& update(cv::Point2f &ptNew) // update filter with new found point
{
float dist = pDistance2(ptLast, ptNew);
if (dist > ptMaxTol) histSize = histHead = 0; // reset smoothing filter if distance is more than threshold
// update smoothing filter with last result
hist[histHead] = ptNew; // update smoothing filter with last
histHead = (histHead + 1) % maxHist;
if (histSize < maxHist) histSize++;
return getResult();
}
cv::Point2f& getResult() // get result of filter
{
float sumx = 0, sumy = 0;
for (int i = 0; i < histSize; i++)
{
sumx += hist[i].x;
sumy += hist[i].y;
}
ptLast.x = sumx / histSize;
ptLast.y = sumy / histSize;
return ptLast;
}
private:
// calculate distance between 2 point without doing a sqrt
float pDistance2(cv::Point2f &p1, cv::Point2f &p2)
{
float dx = p1.x - p2.x;
float dy = p1.y - p2.y;
return (dx * dx + dy * dy);
}
};
相关文章:
- C++,OpenCV,尝试显示图像时"OpenCV(4.3.0) Error: Assertion failed (size.width>0 && size.height>0)"此错误
- 尝试导入pybind-opencv模块时出现libgtk错误
- 在编译C++代码(具有dlib和opencv)到WASM时面临问题
- 如何使用OpenCV将RBG图像转换为HSV,并将H、S和V值保存为C++中的3个独立图像
- OpenCV EqualizeHist()从彩色图像创建黑白图像
- 如何仅为一个函数添加延迟
- 将OpenCV C++重写为EmguCV C#-如何使用指针
- OpenCV C++.快速计算混淆矩阵
- 在C++代码中包含opencv时,使用ctypes创建.so文件
- 哪些库可以通过Opencv调整曝光率
- 以在Qt中的IF语句中设置时间延迟
- 使用OpenCV延迟捕获相机框架
- 使用Kalman滤波器来filt噪声,而不会延迟OpenCV C
- 如何将 Openh264 解码帧无延迟输出格式转换为 OpenCV 矩阵
- 如何使用OpENCV解决图像处理摄像头IO延迟
- WINDOWS环境下的c++opencv应用程序的低延迟视频流
- 在OpENCV中创建摄像头进料的马赛克,但不会大大延迟
- 使用cvblobslib和opencv(c++)减少实时二进制b/w网络摄像头馈送的blob检测过程中的延迟
- openCV-网络摄像头的视频捕获-延迟问题
- OpenCV: Mobotix摄像机馈送延迟