圖像濾波在opencv中可以有多種實(shí)現(xiàn)形式
創(chuàng)新互聯(lián)主要從事網(wǎng)站建設(shè)、成都網(wǎng)站制作、網(wǎng)頁設(shè)計(jì)、企業(yè)做網(wǎng)站、公司建網(wǎng)站等業(yè)務(wù)。立足成都服務(wù)西青,十載網(wǎng)站建設(shè)經(jīng)驗(yàn),價(jià)格優(yōu)惠、服務(wù)專業(yè),歡迎來電咨詢建站服務(wù):13518219792
自定義濾波
如使用3×3的掩模:
對(duì)圖像進(jìn)行處理.
使用函數(shù)filter2D()實(shí)現(xiàn)
#include<opencv2/opencv.hpp> using namespace cv; int main() { //函數(shù)調(diào)用filter2D功能 Mat src,dst; src = imread("E:/image/image/daibola.jpg"); if(!src.data) { printf("can not load image \n"); return -1; } namedWindow("input", CV_WINDOW_AUTOSIZE); imshow("input", src); src.copyTo(dst); Mat kernel = (Mat_<int>(3,3)<<1,1,1,1,1,-1,-1,-1,-1); double t = (double)getTickCount(); filter2D(src, dst, src.depth(), kernel); std::cout<<((double)getTickCount()-t)/getTickFrequency()<<std::endl; namedWindow("output", CV_WINDOW_AUTOSIZE); imshow("output", dst); printf("%d",src.channels()); waitKey(); return 0; }
通過像素點(diǎn)操作實(shí)現(xiàn)
#include<opencv2/opencv.hpp> using namespace cv; int main() { Mat src, dst; src = imread("E:/image/image/daibola.jpg"); CV_Assert(src.depth() == CV_8U); if(!src.data) { printf("can not load image \n"); return -1; } namedWindow("input", CV_WINDOW_AUTOSIZE); imshow("input",src); src.copyTo(dst); for(int row = 1; row<(src.rows - 1); row++) { const uchar* previous = src.ptr<uchar>(row - 1); const uchar* current = src.ptr<uchar>(row); const uchar* next = src.ptr<uchar>(row + 1); uchar* output = dst.ptr<uchar>(row); for(int col = src.channels(); col < (src.cols - 1)*src.channels(); col++) { *output = saturate_cast<uchar>(1 * current[col] + previous[col] - next[col] + current[col - src.channels()] - current[col + src.channels()]); output++; } } namedWindow("output", CV_WINDOW_AUTOSIZE); imshow("output",dst); waitKey(); return 0; }
特定形式濾波
常用的有:
blur(src,dst,Size(5,5));均值濾波
GaussianBlur(src,dst,Size(5,5),11,11);高斯濾波
medianBlur(src,dst,5);中值濾波(應(yīng)對(duì)椒鹽噪聲)
bilateralFilter(src,dst,2,0.5,2,4);雙邊濾波(保留邊緣)
#include<opencv2/opencv.hpp> using namespace cv; int main() { Mat src, dst; src = imread("E:/image/image/daibola.jpg"); CV_Assert(src.depth() == CV_8U); if(!src.data) { printf("can not load image \n"); return -1; } namedWindow("input", CV_WINDOW_AUTOSIZE); imshow("input",src); src.copyTo(dst); //均值濾波 blur(src,dst,Size(5,5)); //中值濾波 //medianBlur(src,dst,5); namedWindow("output", CV_WINDOW_AUTOSIZE); imshow("output",dst); waitKey(); return 0; }
以上這篇opencv3/C++圖像濾波實(shí)現(xiàn)方式就是小編分享給大家的全部內(nèi)容了,希望能給大家一個(gè)參考,也希望大家多多支持創(chuàng)新互聯(lián)。
分享題目:opencv3/C++圖像濾波實(shí)現(xiàn)方式
網(wǎng)站地址:http://chinadenli.net/article36/geoesg.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供營銷型網(wǎng)站建設(shè)、做網(wǎng)站、網(wǎng)站建設(shè)、、靜態(tài)網(wǎng)站、響應(yīng)式網(wǎng)站
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場,如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)