码迷,mamicode.com
首页 > 编程语言 > 详细

自适应中值滤波(基于C++和OpenCV)Kinect深度图

时间:2015-04-03 09:21:24      阅读:347      评论:0      收藏:0      [点我收藏+]

标签:kinect   opencv   filter   

<span style="font-family:Microsoft YaHei;font-size:14px;">#include <opencv2/opencv.hpp>
#include <vector>
#define uint unsigned int 
using namespace cv; 

const uint rowNumber = 480;
const uint colNumber = 640;

void AutoMedianFilter(Mat src, Mat dst, uint window){
	uint d = window / 2;
	for(uint px = d; px < (rowNumber-d); ++px){
		for(uint py = d; py < (colNumber-d); ++py){
			std::vector<uchar> v;
			for(uint sx = (px-d); sx < (px+d); ++sx){
				for(uint sy = (py-d); sy < (py+d); ++sy){
					v.push_back(src.at<uchar>(sx,sy));
				}
			}

			for(uint i = 0; i < (v.size()-1); ++i){
				for(uint j = (i+1); j < v.size(); ++j){
					if(v.at(i) > v.at(j)){ uchar temp; temp = v.at(i); v.at(i) = v.at(j); v.at(j) = temp; }
				}
			}

   			if( (src.at<uchar>(px,py) == v.at((v.size()-1))) || (src.at<uchar>(px,py) == v.at(0)) ){
 				dst.at<uchar>(px,py) = v.at( (v.size() / 2) );
   			}
		}
	}
}

int main( )
{ 
	Mat image=imread("2.jpg", CV_8UC1); 

	namedWindow( "中值滤波【原图】" ); 
 	namedWindow( "中值滤波【Auto】"); 
 	namedWindow( "中值滤波【opencv】"); 

	Mat out1 = image.clone(); 
	AutoMedianFilter(image, out1, 15);

 	Mat out2;
	medianBlur(image, out2, 15);

	imshow( "中值滤波【原图】", image ); 
	imshow( "中值滤波【Auto】" ,out1 ); 
 	imshow( "中值滤波【opencv】", out2); 

	waitKey( 0 );     
	return(0);
} </span>

原图:

技术分享

自适应中值滤波:

技术分享

opencv中的中值滤波:

技术分享

自适应中值滤波(基于C++和OpenCV)Kinect深度图

标签:kinect   opencv   filter   

原文地址:http://blog.csdn.net/kh1445291129/article/details/44839733

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!