zl程序教程

您现在的位置是:首页 >  工具

当前栏目

背景建模技术(七):预处理(PreProcessor)模块

2023-09-14 08:57:58 时间
p br /p p 预处理(PreProcessor)模块是BgsLibrary中一个必选的模块,是真正进入背景建模算法的“预处理”过程,其主要功能包括‘去模糊’、‘获得灰度图’、 应用Canny算子‘等可选模块。 /p p br /p p 下面给出源码: /p p br /p p /p pre name= code >

预处理(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);

最后给出此模块的流程框架图供大家参考:






3D激光SLAM:A-LOAM :前端lidar点预处理部分代码解读 A-LOAM的cpp有四个,其中 kittiHelper.cpp 的作用是将kitti数据集转为rosbag 剩下的三个是作为 slam 的 部分,分别是: - laserMappin.cpp ++++ 当前帧到地图的优化 - laserOdometry.cpp ++++ 帧间里程计 - scanRegistration.cpp ++++ 前端lidar点预处理及特征提取
激光SLAM:ALOAM---后端laserMapping代码结构与数据处理分析 ALOAM方法实现了低的漂移,并且计算的复杂度低,实时性很好.并且不需要高精度的lidar和惯导 这个方法的核心思想就是把SLAM问题进行了拆分,通过两个算法来进行.一个是执行高频率的**前端里程计**但是低精度的运动估计(定位),另一个算法在比定位低一个数量级的频率执行**后端建图**(建图和校正里程计). 这个两个算法都需要提特征点,就是经典的角点和面点,然后进行配准.在前端的那个算法中也就是里程计算法,特征点的提取会用到快速计算的方法.在建图的后端算法中,相互关联的特征点是通过特征值和特征向量来获得的.
带你玩转 3D 检测和分割(一):MMDetection3D 整体框架介绍 由于 3D 本身数据的复杂性和 MMDetection3D 支持任务(点云 3D 检测、单目 3D 检测、多模态 3D 检测和点云 3D 语义分割等)和场景(室内和室外)的多样性,整个框架结构相对复杂,新人用户的上手门槛相对较高。所以我们推出新的系列文章,让各个细分方向的用户都能轻松上手 MMDetection3D,基于框架进行自己的研究和开发。在系列文章的初期,我们会先带大家了解整个框架的设计流程,分析框架中的各种核心组件,介绍数据集的处理方法,然后再对各个细分任务及经典模型进行具体细节的代码层级介绍。