马虎结束数据结构,开始OpenCV大坑
先解释几个定义:
掩膜:http://wenku.baidu.com/view/bc1407d6b14e852458fb57cd.html
数字图像处理中,掩膜为二维数组,有时也用多值图像
通道:RGB,也就是3
位图深度:位深度指图像中每个像素可以使用的颜色信息数量,每个像素使用的位数越多,颜色就越多
例如深度为1,像素只有两种,黑色白色,位深度为8的RGB图像,每一个像素由1600万多种颜色(三个通道,每个通道
8位,也就是256^3)
像素范围处理函数saturate_cast<uchar*>()
锐化函数filter2D(src,dst,src.depth(),temp);
初始化一个与原图像大小一致的空图:Mat dst=Mat::zeros(src.size(),src.type());
复制:src.copyTo(dst);
克隆:dst=src.clone();
填充:dst=Scalar(0,0,255);//纯量的,填充//按照B,G,R顺序
创建一个规定大小的对象:Mat demo(100,100,CV_8UC3,Scalar(0,255,0));//B,G,R
<uchar>类似于类型转换吧。。。。
#include <opencv2/opencv.hpp>
#include <iostream>
using namespace std;
using namespace cv;
int main()
{
Mat src,dst;
src=imread("E:/opencv/cv_1/路飞.jpg");
if(!src.data)
{
cout<<"Failed load...";
return -1;
}
namedWindow("input");
imshow("input",src);
cout<<"通道"<<src.channels();
int cols=src.channels()*(src.cols-1);//列
int td=src.channels();
int rows=src.rows;
dst=Mat::zeros(src.size(),src.type());
/*
//方法一
for(int row=1;row<rows-1;row++)
{
uchar*previous=src.ptr<uchar>(row-1);
uchar*current=src.ptr<uchar>(row);
uchar*next=src.ptr<uchar>(row+1);
uchar*output=dst.ptr<uchar>(row);
for(int col=1;col<cols;col++)
{
output[col]=saturate_cast<uchar>(5*current[col]-(current[col]+current[col]+previous[col]+next[col]));
}
}
*/
//方法二
Mat temp=(Mat_<char>(3,3)<<0,-1,0,-1,5,-1,0,-1,0);
filter2D(src,dst,src.depth(),temp);
namedWindow("output");
imshow("output",dst);
waitKey(0);
return 0;
}
效果图:锐化的很明显的