当前位置:网站首页>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);
}
正文
参考
边栏推荐
- FFMPEG关键结构体——AVFormatContext
- The difference of time zone and the time library of go language
- XML configuration file (DTD detailed explanation)
- 时区的区别及go语言的time库
- LeetCode 6005. The minimum operand to make an array an alternating array
- NSSA area where OSPF is configured for Huawei equipment
- Mathematical model Lotka Volterra
- JS 这次真的可以禁止常量修改了!
- OS i/o devices and device controllers
- 剖面测量之提取剖面数据
猜你喜欢
![[online chat] the original wechat applet can also reply to Facebook homepage messages!](/img/d2/1fd4de4bfd433ed397c236ddb97a66.png)
[online chat] the original wechat applet can also reply to Facebook homepage messages!

权限问题:source .bash_profile permission denied

Hudi of data Lake (2): Hudi compilation

Problem solving win10 quickly open ipynb file

多线程与高并发(8)—— 从CountDownLatch总结AQS共享锁(三周年打卡)
![Go learning --- structure to map[string]interface{}](/img/e3/59caa3f2ba5bd3647bdbba075ee60d.jpg)
Go learning --- structure to map[string]interface{}

Senparc. Weixin. Sample. MP source code analysis

The difference of time zone and the time library of go language

Key structure of ffmpeg -- AVCodecContext

notepad++正则表达式替换字符串
随机推荐
【NOI模拟赛】Anaid 的树(莫比乌斯反演,指数型生成函数,埃氏筛,虚树)
Shardingsphere source code analysis
Gd32f4xx UIP protocol stack migration record
[Luogu p3295] mengmengda (parallel search) (double)
Mysql - CRUD
Global and Chinese markets of universal milling machines 2022-2028: Research Report on technology, participants, trends, market size and share
【在线聊天】原来微信小程序也能回复Facebook主页消息!
【QT】Qt使用QJson生成json文件并保存
Recognize the small experiment of extracting and displaying Mel spectrum (observe the difference between different y_axis and x_axis)
Miaochai Weekly - 8
Start from the bottom structure and learn the introduction of fpga---fifo IP core and its key parameters
LeetCode 1598. Folder operation log collector
7.5模拟赛总结
LeetCode 斐波那契序列
About the slmgr command
Qt 一个简单的word文档编辑器
什么叫做信息安全?包含哪些内容?与网络安全有什么区别?
Global and Chinese market of digital serial inverter 2022-2028: Research Report on technology, participants, trends, market size and share
7.5 simulation summary
Senparc. Weixin. Sample. MP source code analysis