算法集合:https://code.google.com/p/bgslibrary/

测试:AdaptiveBackgroundLearning算法

#include <iostream>
#include <opencv/highgui.h>
#include <opencv/cv.h>
#include "AdaptiveBackgroundLearning.h" int main(int argc, char **argv)
{
CvCapture *capture = 0;
int resize_factor = 100; if(argc > 1)
{
std::cout << "Openning: " << argv[1] << std::endl;
capture = cvCaptureFromAVI(argv[1]);
}
else
{
capture = cvCaptureFromCAM(0);
resize_factor = 50; // set size = 50% of original image
} if(!capture)
{
std::cerr << "Cannot initialize video!" << std::endl;
return 1;
} IplImage *frame_aux = cvQueryFrame(capture);
IplImage *frame = cvCreateImage(cvSize((int)((frame_aux->width*resize_factor)/100) , (int)((frame_aux->height*resize_factor)/100)), frame_aux->depth, frame_aux->nChannels);
cvResize(frame_aux, frame); /* Background Subtraction Methods */ /*** Default Package ***/
//bgs = new FrameDifferenceBGS;
//bgs = new StaticFrameDifferenceBGS;
//bgs = new WeightedMovingMeanBGS;
//bgs = new WeightedMovingVarianceBGS;
//bgs = new MixtureOfGaussianV2BGS;
//bgs = new MixtureOfGaussianV2BGS;
//bgs = new AdaptiveBackgroundLearning;
IBGS *bgs;
bgs= new AdaptiveBackgroundLearning; /*** DP Package (adapted from Donovan Parks) ***/
//bgs = new DPAdaptiveMedianBGS;
//bgs = new DPGrimsonGMMBGS;
//bgs = new DPZivkovicAGMMBGS;
//bgs = new DPMeanBGS;
//bgs = new DPWrenGABGS;
//bgs = new DPPratiMediodBGS;
//bgs = new DPEigenbackgroundBGS;
//bgs = new DPTextureBGS; /*** TB Package (adapted from Thierry Bouwmans) ***/
//bgs = new T2FGMM_UM;
//bgs = new T2FGMM_UV;
//bgs = new T2FMRF_UM;
//bgs = new T2FMRF_UV;
//bgs = new FuzzySugenoIntegral;
//bgs = new FuzzyChoquetIntegral; /*** JMO Package (adapted from Jean-Marc Odobez) ***/
//bgs = new MultiLayerBGS; /*** PT Package (adapted from Hofmann) ***/
//bgs = new PixelBasedAdaptiveSegmenter; /*** LB Package (adapted from Laurence Bender) ***/
//bgs = new LBSimpleGaussian;
//bgs = new LBFuzzyGaussian;
//bgs = new LBMixtureOfGaussians;
//bgs = new LBAdaptiveSOM;
//bgs = new LBFuzzyAdaptiveSOM; /*** LBP-MRF Package (adapted from Csaba Kertész) ***/
//bgs = new LbpMrf; /*** AV Package (adapted from Antoine Vacavant) ***/
//bgs = new VuMeter; /*** EG Package (adapted from Ahmed Elgammal) ***/
//bgs = new KDE; int key = 0;
while(key != 'q')
{
frame_aux = cvQueryFrame(capture);
if(!frame_aux) break; cvResize(frame_aux, frame); cv::Mat img_input(frame);
cv::imshow("input", img_input); cv::Mat img_mask;
cv::Mat img_bkgmodel;
bgs->process(img_input, img_mask, img_bkgmodel); // automatically shows the foreground mask image
//imshow("img_mask",img_mask);
//imshow("img_bkgmodel",img_bkgmodel);
if(!img_mask.empty())
imshow("img_mask",img_mask);
// do something key = cvWaitKey(33);
} delete bgs; cvDestroyAllWindows();
cvReleaseCapture(&capture); return 0;
}

配置文件background.vcxproj

<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug|Win32">
<Configuration>Debug</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|Win32">
<Configuration>Release</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
</ItemGroup>
<ItemGroup>
<ClCompile Include="AdaptiveBackgroundLearning.cpp" />
<ClCompile Include="GMG.cpp" />
<ClCompile Include="main4.cpp" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="AdaptiveBackgroundLearning.h" />
<ClInclude Include="GMG.h" />
<ClInclude Include="IBGS.h" />
</ItemGroup>
<PropertyGroup Label="Globals">
<ProjectGuid>{C9F9AAD6-4C2A-414F-ADBE-891F28F9E32F}</ProjectGuid>
<Keyword>Win32Proj</Keyword>
<RootNamespace>background</RootNamespace>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<CharacterSet>Unicode</CharacterSet>
<UseOfMfc>false</UseOfMfc>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
<Import Project="opencv_d.props" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<PropertyGroup Label="UserMacros" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<LinkIncremental>true</LinkIncremental>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<LinkIncremental>false</LinkIncremental>
</PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<ClCompile>
<PrecompiledHeader>
</PrecompiledHeader>
<WarningLevel>Level3</WarningLevel>
<Optimization>Disabled</Optimization>
<PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
<AdditionalLibraryDirectories>%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
<AdditionalDependencies>%(AdditionalDependencies)</AdditionalDependencies>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<PrecompiledHeader>
</PrecompiledHeader>
<Optimization>MaxSpeed</Optimization>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
</Link>
</ItemDefinitionGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
</Project>

 注意:在可执行文件下要有config文件夹

 效果如下:

1,摄像头

2,视频文件

