当前位置:网站首页>OpenCV经典100题
OpenCV经典100题
2022-07-06 00:17:00 【昨夜雨疏风骤z】

前言
常用知识记录
1. CV_8UC1,CV_8UC2,CV_8UC3等意思
一般的图像文件格式使用的是 Unsigned 8bits吧,CvMat矩阵对应的参数类型就是
CV_8UC1,CV_8UC2,CV_8UC3。
(最后的1、2、3表示通道数,譬如RGB3通道就用CV_8UC3)
而float 是32位的,对应CvMat数据结构参数就是:CV_32FC1,CV_32FC2,CV_32FC3…
double是64bits,对应CvMat数据结构参数:CV_64FC1,CV_64FC2,CV_64FC3等。
一、通道交换
题目: cv2::imread()的系数是按BGR的顺序进行排列的。
code
//读取图像,然后将BGR通道替换成RGB通道。
//Mat 图像没有长宽一说,只有宽高,这应该就能理解 width = cols height = rows
void MainWindow::test1ChannelSwap()
{
Mat sourceImage = imread("../Image/imori.jpg");
qDebug()<<"--->z MainWindow::test1ChannelSwap()1"<<sourceImage.rows<<sourceImage.cols;
imshow("sourceImage",sourceImage);
int width = sourceImage.cols;
int height = sourceImage.rows;
Mat newImage = Mat::zeros(height,width,CV_8UC3);
for (int i = 0; i < width; i++)
{
for (int j = 0; j<height; j++)
{
newImage.at<cv::Vec3b>(i, j)[0] = sourceImage.at<cv::Vec3b>(i, j)[2];
newImage.at<cv::Vec3b>(i, j)[1] = sourceImage.at<cv::Vec3b>(i, j)[1];
newImage.at<cv::Vec3b>(i, j)[2] = sourceImage.at<cv::Vec3b>(i, j)[0];
}
}
imshow("newImage",newImage);
}
二、灰度化
题目:灰度是一种图像亮度的表示方法,通过下式计算: Y = 0.2126 R + 0.7152 G + 0.0722 B Y = 0.2126\ R + 0.7152\ G + 0.0722\ B Y=0.2126 R+0.7152 G+0.0722 Bcode
void MainWindow::test2Grayscale()
{
Mat sourceImage = imread("../Image/imori.jpg");
qDebug()<<"--->z MainWindow::test1ChannelSwap()1"<<sourceImage.rows<<sourceImage.cols;
imshow("sourceImage",sourceImage);
int width = sourceImage.cols;
int height = sourceImage.rows;
Mat newImage = Mat::zeros(height,width,CV_8UC1);//注意,申请的时候是一个通道就可以了,因为只是一个灰度图而已。
for (int i = 0; i<height; i++)
{
for (int j = 0; j < width; j++)
{
newImage.at<uchar>(i,j) = 0.0126 * (float)sourceImage.at<Vec3b>(i,j)[2]+ 0.7152 * (float)sourceImage.at<Vec3b>(i,j)[1] + 0.0722 * (float)sourceImage.at<Vec3b>(i,j)[0];
}
}
imshow("newImage",newImage);
}
正文
参考
边栏推荐
- 行列式学习笔记(一)
- JS 这次真的可以禁止常量修改了!
- 上门预约服务类的App功能详解
- Ffmpeg learning - core module
- 【二叉搜索树】增删改查功能代码实现
- Yunna | what are the main operating processes of the fixed assets management system
- Configuring OSPF load sharing for Huawei devices
- 权限问题:source .bash_profile permission denied
- Effet Doppler (déplacement de fréquence Doppler)
- MySQL functions
猜你喜欢

Huawei equipment is configured with OSPF and BFD linkage

Ffmpeg learning - core module

【DesignMode】装饰者模式(Decorator pattern)

FFT 学习笔记(自认为详细)

从底层结构开始学习FPGA----FIFO IP核及其关键参数介绍

Determinant learning notes (I)

建立时间和保持时间的模型分析

MySql——CRUD
![[designmode] composite mode](/img/9a/25c7628595c6516ac34ba06121e8fa.png)
[designmode] composite mode
![[day39 literature extensive reading] a Bayesian perspective on magnetic estimation](/img/9c/438ef820a9f703c21f708bfc1dbbc4.jpg)
[day39 literature extensive reading] a Bayesian perspective on magnetic estimation
随机推荐
LeetCode 6005. The minimum operand to make an array an alternating array
OS i/o devices and device controllers
notepad++正则表达式替换字符串
认识提取与显示梅尔谱图的小实验(观察不同y_axis和x_axis的区别)
FFmpeg学习——核心模块
NSSA area where OSPF is configured for Huawei equipment
DEJA_ Vu3d - cesium feature set 055 - summary description of map service addresses of domestic and foreign manufacturers
Qt 一个简单的word文档编辑器
Codeforces Round #804 (Div. 2)【比赛记录】
2022.7.5-----leetcode. seven hundred and twenty-nine
Hudi of data Lake (1): introduction to Hudi
Notepad + + regular expression replace String
About the slmgr command
JS 这次真的可以禁止常量修改了!
Problems encountered in the database
Start from the bottom structure and learn the introduction of fpga---fifo IP core and its key parameters
MySQL functions
Atcoder beginer contest 254 [VP record]
Determinant learning notes (I)
QT a simple word document editor