算法集合: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. 在工程中添加pch文件

    在Xcode6之前,新建一个工程的时候,系统会帮我们自动新建一个以工程名为名字的pch (precompile header)文件,在开发过程中,可以将那些整个工程都广泛使用的头文件包含在该文件下,编 ...

  2. shell复习---文件解压命令

    需要自己部署服务端,故在申请了空间之后,需要自己安装linux自己,自己安装Apache等,所以下载的压缩文件需要运行.网上找了一些解压命令不对,特别试了下面的方法有效,特别记录一下: 用ssh 登陆 ...

  3. mysql分表与分区表

    mysql分表与分区表 转自:http://blog.51yip.com/mysql/949.html   一,什么是mysql分表,分区 什么是分表,从表面意思上看呢,就是把一张表分成N多个小表,具 ...

  4. 浅谈Javascript 数组与字典

    Javascript 的数组Array,既是一个数组,也是一个字典(Dictionary). 先举例看看数组的用法. var a = new Array();  a[0] = "Acer&q ...

  5. 用printf做彩色日志记录

    写了一个简单的程序,但是考虑到有一些信息是需要打印在控制台上的,就像在windows上启动apache tomcat时控制台显示的信息一样.琢磨一会儿之后,对printf进行了封装,支持控制台打印日志 ...

  6. HDU4756+Prim

    题意简单:去掉最小生成树的某一条边并补上一条,求MaxVal 思路:贪心(借鉴Yamidie的思路...) 分别求出最小生成树和次最小生成树,再在这两棵树上求最小生成树 #include<std ...

  7. hdu 4672 Present Day, Present Time 博弈论

    看了解题报告才知道怎么做!! 题意:有 N 堆石子和 M 个石子回收站,每回合操作的人可以选择一堆石子,从中拿出一些 放到石子回收站里(可以放进多个回收站,每个回收站可以使用无数次),但每个石子回收站 ...

  8. hdu 3864 D_num

    思路:给一个数n,是否只有4个约数(包括1),也就是找3个大于1的约数. 而任何一个数都可由质数表示,所以对于给定的数,只需要进行质因数分解.这里有 2种情况:如果有3个一样的质因数,则满足条件:否则 ...

  9. 嵌入式开发之NorFlash 和NandFlash

    http://blog.csdn.net/tigerjibo/article/details/9322035 [摘要]:作为一个嵌入式工程师,要对NorFlash 和NandFlash要有最起码的认知 ...

  10. 每个QWidget都有contentsMargins函数,善用QMargins

    m_pSearchLineEdit = new QLineEdit(); QPushButton *pSearchButton = new QPushButton(this); pSearchButt ...