其他分享
首页 > 其他分享> > OpenCV,图像掩膜

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;
}

执行结果:

 

标签:src,掩膜,int,current,OpenCV,图像,row,col,Mat
来源: https://blog.csdn.net/qq_51890340/article/details/122761388