以下使用 img * 5; 将每一个像素的RGB值都乘以5.
最后打印来验证结果。
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <fcntl.h>
#include <sys/ioctl.h>
#include <linux/videodev2.h>
#include <string.h>
#include <sys/mman.h>
#include <assert.h>
#include <opencv2/opencv.hpp>
#include <opencv2/core.hpp>
#include <opencv2/imgcodecs.hpp>
#include <opencv2/highgui.hpp>
using namespace std;
using namespace cv;
typedef cv::Point3_<uint8_t> Pixel;
int main() {
Mat img(20, 20, CV_8UC3, Scalar(1, 1, 50));
Mat tmp2 = img * 5;
for (Pixel p : cv::Mat_<Pixel>(tmp2)) {
printf("%d,%d,%d\n",p.x,p.y,p.z);
}
imwrite("out.jpg", tmp2);
return 0;
}