一杯清酒邀明月
天下本无事,庸人扰之而烦耳。
复制代码
 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 }
复制代码

 

posted on   一杯清酒邀明月  阅读(973)  评论(0编辑  收藏  举报
编辑推荐:
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
· 没有源码,如何修改代码逻辑?
· 一个奇形怪状的面试题:Bean中的CHM要不要加volatile?
· [.NET]调用本地 Deepseek 模型
· 一个费力不讨好的项目,让我损失了近一半的绩效!
阅读排行:
· 全网最简单!3分钟用满血DeepSeek R1开发一款AI智能客服,零代码轻松接入微信、公众号、小程
· .NET 10 首个预览版发布,跨平台开发与性能全面提升
· 《HelloGitHub》第 107 期
· 全程使用 AI 从 0 到 1 写了个小工具
· 从文本到图像:SSE 如何助力 AI 内容实时呈现?(Typescript篇)
< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5

点击右上角即可分享
微信分享提示