背景建模技术(七):预处理(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的数据结构会有些感觉.我的感觉是 ...
随机推荐
- TPO-10 C2 Return a literature book
TPO-10 C2 Return a literature book 第 1 段 1.Listen to a conversation between a student and an employe ...
- (python)leetcode刷题笔记 01 TWO SUM
1. Two Sum Given an array of integers, return indices of the two numbers such that they add up to a ...
- python函数学习之装饰器
装饰器 装饰器的本质是一个python函数,它的作用是在不对原函数做任何修改的同时,给函数添加一定的功能.装饰器的返回值也是一个函数对象. 分类: 1.不带参数的装饰器函数: def wrapper( ...
- js经典试题之运算符的优先级
js经典试题之运算符 1.假设val已经声明,可定义为任何值.则下面js代码有可能输出的结果为: console.log('Value is ' + (val != '0') ? 'define' : ...
- Generating a PDF in Codeigniter using mPDF
https://arjunphp.com/generating-a-pdf-in-codeigniter-using-mpdf/
- kmeans算法理解及代码实现
github:kmeans代码实现1.kmeans代码实现2(包含二分k-means) 本文算法均使用python3实现 1 聚类算法 对于"监督学习"(supervised ...
- TCP系列13—重传—3、协议中RTO计算和RTO定时器维护
从上一篇示例中我们可以看到在TCP中有一个重要的过程就是决定何时进行超时重传,也就是RTO的计算更新.由于网络状况可能会受到路由变化.网络负载等因素的影响,因此RTO也必须跟随网络状况动态更新.如果T ...
- 软工网络15团队作业4——Alpha阶段敏捷冲刺-2
一.当天站立式会议照片: 二.项目进展 昨天已完成的工作: 微信公众号平台注册"小程序"的账号; 下载微信官方的小程序开发工具,这个是编辑小程序和上传审核小程序必须的工具; 大家一 ...
- 原生js操作Dom节点:CRUD
知识点,依然会遗忘.我在思考到底是什么原因.想到研究生考试准备的那段岁月,想到知识体系的建立,知识体系分为正向知识体系和逆向知识体系:正向知识体系可以理解为教科书目录,逆向知识体系可以理解考试真题. ...
- 异步请求Python库 grequests的应用和与requests库的响应速度的比较
requests库是python一个优秀的HTTP库,使用它可以非常简单地执行HTTP的各种操作,例如GET.POST等.不过,这个库所执行的网络请求都是同步了,即cpu发出请求指令后,IO执行发送和 ...