当前位置:网站首页>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);
}
正文
参考
边栏推荐
- Single source shortest path exercise (I)
- 【NOI模拟赛】Anaid 的树(莫比乌斯反演,指数型生成函数,埃氏筛,虚树)
- Zhuan: in the future, such an organization can withstand the risks
- [gym 102832h] [template] combination lock (bipartite game)
- 电机的简介
- [designmode] Decorator Pattern
- FFmpeg学习——核心模块
- STM32 configuration after chip replacement and possible errors
- 【DesignMode】组合模式(composite mode)
- shardingsphere源码解析
猜你喜欢
wx. Getlocation (object object) application method, latest version
【DesignMode】组合模式(composite mode)
Search (DFS and BFS)
传输层协议------UDP协议
Key structure of ffmpeg -- AVCodecContext
【DesignMode】装饰者模式(Decorator pattern)
Yunna | what are the main operating processes of the fixed assets management system
FFMPEG关键结构体——AVFrame
软件测试工程师必会的银行存款业务,你了解多少?
Effet Doppler (déplacement de fréquence Doppler)
随机推荐
STM32 configuration after chip replacement and possible errors
PHP determines whether an array contains the value of another array
N1 # if you work on a metauniverse product [metauniverse · interdisciplinary] Season 2 S2
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
Add noise randomly to open3d point cloud
认识提取与显示梅尔谱图的小实验(观察不同y_axis和x_axis的区别)
Atcoder beginer contest 254 [VP record]
Go learning - dependency injection
【QT】Qt使用QJson生成json文件并保存
AtCoder Beginner Contest 258【比赛记录】
Atcoder beginer contest 258 [competition record]
Effet Doppler (déplacement de fréquence Doppler)
LeetCode 1189. Maximum number of "balloons"
Detailed explanation of APP functions of door-to-door appointment service
数据库遇到的问题
Global and Chinese market of digital serial inverter 2022-2028: Research Report on technology, participants, trends, market size and share
剖面测量之提取剖面数据
Miaochai Weekly - 8
Go learning --- structure to map[string]interface{}
JS 这次真的可以禁止常量修改了!