(7)opencv图片内部的基本处理
就是,给定我们一张图片,我们可以对图片的每一个像素的色彩进行处理
比如,我们的原图是这个样子
然后我首先将他变成灰度图(灰度图的行道是1,就是chanaual是1)
然后,我又将灰色图片的黑白进行颠倒
涉及的代码如下:
#include<iostream>
#include<opencv.hpp> using namespace std;
using namespace cv; int main()
{ Mat sou;
sou = imread("C:\\Users\\32829\\Desktop\\aa.jpg");
if (sou.empty())
{
cout << "图像读入失败" << endl;
}
namedWindow("new");
imshow("new", sou); Mat dst;
//将原图改为灰度图,就是改变原图的色系
cvtColor(sou, dst, CV_BGR2GRAY);
namedWindow("old1");
imshow("old1", dst); int height = dst.rows;//获取目标图的高度
int weight = dst.cols;//获取目标图的宽度 for (int row = ; row < height; row++)
{
for (int col = ; col < weight; col++)
{
int grey = dst.at<uchar>(row, col);//获取图片的每一个像素点
dst.at<uchar>(row, col) = - grey;//将像素点变成他的补
}
}
namedWindow("old2");
imshow("old2", dst); waitKey();
return ;
}
上面是一通道的图片修改,下面是三通道的修改
原图和修改后的图片展示
#include<iostream>
#include<opencv.hpp> using namespace std;
using namespace cv; int main()
{ Mat sou;
sou = imread("C:\\Users\\32829\\Desktop\\aa.jpg");
if (sou.empty())
{
cout << "图像读入失败" << endl;
}
namedWindow("new");
imshow("new", sou); Mat dst;
////将原图改为灰度图,就是改变原图的色系
//cvtColor(sou, dst, CV_BGR2GRAY);
//namedWindow("old1");
//imshow("old1", dst); //int height = dst.rows;//获取目标图的高度
//int weight = dst.cols;//获取目标图的宽度 //for (int row = 0; row < height; row++)
//{
// for (int col = 0; col < weight; col++)
// {
// int grey = dst.at<uchar>(row, col);//获取图片的每一个像素点
// dst.at<uchar>(row, col) = 255 - grey;//将像素点变成他的补
// }
//}
//namedWindow("old2");
//imshow("old2", dst); dst.create(sou.size(), sou.type());
namedWindow("old2");
imshow("old2", dst);
int height = dst.rows;//获取目标图的高度
int weight = dst.cols;//获取目标图的宽度
int chan = dst.channels(); for (int row = ; row < height; row++)
{
for (int col = ; col < weight; col++)
{
if (chan == )
{
int grey = dst.at<uchar>(row, col);//获取图片的每一个像素点
dst.at<uchar>(row, col) = - grey;//将像素点变成他的补
}
else if (chan==){
int b=sou.at<Vec3b>(row,col)[];//获取他的这个像素点的第一个值
int g = sou.at<Vec3b>(row, col)[];//获取他的这个像素点的第二个值
int r = sou.at<Vec3b>(row, col)[];//获取他的这个像素点的第三个值
//下面是修改像素值;
dst.at<Vec3b>(row, col)[] = - b;
dst.at<Vec3b>(row, col)[] = - g;
dst.at<Vec3b>(row, col)[] = - r;
}
}
} namedWindow("old4");
imshow("old4", dst); waitKey();
return ;
}
还有一个简单的方法:
然后代码就是将上面的for循环给删了
#include<iostream>
#include<opencv.hpp> using namespace std;
using namespace cv; int main()
{ Mat sou;
sou = imread("C:\\Users\\32829\\Desktop\\aa.jpg");
if (sou.empty())
{
cout << "图像读入失败" << endl;
}
namedWindow("new");
imshow("new", sou); Mat dst; dst.create(sou.size(), sou.type());
namedWindow("old2");
imshow("old2", dst);
int height = dst.rows;//获取目标图的高度
int weight = dst.cols;//获取目标图的宽度
int chan = dst.channels(); /////////////////////////////////////////////////////////就加了这一行 bitwise_not(sou, dst); ////////////////////////////////////////////////////////////////////
namedWindow("old4");
imshow("old4", dst); waitKey();
return ;
}
基础知识整理:
====================================================================
============================================================================
=============================================================================
===========================================================================
(7)opencv图片内部的基本处理的更多相关文章
- 基于opencv图片切割
基于opencv图片切割为n个3*3区块 工作原因,切割图片,任务急,暂留调通的源码,留以后用. package com.rosetta.image.test; import org.opencv.c ...
- Opencv图片明暗处理
Opencv图片明暗处理 #include <iostream> #include <opencv2/opencv.hpp> using namespace std; usin ...
- Python OpenCV图片转视频 工具贴(三)
Python OpenCV图片转视频 粘贴即用,注意使用时最好把自己的文件按照数字顺序命名.按照引导输入操作. # 一键傻瓜式引导图片串成视频 # 注意使用前最好把文件命名为数字顺序格式 import ...
- OpenCV图片类cv::Mat和QImage之间进行转换(好多相关文章)
在使用Qt和OpenCV混合编程时,我们有时需要在两种图片类cv::Mat和QImage之间进行转换,下面的代码参考了网上这个帖子: //##### cv::Mat ---> QImage ## ...
- OpenCV 图片尺寸调整
http://blog.csdn.net/xiaoshengforever/article/details/12191303 2013-09-30 12:21 10842人阅读 评论(0) 收藏 举报 ...
- OpenCV图片矩阵操作相关,对png图片操作(多通道)
文献链接: http://www.cnblogs.com/tornadomeet/archive/2012/12/26/2834336.html 下面这个高手,写了个小程序我还没有调试,回头 调试看看 ...
- 机器学习进阶-项目实战-信用卡数字识别 1.cv2.findContour(找出轮廓) 2.cv2.boudingRect(轮廓外接矩阵位置) 3.cv2.threshold(图片二值化操作) 4.cv2.MORPH_TOPHAT(礼帽运算突出线条) 5.cv2.MORPH_CLOSE(闭运算图片内部膨胀) 6. cv2.resize(改变图像大小) 7.cv2.putText(在图片上放上文本)
7. cv2.putText(img, text, loc, text_font, font_scale, color, linestick) # 参数说明:img表示输入图片,text表示需要填写的 ...
- opencv图片转幻灯片视频
/*g++ *.cpp `pkg-config --cflags --libs opencv` -std=c++11*/ #include <opencv2/opencv.hpp> usi ...
- opencv图片右转函数
因为需要将函数进行右转,发现opencv自带 的过于麻烦.自己写了个右转的.可以根据这个想法写出任何方向的 //函数功能,右转图片 IplImage* convertImage(IplImage* i ...
随机推荐
- 2.Jsoup
public static void main(String[] args) { //爬取最大资源网上的数据 //用CSS选择器 try { Document doc = Jsoup.parse(ne ...
- POJ 2386 Lake Counting 八方向棋盘搜索
Lake Counting Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 53301 Accepted: 26062 D ...
- C++ 类 与 static
背景 从学习C++到使用现在,发现很多新的东西,正好整理一下. static 为静态,指是当类编译加载的时候,内存就会开辟存储空间的. static 数据成员 在类中,static 可修饰 类中的成员 ...
- Windows驱动开发-派遣函数格式
NTSTATUS functionName(PDEVICE_OBJECT pDeviceObject, PIRP pIrp) { //业务代码区 //设置返回状态 pIrp->IoStatus. ...
- oracle 查看表中有多少字段
select count(*) from user_tab_columns t where t.TABLE_NAME='WPM_CHECK_ORDER'
- win10提示防火墙没有法更改某些设置的处理办法
一.问题发现 远程链接电脑时间发现远程链接失败 提问在“控制面板” 中打开“程序” 列表中启用“windows 防火墙” . 按照提示启用防火墙 ,发现启用或关闭页面不可编辑 二.原因是防火墙Wind ...
- python使用opencv在Windows下调用摄像头
环境准备 1.我这里使用的是python3.7.4,python官网下载较慢的同学可以移步至 https://pan.baidu.com/s/1XiPafBjM__zfBvvsLyK7kQ 提取码:z ...
- 吴裕雄 Bootstrap 前端框架开发——Bootstrap 字体图标(Glyphicons):glyphicon glyphicon-minus
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <meta name ...
- poj 2376 Cleaning Shifts 最小区间覆盖
Cleaning Shifts Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 40751 Accepted: 9871 ...
- 【pwnable.kr】 memcpy
pwnable的新一题,和堆分配相关. http://pwnable.kr/bin/memcpy.c ssh memcpy@pwnable.kr -p2222 (pw:guest) 我觉得主要考察的是 ...