zoukankan      html  css  js  c++  java
  • opencv2.4.4 背景减除算法收集

    算法集合: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,视频文件

    本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。
  • 相关阅读:
    web自动化搞定文件上传
    App自动化08-Android SDK目录架构详解
    App自动化07-Appium日志分析,深入剖析 Appium 实现原理
    App自动化06-adb常见连接问题整理
    crontab 定时任务
    谷歌对华为断供了,那自动化测试还做吗?
    Fiddler 抓取 https 请求大全
    App自动化05-adb
    App自动化04-Inspector检查器启动QQ测试
    (转载)边缘计算与深度学习综述
  • 原文地址:https://www.cnblogs.com/yuliyang/p/3347609.html
Copyright © 2011-2022 走看看