cv::Vec3b 是 OpenCV 中用于表示彩色图像像素值的数据类型。它是一个长度为 3 的数组,每个元素都是一个 8 位无符号整数,用于表示像素的蓝色、绿色和红色通道的值。通常,它用于处理彩色图像的像素。
获取每一个点的像素值增加25点
#include
#include
#include
#include
using namespace std;
using namespace cv;
#include
#include
#include
#include
int main() {
// 读取彩色图像
cv::Mat image = cv::imread("1.png");
if (image.empty()) {
std::cerr << "Could not open or find the image!" << std::endl;
return -1;
}
// 获取图像的宽度和高度
int width = image.cols;
int height = image.rows;
// 遍历图像的每个像素
for (int y = 0; y < height; y++) {
for (int x = 0; x < width; x++) {
// 获取当前像素的颜色值
cv::Vec3b& pixel = image.at<cv::Vec3b>(y, x);
// 反转颜色(简单的方式:每个通道取反)
pixel[0] = 25 + pixel[0]; // 蓝色通道
pixel[1] = 25 + pixel[1]; // 绿色通道
pixel[2] = 25 + pixel[2]; // 红色通道
}
}
// 保存处理后的图像
cv::imwrite("output.jpg", image);
return 0;
}