采用 CAMSHIFT 算法快速跟踪和检测运动目标的 C/C++ 源代码

    在实现运动目标的跟踪的过程中,发现网上流传很广的一段跟踪与检测源代码,大家可以在各个网站上都找到其踪影。为了方便查阅和参考,特转发如下:

    因为转发地址不可考,就在此先谢谢提供最初版本的前辈。

 


 

    采用 CAMSHIFT 算法快速跟踪和检测运动目标的 C/C++ 源代码,OPENCV BETA 4.0 版本在其 SAMPLE 中给出了这个例子。算法的简单描述如下(英文):

    This application demonstrates a fast, simple color tracking algorithm that can be used to track faces, hands . The CAMSHIFT algorithm is a modification of the Meanshift algorithm which is a robust statistical method of finding the mode (top) of a probability distribution. Both CAMSHIFT and Meanshift algorithms exist in the library. While it is a very fast and simple method of tracking, because CAMSHIFT tracks the center and size of the probability distribution of an object, it is only as good as the probability distribution that you produce for the object. Typically the probability distribution is derived from color via a histogram, although it could be produced from correlation, recognition scores or bolstered by frame differencing or motion detection schemes, or joint probabilities of different colors/motions etc. 
    In this application, we use only the most simplistic approach: A 1-D Hue histogram is sampled from the object in an HSV color space version of the image. To produce the probability image to track, histogram "back projection" (we replace image pixels by their histogram hue value) is used.

    算法的详细情况,请看论文:

    http://www.assuredigit.com/incoming/camshift.pdf

    该运行文件在VC6.0环境下编译通过,是一个 stand-alone 运行程序,不需要OPENCVDLL库支持。在运行之前,请先连接好USB接口的摄像头。然后可以用鼠标选定欲跟踪目标。

 

 

    笔者在VC6.0中,代码通过编译,可以正常使用。但是如果将该代码转换到MFC中,则会出现,cvSetMouseCallback()函数不断报错的情况出现。笔者在网上搜索解决方法,高手们的建议,一个方向是:用MFC自行提供的消息机制,但是如何使用,并没有说。一个方向是:将该函数在声明的时候定义为static类型。但是解决方法回复为,即使定义后,仍然无法解决该问题。笔者查阅了大量的网页,还有侯俊杰老师的《深入浅出MFC,解决了该问题,可以使程序在MFC中正常运行。

    方法比较简单,希望,懂得如何利用MFC消息机制的高手,提点一二

    具体解决方法,见下篇文章

 

 

 

 

  • 0
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 6
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 6
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值