当前位置:首页 > 编程笔记 > 正文
已解决

c++图片取出每一个像素的值

来自网友在路上 164864提问 提问时间:2023-09-28 03:55:33阅读次数: 64

最佳答案 问答题库648位专家为你答疑解惑

图片取出每一个像素的值

cv::Vec3b 是 OpenCV 中用于表示彩色图像像素值的数据类型。它是一个长度为 3 的数组,每个元素都是一个 8 位无符号整数,用于表示像素的蓝色、绿色和红色通道的值。通常,它用于处理彩色图像的像素。

获取每一个点的像素值增加25点

#include <opencv2/opencv.hpp>
#include <iostream>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/imgproc/imgproc.hpp>using namespace std;
using namespace cv;
#include <iostream>
#include <fstream>#include <opencv2/opencv.hpp>#include <opencv2/opencv.hpp>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;
}
查看全文

99%的人还看了

猜你感兴趣

版权申明

本文"c++图片取出每一个像素的值":http://eshow365.cn/6-15005-0.html 内容来自互联网,请自行判断内容的正确性。如有侵权请联系我们,立即删除!