超详细opencv掩膜操作,看不懂算我输:
另外附上一篇博文,此博文当时算是解决我老大问题了!
掩膜图像对通道的理解
#include<opencv2/opencv.hpp>
#include<iostream>
#include<math.h>
using namespace cv;
int main(int argc, char** argv)
{
Mat src, dst,t;
src = imread("D:/PT/yun.jpg");
double scale = 0.5;
Size dsize = Size(src.cols * scale, src.rows * scale);
Mat src2 = Mat(dsize, CV_32S);
resize(src, src2, dsize);
CV_Assert(src2.depth() == CV_8U);
if (!src2.data)
{
printf("could not load image...\n");
return -1;
}
namedWindow("Example1", WINDOW_AUTOSIZE);
imshow("Example1", src2);
int offsetx = src2.channels();
int cols = (src2.cols-1) * offsetx;
int rows = src2.rows;
dst = Mat::zeros(src2.size(), src2.type());
for (int row = 1; row < (rows - 1); row++) {
const uchar* previous = src2.ptr<uchar>(row - 1);
const uchar * current = src2.ptr<uchar>(row);
const uchar * next = src2.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]));
}
}
namedWindow("Example2", WINDOW_AUTOSIZE);
imshow("Example2", dst);
waitKey(0);
return 0;
}
|