当前位置:网站首页>OpenCV获取和设置图像的平均亮度
OpenCV获取和设置图像的平均亮度
2022-08-04 05:24:00 【superchao1982】
1. OpenCV1.0中C方式:
double getAvg(IplImage *img)
{
IplImage *gray = cvCreateImage(cvGetSize(img),IPL_DEPTH_8U,1);
cvCvtColor(img,gray,CV_RGB2GRAY);
CvScalar scalar = cvAvg(gray);
cvReleaseImage(&gray);
return scalar.val[0];
}
void setAvg(IplImage *img,IplImage *out,double avg_gray)
{
double prev_avg_gray = get_avg_gray(img);
cvConvertScale(img,out,avg_gray/prev_avg_gray);
}
2. OpenCV2.0中C++方式:
double getAvg(Mat img)
{
Mat gray;
cvtColor(img, gray, CV_RGB2GRAY);
Scalar scalar = mean(gray);
return scalar.val[0];
}
void setAvg(Mat scr,Mat dst, double avg)
{
double fpreAvg = getAvg(scr);
scr.convertTo(dst,scr.type(),avg/fpreAvg);
}
边栏推荐
- 败给“MySQL”的第60天,我重振旗鼓,四面拿下蚂蚁金服offer
- 12、分页插件
- 力扣:96.不同的二叉搜索树
- 解决错误:npm WARN config global `--global`, `--local` are deprecated
- The symbol table
- MySQL日期函数
- C Expert Programming Chapter 5 Thinking about Linking 5.1 Libraries, Linking and Loading
- C专家编程 第4章 令人震惊的事实:数组和指针并不相同 4.1 数组并非指针
- The difference between px, em, and rem
- Performance testing with Loadrunner
猜你喜欢
企业需要知道的5个 IAM 最佳实践
4.3 基于注解的声明式事务和基于XML的声明式事务
Resolved error: npm WARN config global `--global`, `--local` are deprecated
CentOS7 - yum install mysql
DP4398:国产兼容替代CS4398立体声24位/192kHz音频解码芯片
Turn: Management is the love of possibility, and managers must have the courage to break into the unknown
sql server如何得到本条记录与上一条记录的差异,即变动值
[One step in place] Jenkins installation, deployment, startup (complete tutorial)
关于yolo7和gpu
The symbol table
随机推荐
谷粒商城-基础篇(项目简介&项目搭建)
Get the selected content of the radio box
Teenage Achievement Hackers Need These Skills
What are the functions of mall App development?
Dynamic programming of the division of numbers
JS基础--强制类型转换(易错点,自用)
flink cdc一启动,源端Oracle那台服务器的CPU就飙升到80%以上,会是啥原因呢?
C Expert Programming Chapter 5 Thinking about Linking 5.3 5 Special Secrets of Library Linking
C Expert Programming Chapter 4 The Shocking Fact: Arrays and Pointers Are Not the Same 4.5 Other Differences Between Arrays and Pointers
C Expert Programming Chapter 5 Thinking about Chaining 5.6 Take it easy --- see who's talking: take the Turning quiz
C专家编程 第5章 对链接的思考 5.1 函数库、链接和载入
C专家编程 第4章 令人震惊的事实:数组和指针并不相同 4.1 数组并非指针
Delphi-C端有趣的菜单操作界面设计
2022年PMP考试延迟了,该喜该忧?
LCP 17. 速算机器人
The Road to Ad Monetization for Uni-app Mini Program Apps: Full Screen Video Ads
4.3 基于注解的声明式事务和基于XML的声明式事务
[C language advanced] program environment and preprocessing
static在不同位置定义变量居然还有不同的含义?
4.2 Declarative Transaction Concept