背景建模技术(七):预处理(PreProcessor)模块
预处理(PreProcessor)模块是BgsLibrary中一个必选的模块,是真正进入背景建模算法的“预处理”过程,其主要功能包括‘去模糊’、‘获得灰度图’、'应用Canny算子‘等可选模块。
下面给出源码:
- #include "PreProcessor.h"
- namespace bgslibrary
- {
- PreProcessor::PreProcessor() : firstTime(true), equalizeHist(false), gaussianBlur(false)
- {
- std::cout << "PreProcessor()" << std::endl;
- }
- PreProcessor::~PreProcessor()
- {
- std::cout << "~PreProcessor()" << std::endl;
- }
- void PreProcessor::setEqualizeHist(bool value)
- {
- equalizeHist = value;
- }
- void PreProcessor::setGaussianBlur(bool value)
- {
- gaussianBlur = value;
- }
- cv::Mat PreProcessor::getGrayScale()
- {
- return img_gray.clone();
- }
- void PreProcessor::process(const cv::Mat &img_input, cv::Mat &img_output)
- {
- if (img_input.empty())
- return;
- loadConfig();
- if (firstTime)
- saveConfig();
- img_input.copyTo(img_output);
- // Converts image from one color space to another
- // http://opencv.willowgarage.com/documentation/cpp/miscellaneous_image_transformations.html#cv-cvtcolor
- cv::cvtColor(img_input, img_gray, CV_BGR2GRAY);
- //img_gray.copyTo(img_output);
- // Equalizes the histogram of a grayscale image
- // http://opencv.willowgarage.com/documentation/cpp/histograms.html#cv-equalizehist
- if (equalizeHist)
- cv::equalizeHist(img_output, img_output);
- // Smoothes image using a Gaussian filter
- // http://opencv.willowgarage.com/documentation/cpp/imgproc_image_filtering.html#GaussianBlur
- if (gaussianBlur)
- cv::GaussianBlur(img_output, img_output, cv::Size(7, 7), 1.5);
- if (enableShow)
- cv::imshow("Pre Processor", img_output);
- firstTime = false;
- }
- void PreProcessor::rotate(const cv::Mat &img_input, cv::Mat &img_output, float angle)
- {
- IplImage* image = new IplImage(img_input);
- //IplImage *rotatedImage = cvCreateImage(cvSize(480,320), IPL_DEPTH_8U, image->nChannels);
- //IplImage *rotatedImage = cvCreateImage(cvSize(image->width,image->height), IPL_DEPTH_8U, image->nChannels);
- IplImage* rotatedImage = cvCreateImage(cvSize(image->height, image->width), IPL_DEPTH_8U, image->nChannels);
- CvPoint2D32f center;
- //center.x = 160;
- //center.y = 160;
- center.x = (image->height / 2);
- center.y = (image->width / 2);
- CvMat* mapMatrix = cvCreateMat(2, 3, CV_32FC1);
- cv2DRotationMatrix(center, angle, 1.0, mapMatrix);
- cvWarpAffine(image, rotatedImage, mapMatrix, CV_INTER_LINEAR + CV_WARP_FILL_OUTLIERS, cvScalarAll(0));
- cv::Mat img_rot(rotatedImage);
- img_rot.copyTo(img_output);
- cvReleaseImage(&image);
- cvReleaseImage(&rotatedImage);
- cvReleaseMat(&mapMatrix);
- }
- void PreProcessor::applyCanny(const cv::Mat &img_input, cv::Mat &img_output)
- {
- if (img_input.empty())
- return;
- //------------------------------------------------------------------
- // Canny
- // Finds edges in an image using Canny algorithm.
- // http://opencv.willowgarage.com/documentation/cpp/imgproc_feature_detection.html#cv-canny
- //------------------------------------------------------------------
- cv::Mat img_canny;
- cv::Canny(
- img_input, // image ?Single-channel 8-bit input image
- img_canny, // edges ?The output edge map. It will have the same size and the same type as image
- 100, // threshold1 ?The first threshold for the hysteresis procedure
- 200); // threshold2 ?The second threshold for the hysteresis procedure
- cv::threshold(img_canny, img_canny, 128, 255, cv::THRESH_BINARY_INV);
- img_canny.copyTo(img_output);
- }
- void PreProcessor::saveConfig()
- {
- CvFileStorage* fs = cvOpenFileStorage("./config/PreProcessor.xml", 0, CV_STORAGE_WRITE);
- cvWriteInt(fs, "equalizeHist", equalizeHist);
- cvWriteInt(fs, "gaussianBlur", gaussianBlur);
- cvWriteInt(fs, "enableShow", enableShow);
- cvReleaseFileStorage(&fs);
- }
- void PreProcessor::loadConfig()
- {
- CvFileStorage* fs = cvOpenFileStorage("./config/PreProcessor.xml", 0, CV_STORAGE_READ);
- equalizeHist = cvReadIntByName(fs, 0, "equalizeHist", false);
- gaussianBlur = cvReadIntByName(fs, 0, "gaussianBlur", false);
- enableShow = cvReadIntByName(fs, 0, "enableShow", true);
- cvReleaseFileStorage(&fs);
- }
- }
最后给出此模块的流程框架图供大家参考:
背景建模技术(七):预处理(PreProcessor)模块的更多相关文章
- 背景建模技术(三):背景减法库(BGS Library)的基本框架与入口函数main()的功能
背景减法库(BGS Library = background subtraction library)包含了37种背景建模算法,也是目前国际上关于背景建模技术研究最全也最权威的资料.本文将更加详细的介 ...
- 背景建模技术(二):BgsLibrary的框架、背景建模的37种算法性能分析、背景建模技术的挑战
背景建模技术(二):BgsLibrary的框架.背景建模的37种算法性能分析.背景建模技术的挑战 1.基于MFC的BgsLibrary软件下载 下载地址:http://download.csdn.ne ...
- 背景建模技术(六):帧处理(FrameProcessor)模块
前面几篇文章简单介绍了BgsLibrary的入口函数.视频分析和视频捕获模块,本文将简单介绍帧处理模块,即对每一帧进行处理的函数,也就是真正调用背景建模算法的接口处. 下面贴出源码供大家分析: #in ...
- 背景建模技术(五):视频捕获(VideoCapture)模块
本次对“视频捕获(VideoCapture)模块”做出分析,给出源代码和对应的程序流程框架. 视频捕获模块的主要功能是设置视频或相机参数,并读取设置配置参数,最后进入帧处理模块的process进程,该 ...
- 背景建模技术(四):视频分析(VideoAnalysis)模块
视频分析模块主要包含两个函数,一个是VideoAnalysis::setup(....),其主要功能就是确定测试的视频是视频文件或摄像头输入亦或是采用命令行参数:第二个函数是VideoAnalysis ...
- SPSS Modeler数据挖掘项目实战(数据挖掘、建模技术)
SPSS Modeler是业界极为著名的数据挖掘软件,其前身为SPSS Clementine.SPSS Modeler内置丰富的数据挖掘模型,以其强大的挖掘功能和友好的操作习惯,深受用户的喜爱和好评, ...
- 浅析软件工程中的UML建模技术
一.基本信息 标题:浅析软件工程中的UML建模技术 时间:2018 出版源:电子世界 领域分类:软件工程:UML建模技术:需求分析 二.研究背景 问题定义:软件工程中UML建模技术的研究 难点:明确软 ...
- NoSQL 数据建模技术(转)
本文转载自:http://coolshell.cn/articles/7270.html ================================================ 全文译自墙外 ...
- NoSQL数据建模技术
原文来自“NoSQL Data Modeling Techniques”,由酷壳网陈皓编译<NoSQL数据建模技术>.这篇文章看完之后,你可能会对NoSQL的数据结构会有些感觉.我的感觉是 ...
随机推荐
- 孤荷凌寒自学python第八十六天对selenium模块进行较详细的了解
孤荷凌寒自学python第八十六天对selenium模块进行较详细的了解 (今天由于文中所阐述的原因没有进行屏幕录屏,见谅) 为了能够使用selenium模块进行真正的操作,今天主要大范围搜索资料进行 ...
- 深入理解eos账户体系 active和action
在eos中,账户是一个非常重要的概念. 账户分为两部分组成 一种是active 一种是action. 智能合约本质上来讲就是一个action加上一个回馈脚本程序.任何智能合约都有这俩个部分组成. 那么 ...
- Python3 小工具-UDP扫描
from scapy.all import * import optparse import threading def scan(target,port): pkt=IP(dst=target)/U ...
- Python高级编程-多进程
要让Python程序实现多进程(multiprocessing),我们先了解操作系统的相关知识. Unix/Linux操作系统提供了一个fork()系统调用,它非常特殊.普通的函数调用,调用一次,返回 ...
- Python3 数据类型-字典
字典是一种可变数据类型,且可存储任意类型对象. 字典使用大括号"{}"括起来,由键(key)和值(values)组成,键只能使用不可变类型定义,值可以使用可变类型{'键':'值'} ...
- 基于angular+bower+glup的webapp
一:bower介绍 1:全局安装安装bower cnpm i -g bower bower常用指令: bower init //初始化文件 bower install bower uninstall ...
- Java学习个人备忘录之多线程
进程:正在进行中的程序(直译). 线程:就是进程中一个负责程序执行的控制单元(执行路径) 一个进程中可以有多个执行路径,称之为多线程. 一个进程中至少要有一个线程. 开启多个线程是为了同时运行多部分代 ...
- LintCode-211.字符串置换
字符串置换 给定两个字符串,请设计一个方法来判定其中一个字符串是否为另一个字符串的置换. 置换的意思是,通过改变顺序可以使得两个字符串相等. 样例 "abc" 为 "cb ...
- Swift-闭包理解(二)
简明扼要的闭包表达式 其实Swift已经为我们提供了很多简化的语法,可以让我们保证代码的高可读性和维护性.还用上面的例子来说明,对于 greetPeople 这个全局函数来说,其实只需要使用一次,所 ...
- matlab的二维卷积操作(转)
MATLAB的conv2函数实现步骤(conv2(A,B)): 其中,矩阵A和B的尺寸分别为ma*na即mb*nb ① 对矩阵A补零,第一行之前和最后一行之后都补mb-1行,第一列之前和最后一列之后都 ...