当前位置:网站首页>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);
}
正文
参考
边栏推荐
- Qt 一个简单的word文档编辑器
- Hardware and interface learning summary
- What are the functions of Yunna fixed assets management system?
- 云呐|固定资产管理系统功能包括哪些?
- The global and Chinese markets of dial indicator calipers 2022-2028: Research Report on technology, participants, trends, market size and share
- Add noise randomly to open3d point cloud
- 7.5模拟赛总结
- 单商户V4.4,初心未变,实力依旧!
- Senparc. Weixin. Sample. MP source code analysis
- QT -- thread
猜你喜欢

Doppler effect (Doppler shift)

18. (ArcGIS API for JS) ArcGIS API for JS point collection (sketchviewmodel)

Tools to improve work efficiency: the idea of SQL batch generation tools

Gavin teacher's perception of transformer live class - rasa project actual combat e-commerce retail customer service intelligent business dialogue robot system behavior analysis and project summary (4

Learn PWN from CTF wiki - ret2libc1

教你在HbuilderX上使用模拟器运行uni-app,良心教学!!!

多普勒效應(多普勒頻移)

OS i/o devices and device controllers

MySql——CRUD

GD32F4xx uIP协议栈移植记录
随机推荐
notepad++正則錶達式替換字符串
Permission problem: source bash_ profile permission denied
Transport layer protocol ----- UDP protocol
【NOI模拟赛】Anaid 的树(莫比乌斯反演,指数型生成函数,埃氏筛,虚树)
MySQL functions
QT QPushButton details
Atcoder beginer contest 254 [VP record]
[designmode] composite mode
【QT】Qt使用QJson生成json文件并保存
2022.7.5-----leetcode. seven hundred and twenty-nine
N1 # if you work on a metauniverse product [metauniverse · interdisciplinary] Season 2 S2
FFT learning notes (I think it is detailed)
提升工作效率工具:SQL批量生成工具思想
Codeforces Round #804 (Div. 2)【比赛记录】
FPGA内部硬件结构与代码的关系
Search (DFS and BFS)
Notepad + + regular expression replace String
MySQL global lock and table lock
[binary search tree] add, delete, modify and query function code implementation
Codeforces gr19 D (think more about why the first-hand value range is 100, JLS yyds)