博客
关于我
opencv4-图像操作
阅读量:799 次
发布时间:2023-02-23

本文共 1223 字,大约阅读时间需要 4 分钟。

Mat src = imread("E:\vs2015\opencvstudy\2.jpg", 1);

if (!src.data) {
cout << "could not load image!" << endl;
return -1;
}

// 灰度化处理

Mat gray_src;
cvtColor(src, gray_src, CV_BGR2GRAY);

// 取反处理

Mat gray_src_invert = Mat::zeros(gray_src.size(), gray_src.type());
for (int row = 0; row < gray_src.rows; row++) {
for (int col = 0; col < gray_src.cols; col++) {
int gray_pixel = gray_src.at
(row, col);
gray_src_invert.at
(row, col) = 255 - gray_pixel;
}
}

// 3通道取反处理

Mat dst, dst2;
dst.create(src.size(), src.type());
dst2.create(src.size(), src.type());

for (int row = 0; row < src.rows; row++) {

for (int col = 0; col < src.cols; col++) {
if (src.channels() == 1) {
int gray_pixel = gray_src.at
(row, col);
gray_src_invert.at
(row, col) = 255 - gray_pixel;
} else if (src.channels() == 3) {
Vec3b pixel = src.at
(row, col);
dst.at
(row, col) = {255 - pixel[0], 255 - pixel[1], 255 - pixel[2]};
dst2.at
(row, col) = {pixel[2], max(pixel[1], pixel[0])};
}
}
}

// 位操作取反

Mat bitwise_not_dst;
bitwise_not(src, bitwise_not_dst);

// ROI截取

Rect r(300, 300, 1000, 400);
Mat smallImg = gray_src(r);

cout << "gray_image height:" << gray_src.rows << endl;

cout << "gray_image width:" << gray_src.cols << endl;

imshow("ROI截取图像", smallImg);

转载地址:http://mmsfk.baihongyu.com/

你可能感兴趣的文章
oracle 10g crs命令,Oracle 10g CRS安装问题解决一例
查看>>
oracle 10g的安装配置
查看>>
Oracle 11.2.0.4 x64 RAC修改public/private/vip/scan地址
查看>>
Oracle 11G INDEX FULL SCAN 和 INDEX FAST FULL SCAN 对比分析
查看>>
Oracle 11g 使用RMAN备份数据库
查看>>
Oracle 11g 单实例安装文档
查看>>
Oracle 11gR2学习之二(创建数据库及OEM管理篇)
查看>>
Oracle 11gR2构建RAC之(2)--配置共享存储
查看>>
Oracle 11g中的snapshot standby特性
查看>>
Oracle 11g忘记sys、system、scott密码该这样修改!
查看>>
Oracle 11g数据库安装和卸载教程
查看>>
Oracle 11g超详细安装步骤
查看>>
Oracle 12c中的MGMTDB
查看>>
oracle avg、count、max、min、sum、having、any、all、nvl的用法
查看>>
Oracle BEQ方式连接配置
查看>>
oracle Blob保存方式,oracle 存储过程操作blob
查看>>
Oracle BMW Racing sailing vessel帆船图
查看>>
ORACLE Bug 4431215 引发的血案—原因分析篇
查看>>
Oracle Corp甲骨文公司推出Oracle NoSQL数据库2.0版
查看>>
oracle dblink 创建使用 垮库转移数据
查看>>