本文共 1223 字,大约阅读时间需要 4 分钟。
Mat src = imread("E:\vs2015\opencvstudy\2.jpg", 1);
if (!src.data) {cout << "could not load image!" << endl;return -1;}// 灰度化处理
Mat gray_src;cvtColor(src, gray_src, CV_BGR2GRAY);// 取反处理
Mat gray_src_invert = Mat::zeros(gray_src.size(), gray_src.type());for (int row = 0; row < gray_src.rows; row++) {for (int col = 0; col < gray_src.cols; col++) {int gray_pixel = gray_src.at// 3通道取反处理
Mat dst, dst2;dst.create(src.size(), src.type());dst2.create(src.size(), src.type());for (int row = 0; row < src.rows; row++) {
for (int col = 0; col < src.cols; col++) {if (src.channels() == 1) {int gray_pixel = gray_src.at// 位操作取反
Mat bitwise_not_dst;bitwise_not(src, bitwise_not_dst);// ROI截取
Rect r(300, 300, 1000, 400);Mat smallImg = gray_src(r);cout << "gray_image height:" << gray_src.rows << endl;
cout << "gray_image width:" << gray_src.cols << endl;imshow("ROI截取图像", smallImg);
转载地址:http://mmsfk.baihongyu.com/