OpenCV,图像掩膜

 程序代码

#include <opencv2/opencv.hpp>
#include <iostream>
#include <opencv2/core/utils/logger.hpp>

using namespace std;
using namespace cv;

int main(int argc, const char** argv)
{
	setLogLevel(utils::logging::LOG_LEVEL_SILENT);	//设置日志输出

	Mat src = imread("E:/picture/9.jpg");
	Mat dst = Mat::zeros(src.size(), src.type());
	if (src.empty())
	{
		cout << "could not find picture" << endl;
		return -1;
	}
	
	//int cols = (src.cols - 1) * src.channels();
	//int rows = src.rows;
	//int offsetx = src.channels();
	//for (int row = 1; row < (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 = offsetx; col < cols; col++)
	//	{
	//		output[col] = saturate_cast<uchar>(5 * current[col] - (current[col] - offsetx + current[col + offsetx]
	//			+ previous[col] + next[col]));
	//	}
	//}
	double t1 = getTickCount();
	Mat kernel = (Mat_<char>(3, 3) << 0, -1, 0, -1, 5, -1, 0, -1, 0);
	filter2D(src, dst, src.depth(), kernel);
	imshow("input", src);
	imshow("output", dst);
	double t2 = (getTickCount() - t1) / getTickFrequency();
	cout << "Time=" << t2 << "\n";
	waitKey(0);
	destroyAllWindows();
	return 0;
}

执行结果:

OpenCV,图像掩膜

 

上一篇:自定义包的目录结构、go install 和 go test


下一篇:13.图像金字塔——上下采样、高斯不同