一、学习内容
1. 通过指针,操作图像内容
uchar* output_row = output.ptr<uchar>(row);
output_row[col] = 5 * current_row[col] - (current_row[col-offset] + current_row[col + offset]+ previous_row[col]+ next_row[col]);
2. 获取图像的通道数、宽度cols、高度rows
int offset = src.channels();
int cols = src.cols * src.channels();//获取图像的实际总列数cols = 图像列数 * 图像通道数(例如,RGB图像的通道数是3)
int rows = src.rows;
3. Mat 初始化一个空图像数据
Mat output = Mat::zeros(src.size(), src.type());
4. 计算用时
double t = getTickCount();//计算用时
double time_cost = (getTickCount() - t) / getTickFrequency();
5. 调用函数filter2D
filter2D(src, output, src.depth(), kernel);
二、代码调试
#include <opencv2/opencv.hpp>
#include <iostream>
#include <math.h>
using namespace cv;
int main(int argc, char** argv) {
Mat src &#