OpenCV实现彩色图片的补色与反色
Posted ybqjymy
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了OpenCV实现彩色图片的补色与反色相关的知识,希望对你有一定的参考价值。
1 #include "stdafx.h" 2 #include <algorithm> 3 #include <opencv2/core/core.hpp> 4 #include <opencv2/highgui/highgui.hpp> 5 #include <opencv2/imgproc/imgproc.hpp> 6 using namespace cv; 7 8 int _tmain(int argc, _TCHAR* argv[]) 9 { 10 Mat img = imread("cat.jpg"); 11 Mat dst1,dst2; 12 img.copyTo(dst1); 13 img.copyTo(dst2); 14 int row = img.rows; 15 int col = img.cols; 16 for (int i = 0; i < row;++i) 17 for (int j = 0; j < col; ++j){ 18 int b = img.at<Vec3b>(i, j)[0];//blue 19 int g = img.at<Vec3b>(i, j)[1];//green 20 int r = img.at<Vec3b>(i, j)[2];//red 21 int maxrgb = max(max(r, g), b); 22 int minrgb = min(min(r, g), b); 23 dst1.at<Vec3b>(i, j)[0] = maxrgb + minrgb - b; 24 dst1.at<Vec3b>(i, j)[1] = maxrgb + minrgb - g; 25 dst1.at<Vec3b>(i, j)[2] = maxrgb + minrgb - r; 26 dst2.at<Vec3b>(i, j)[0] = 255 - b; 27 dst2.at<Vec3b>(i, j)[1] = 255 - g; 28 dst2.at<Vec3b>(i, j)[2] = 255 - r; 29 } 30 imshow("原图" , img ); 31 imshow("补色", dst1); 32 imshow("反色", dst2); 33 waitKey(); 34 return 0; 35 }
以上是关于OpenCV实现彩色图片的补色与反色的主要内容,如果未能解决你的问题,请参考以下文章
Intel Realsense D435 C/C++调用code examples(附代码)(坑坑坑坑坑!!!)(opencv显示图片反色解决)
Intel Realsense D435 C/C++调用code examples(附代码)(坑坑坑坑坑!!!)(opencv显示图片反色解决)