• 大小: 1.01MB
    文件类型: .rar
    金币: 1
    下载: 0 次
    发布日期: 2023-08-29
  • 语言: 其他
  • 标签: opencv  

资源简介

建立在opencv上的粒子滤波目标跟踪,实现的效果还不错,大家有空可以看下,有什么不足就指出,修改下。

资源截图

代码片段和文件信息

/************************************************************************/
/* 
Description: 基本的粒子滤波目标跟踪
Author: Yang Xian
Email: yang_xian521@163.com
Version: 2011-11-2
History:
*/
/************************************************************************/
#include  // for standard I/O
#include    // for strings
#include   // for controlling float print precision
#include   // string to number conversion

#include   
#include         // Basic OpenCV structures (cv::Mat Scalar)
#include   // OpenCV window I/O

using namespace cv;
using namespace std;

// 以下这些参数对结果影响很大,而且也会根据视频内容,会对结果有很大的影响
const int PARTICLE_NUM = 25; // 粒子个数
// 粒子放入的相关区域
const double A1 = 2.0;
const double A2 = -1.0;
const double B0 = 1.0;
// 高斯随机数sigma参数
const double SIGMA_X = 1.0;
const double SIGMA_Y = 0.5;
const double SIGMA_SCALE = 0.001;

// 粒子结构体
typedef struct particle {
double x; // 当前x坐标
double y; // 当前y坐标
double scale; // 窗口比例系数
double xPre; // x坐标预测位置
double yPre; // y坐标预测位置
double scalePre; // 窗口预测比例系数
double xOri; // 原始x坐标
double yOri; // 原始y坐标
//  int width; // 原始区域宽度
//  int height; // 原始区域高度
Rect rect; // 原始区域大小
MatND hist; // 粒子区域的特征直方图
double weight; // 该粒子的权重
} PARTICLE;

Mat hsv; // hsv色彩空间的输入图像
Mat roiImage; // 目标区域
MatND roiHist; // 目标区域直方图
Mat img; // 输出的目标图像
PARTICLE particles[PARTICLE_NUM]; // 粒子

int nframeNum = 0;

bool bSelectobject = false; // 区域选择标志
bool bTracking = false; // 开始跟踪标志
Point origin; // 鼠标按下时的点位置
Rect selection;// 感兴趣的区域大小

// 直方图相关参数,特征的选取也会对结果影响巨大
// Quantize the hue to 30 levels
// and the saturation to 32 levels
// value to 10 levels
int hbins = 180 sbins = 256 vbin = 10;
int histSize[] = {hbins sbins vbin};
// hue varies from 0 to 179 see cvtColor
float hranges[] = { 0 180 };
// saturation varies from 0 (black-gray-white) to 255 (pure spectrum color)
float sranges[] = { 0 256 };
// value varies from 0 (black-gray-white) to 255 (pure spectrum color)
float vranges[] = { 0 256 };
const float* ranges[] = {hranges sranges vranges};
// we compute the histogram from the 0-th and 1-st channels
int channels[] = {0 1 2};

// 鼠标响应函数,得到选择的区域,保存在selection
void onMouse(int event int x int y int void*)
{
if( bSelectobject )
{
selection.x = MIN(x origin.x);
selection.y = MIN(y origin.y);
selection.width = std::abs(x - origin.x);
selection.height = std::abs(y - origin.y);

selection &= Rect(0 0 img.cols img.rows);
}

switch (event)
{
case CV_EVENT_LBUTTONDOWN:
origin = Point(xy);
selection = Rect(xy00);
bSelectobject = true;
bTracking = false;
break;
case CV_EVENT_LBUTTONUP:
bSelectobject = false;
bTracking = true;
nframeNum = 0;
break;
}
}

// 快速排序算法排序函数
int particle_cmp(const void* p1const void* p2)
{
PARTICLE* _p1 = (PARTICLE*)p1;
PA

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----

     文件      57856  2011-11-04 20:30  particleFilterTrackingTest\Debug\particleFilterTrackingTest.exe

     文件     404684  2011-11-04 20:30  particleFilterTrackingTest\Debug\particleFilterTrackingTest.ilk

     文件     846848  2011-11-04 20:30  particleFilterTrackingTest\Debug\particleFilterTrackingTest.pdb

     文件       6834  2011-11-04 20:30  particleFilterTrackingTest\particleFilterTrackingTest\Debug\BuildLog.htm

     文件     103289  2011-11-04 20:30  particleFilterTrackingTest\particleFilterTrackingTest\Debug\main.obj

     文件         67  2011-11-04 20:30  particleFilterTrackingTest\particleFilterTrackingTest\Debug\mt.dep

     文件        621  2011-11-04 20:30  particleFilterTrackingTest\particleFilterTrackingTest\Debug\particleFilterTrackingTest.exe.intermediate.manifest

     文件     338944  2011-11-04 20:30  particleFilterTrackingTest\particleFilterTrackingTest\Debug\vc90.idb

     文件     495616  2011-11-04 20:30  particleFilterTrackingTest\particleFilterTrackingTest\Debug\vc90.pdb

     文件       9464  2011-11-04 20:30  particleFilterTrackingTest\particleFilterTrackingTest\main.cpp

     文件       3774  2011-11-02 14:53  particleFilterTrackingTest\particleFilterTrackingTest\particleFilterTrackingTest.vcproj

     文件       1423  2011-11-04 20:35  particleFilterTrackingTest\particleFilterTrackingTest\particleFilterTrackingTest.vcproj.HP98402794308.Administrator.user

     文件    2845696  2011-11-04 20:35  particleFilterTrackingTest\particleFilterTrackingTest.ncb

     文件        944  2011-11-02 13:34  particleFilterTrackingTest\particleFilterTrackingTest.sln

    ..A..H.     11264  2011-11-04 20:35  particleFilterTrackingTest\particleFilterTrackingTest.suo

     目录          0  2011-11-04 20:30  particleFilterTrackingTest\particleFilterTrackingTest\Debug

     目录          0  2011-11-04 20:30  particleFilterTrackingTest\Debug

     目录          0  2011-11-04 20:30  particleFilterTrackingTest\particleFilterTrackingTest

     目录          0  2011-11-02 14:53  particleFilterTrackingTest

     文件         19  2012-10-01 22:23  www.opencvchina.com.txt

----------- ---------  ---------- -----  ----

              5127343                    20


评论

共有 条评论