opencv2.4.4 背景减除算法收集的更多相关文章

  1. 【计算机视觉】基于样本一致性的背景减除运动目标检测算法(SACON)

    SACON(SAmple CONsensus)算法是基于样本一致性的运动目标检测算法.该算法通过对每个像素进行样本一致性判断来判定像素是否为背景. 算法框架图 由上图可知,该算法主要分为四个主要部分, ...

  2. PHP 经典有趣的算法收集(面试题)

    1.一群猴子排成一圈,按1,2,…,n依次编号.然后从第1只开始数,数到第m只,把它踢出圈,从它后面再开始数,再数到第m只,在把它踢出去…,如此不停的进行下去,直到最后只剩下一只猴子为止,那只猴子就叫 ...

  3. 【计算机视觉】背景建模--Vibe 算法优缺点分析

    一.Vibe 算法的优点 Vibe背景建模为运动目标检测研究邻域开拓了新思路,是一种新颖.快速及有效的运动目标检测算法.其优点有以下两点: 1.思想简单,易于实现.Vibe通常随机选取邻域20个样本为 ...

  4. 基于SNMP的路由拓扑发现算法收集

    一.三层(网络层)发现 算法来源:王娟娟.基于SNMP的网络拓扑发现算法研究.武汉科技大学硕士学位论文,2008 数据结构: 待检路由设备网关链表:存放指定深度内待检路由设备的网关信息,处理后删除. ...

  5. js-数组算法收集版(转)

    不管是在面试中还是在笔试中,我们都会被经常问到关于javascript数组的一些算法,比方说数组去重.数组求交集.数组扰乱等等.今天抽点时间把javascript中的一些常用的数组算法做一下总结,以方 ...

  6. 数据结构 + 算法 -> 收集

    董的博客:数据机构与算法合集 背包问题应用(2011-08-26) 数据结构之红黑树(2011-08-20) 素数判定算法(2011-06-26) 算法之图搜索算法(一)(2011-06-22) 算法 ...

  7. 减治算法之寻找第K小元素问题

    一.问题描写叙述 给定一个整数数列,寻找其按递增排序后的第k个位置上的元素. 二.问题分析 借助类似快排思想实现pation函数.再利用递归思想寻找k位置. 三.算法代码 public static ...

  8. asp中的md5/sha1/sha256算法收集

    对于asp这种古董级的技术,这年头想找一些有用的资料已经不容易了,下面是一些常用的加密算法: md5 (将以下代码另存为md5.inc) <% Private Const BITS_TO_A_B ...

  9. Scala 大数据 常用算法收集

    一:IP转数字,用于比大小,用在求IP段范围中 def ip2Long(ip: String): Long = { val fragments = ip.split("[.]") ...

随机推荐

  1. kill 进程卡住,超时kill方法

    还是有漏洞 ,万一 working.py未超时, kill_job.sh 会不会杀死别人的进程啊start.sh#!/bin/bash python working.py &python wo ...

  2. win8连接蓝牙听歌

    今天买了一个蓝牙耳机,琢磨着在win8.1上听一下,可是折腾了一阵时间,现在把最佳配置方式写出来,希望对朋友有所帮助 确保win8的蓝牙驱动已经安装完毕,并且开启蓝牙,win8,设置--右下角更改电脑 ...

  3. Android支付接入(一):支付宝

    原地址:http://blog.csdn.net/simdanfeg/article/details/9011603 转载之前我想深深地感谢屌丝哥 相信相同过App获取利润的都会需要接入计费SDK,下 ...

  4. 国外程序员整理的 C++ 资源大全

    摘要:C++是在C语言的基础上开发的一种集面向对象编程.泛型编程和过程化编程于一体的编程语言.应用较为广泛,是一种静态数据类型检查的,支持多重编程的通用程序设计语言. 关于 C++ 框架.库和资源的一 ...

  5. (转)eclipse快捷键

    Eclipse常用快捷键 Eclipse的编辑功能非常强大,掌握了Eclipse快捷键功能,能够大大提高开发效率.Eclipse中有如下一些和编辑相关的快捷键. 1. [ALT+/] 此快捷键为用户编 ...

  6. BZOJ 2553 禁忌

    首先我们要考虑给定一个串,如何将他划分,使得他有最多的禁忌串 我们只需要按里面出现的禁忌串们的出现的右端点排序然后贪心就可以啦 我们建出AC自动机,在AC自动机等价于走到一个包含禁忌串的节点就划分出一 ...

  7. codeforces #305 A Mike and Frog

    挺简单的题目,但是有一堆恶心的边界 在刨去恶心的边界之后: 假定我们知道两边的循环节为b1,b2 其中h第一次到达目标的时间为a1,a2 又知道对于答案t t=a1+b1*t1=a2+b2*t2 不妨 ...

  8. [译]C++书籍终极推荐

    转载声明: 翻译仅以技术学习和交流为目的,如需转载请务必标明原帖链接. 来源:http://stackoverflow.com/questions/388242/the-definitive-c-bo ...

  9. 选择Android还是选择JavaEE?

    很多同学咨询过同样的一个问题,该问题也是最备受争议的问题,那就是到底是选择Android还是选择JavaEE.下面发表一些本人的看法.       Android属于一个特有的Java技术应用,专注于 ...

  10. HDU4857——逃生(反向建图+拓扑排序)(BestCoder Round #1)

    逃生 Description 糟糕的事情发生啦,现在大家都忙着逃命.但是逃命的通道很窄,大家只能排成一行. 现在有n个人,从1标号到n.同时有一些奇怪的约束条件,每个都形如:a必须在b之前.同时,社会 ...