当前位置:网站首页>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);
}
边栏推荐
- BFC、IFC、GFC、FFC概念理解、布局规则、形成方法、用处浅析
- 符号表
- 7.15 Day21---MySQL----索引
- 8款最佳实践,保护你的 IaC 安全!
- 3面头条,花7天整理了面试题和学习笔记,已正式入职半个月
- Can‘t connect to MySQL server on ‘localhost3306‘ (10061) 简洁明了的解决方法
- Turn: Management is the love of possibility, and managers must have the courage to break into the unknown
- 心余力绌:企业面临的软件供应链安全困境
- 在被面试官说了无数次后,终于潜下心来整理了一下JVM的类加载器
- C Expert Programming Chapter 5 Thinking about Chaining 5.6 Take it easy --- see who's talking: take the Turning quiz
猜你喜欢
![[Evaluation model] Topsis method (pros and cons distance method)](/img/e7/c24241faced567f3e93f6ff3f20074.png)
[Evaluation model] Topsis method (pros and cons distance method)

Web Basics and Exercises for C1 Certification - My Study Notes

编程大杂烩(三)

npm报错Beginning October 4, 2021, all connections to the npm registry - including for package installa

读者让我总结一波 redis 面试题,现在肝出来了

符号表

《看见新力量》第四期免费下载!走进十五位科技创业者的精彩故事

触觉智能分享-SSD20X实现升级显示进度条

获取单选框选中内容

Delphi-C端有趣的菜单操作界面设计
随机推荐
What are the steps for how to develop a mall system APP?
编程大杂烩(四)
【评价类模型】Topsis法(优劣解距离法)
梳理CamStyle、PTGAN、SPGAN、StarGAN
一个对象引用的思考
Use Patroni callback script to bind VIP pit
去重的几种方式
4.3 Annotation-based declarative transactions and XML-based declarative transactions
As soon as flink cdc is started, the CPU of the source Oracle server soars to more than 80%. What is the reason?
你以为border-radius只是圆角吗?【各种角度】
《看见新力量》第四期免费下载!走进十五位科技创业者的精彩故事
【一步到位】Jenkins的安装、部署、启动(完整教程)
CentOS7 —— yum安装mysql
C专家编程 第4章 令人震惊的事实:数组和指针并不相同 4.5 数组和指针的其他区别
C Expert Programming Chapter 5 Thinking about Linking 5.2 Advantages of Dynamic Linking
Cannot read properties of null (reading ‘insertBefore‘)
C专家编程 第4章 令人震惊的事实:数组和指针并不相同 4.1 数组并非指针
idea设置识别.sql文件类型以及其他文件类型
【JS】js给对象动态添加、设置、删除属性名和属性值
力扣:62.不同路径