当前位置:网站首页>24. histogram calculation
24. histogram calculation
2022-06-26 01:36:00 【Nightmare satiety】
#include <opencv4/opencv2/opencv.hpp>
#include <iostream>
int main(int argc, char** argv){
cv::Mat src = cv::imread("/home/long2double/Desktop/OpenCV_Study/source/lena.png");
if(src.empty()){
std::cout << "could not load image ...." << std::endl;
return -1;
}
cv::namedWindow("test opencv setup");
cv::imshow("test opencv setup", src);
// Split channels
std::vector<cv::Mat> bgr_planes;
cv::split(src, bgr_planes);
// Calculate the histogram
int histSize = 256;
float range[] = {
0, 256};
const float *histRanges = {
range};
cv::Mat b_hist, g_hist, r_hist;
cv::calcHist(&bgr_planes[0], 1, 0, cv::Mat(), b_hist, 1, &histSize, &histRanges, true, false);
cv::calcHist(&bgr_planes[1], 1, 0, cv::Mat(), g_hist, 1, &histSize, &histRanges, true, false);
cv::calcHist(&bgr_planes[2], 1, 0, cv::Mat(), r_hist, 1, &histSize, &histRanges, true, false);
// normalization
int hist_h = 400;
int hist_w = 512;
int bin_w = hist_w / histSize;
cv::normalize(b_hist, b_hist, 0, hist_h, cv::NORM_MINMAX);
cv::normalize(g_hist, g_hist, 0, hist_h, cv::NORM_MINMAX);
cv::normalize(r_hist, r_hist, 0, hist_h, cv::NORM_MINMAX);
// Calculate the histogram
cv::Mat histImage(hist_w, hist_h, CV_8UC3, cv::Scalar(0, 0, 0));
for(int i = 1; i < histSize; i++){
cv::line(histImage, cv::Point((i - 1) * bin_w, hist_h - cvRound(b_hist.at<float>(i - 1))),
cv::Point(i * bin_w, hist_h - cvRound(b_hist.at<float>(i))), cv::Scalar(255, 0, 0), 2, cv::LINE_AA);
cv::line(histImage, cv::Point((i - 1) * bin_w, hist_h - cvRound(g_hist.at<float>(i - 1))),
cv::Point(i * bin_w, hist_h - cvRound(g_hist.at<float>(i))), cv::Scalar(0, 255, 0), 2, cv::LINE_AA);
cv::line(histImage, cv::Point((i - 1) * bin_w, hist_h - cvRound(r_hist.at<float>(i - 1))),
cv::Point(i * bin_w, hist_h - cvRound(r_hist.at<float>(i))), cv::Scalar(0, 0, 255), 2, cv::LINE_AA);
}
cv::imshow("histImage", histImage);
cv::waitKey();
}

边栏推荐
- Etcd database source code analysis -- inter cluster network layer server interface
- **MySQL例题一(根据不同问题,多条件查询)**
- leetcode 300. Longest Increasing Subsequence 最长递增子序列 (中等)
- 如何有效地推廣產品
- Longitude and latitude multipoint acquisition center point has been solved
- Is it safe for flush software to buy stocks for trading? How to open an account to buy shares
- Laravel basic course routing and MVC - controller
- 网上开通证券账户安全吗 证券网上开户
- [flower carving experience] 11 start esp32c3
- Laravel basic course routing and MVC - routing
猜你喜欢

物联网?快来看 Arduino 上云啦

Obtain WiFi password through computer (only connected WiFi)

RT thread project engineering construction and configuration - (Env kconfig)

DGUS新升级:全面支持数字视频播放功能

数组中的第K个最大元素

100ask seven day IOT training camp learning notes - bare metal program framework design

Idea configuration

【花雕体验】11 上手ESP32C3

"Hot post" Statistics

Xinku online | cnopendata text data of IPO declaration and issuance of A-share listed companies
随机推荐
Oracle数据库开启备份准备工作
Redis strings command
Is it safe to log in the stock account on the flush? How to open a stock account in the flush
Native DOM vs. virtual DOM
Embedded C first learning notes
2021 - 1 - 15 notes de pêche Ctrl + C / V
黑盒测试 — 测试用例 之 判定表法看这一篇就够了
Nacos registry
Reading notes on how to connect the network - hubs, routers and routers (III)
开窍之问答
[flower carving experience] 11 start esp32c3
--都市修炼手册之SQL-- 第一章 基础复习
CityJSON
New library launched | cnopendata wholesale price data of agricultural products
ETCD数据库源码分析——集群间网络层服务端接口
2022 explosion proof electrical operation certificate examination question bank and simulation examination
containerd客户端比较
Containerd client comparison
Simple making of master seal
Qt Cmake 纯C 代码调用系统控制台输入scanf 及 中文输出乱码