当前位置:网站首页>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);
}
正文
参考
边栏推荐
- 【二叉搜索树】增删改查功能代码实现
- LeetCode 6004. Get operands of 0
- Hardware and interface learning summary
- 【GYM 102832H】【模板】Combination Lock(二分图博弈)
- 软件测试工程师必会的银行存款业务,你了解多少?
- Qt 一个简单的word文档编辑器
- Notepad++ regular expression replacement string
- Effet Doppler (déplacement de fréquence Doppler)
- FFMPEG关键结构体——AVFormatContext
- China Jinmao online electronic signature, accelerating the digitization of real estate business
猜你喜欢
AtCoder Beginner Contest 258【比赛记录】
Upgrade openssl-1.1.1p for openssl-1.0.2k
Browser local storage
认识提取与显示梅尔谱图的小实验(观察不同y_axis和x_axis的区别)
Problem solving win10 quickly open ipynb file
Miaochai Weekly - 8
Yunna | what are the main operating processes of the fixed assets management system
FFMPEG关键结构体——AVCodecContext
GD32F4xx uIP协议栈移植记录
N1 # if you work on a metauniverse product [metauniverse · interdisciplinary] Season 2 S2
随机推荐
Permission problem: source bash_ profile permission denied
【luogu P3295】萌萌哒(并查集)(倍增)
Atcoder beginer contest 258 [competition record]
AtCoder Beginner Contest 254【VP记录】
[Chongqing Guangdong education] reference materials for Zhengzhou Vocational College of finance, taxation and finance to play around the E-era
【DesignMode】适配器模式(adapter pattern)
GD32F4xx uIP协议栈移植记录
VBA fast switching sheet
FFMPEG关键结构体——AVFrame
建立时间和保持时间的模型分析
Knowledge about the memory size occupied by the structure
多普勒效應(多普勒頻移)
Atcoder beginer contest 254 [VP record]
Codeforces Round #804 (Div. 2)【比赛记录】
Extracting profile data from profile measurement
[designmode] Decorator Pattern
【luogu CF487E】Tourists(圆方树)(树链剖分)(线段树)
Codeforces gr19 D (think more about why the first-hand value range is 100, JLS yyds)
PV static creation and dynamic creation
Problem solving win10 quickly open ipynb file