当前位置:网站首页>26. histogram back projection
26. histogram back projection
2022-06-26 01:36:00 【Nightmare satiety】
#include <opencv2/opencv.hpp>
#include <iostream>
cv::Mat src, hsv, hue;
int bins = 12;
void Hist_And_Backproject(int, void*);
int main(int argc, char** argv){
src = cv::imread("../../source/project.png");
if(src.empty()){
std::cout << "could not load image...\n" << std::endl;
return -1;
}
const char* window_image = "input image";
cv::namedWindow(window_image, cv::WINDOW_AUTOSIZE);
cv::namedWindow("BackProj", cv::WINDOW_AUTOSIZE);
cv::namedWindow("Histogram", cv::WINDOW_AUTOSIZE);
cv::cvtColor(src, hsv, cv::COLOR_BGR2HSV);
hue.create(hsv.size(), hsv.depth());
int nchannels[] = {
0, 0};
cv::mixChannels(&hsv, 1, &hue, 1, nchannels, 1);
cv::createTrackbar("Histogram Bins: ", window_image, &bins, 180, Hist_And_Backproject);
Hist_And_Backproject(0, 0);
cv::imshow(window_image, src);
cv::waitKey(0);
}
void Hist_And_Backproject(int, void*){
float range[] = {
0, 180};
const float *histRanges = {
range };
cv::Mat h_hist;
cv::calcHist(&hue, 1, 0, cv::Mat(), h_hist, 1, &bins, &histRanges, true, false);
cv::normalize(h_hist, h_hist, 0, 255, cv::NORM_MINMAX, -1, cv::Mat());
cv::Mat backProImage;
cv::calcBackProject(&hue, 1, 0, h_hist, backProImage, &histRanges, 1, true);
cv::imshow("BackProj", backProImage);
int hist_h = 400;
int hist_w = 512;
cv::Mat histImage(hist_w, hist_h, CV_8UC3, cv::Scalar(0, 0, 0));
int bin_w = hist_w / bins;
for(int i = 1; i < bins; i++){
cv::rectangle(histImage, cv::Point((i - 1) * bin_w, (hist_h - cvRound(h_hist.at<float>(i - 1) * (400 / 255)))),
cv::Point(i * bin_w, hist_h),
cv::Scalar(0, 0, 255), -1);
}
cv::imshow("Histogram", histImage);
}

边栏推荐
- JSON basic syntax
- shell正则表达式
- RT-Thread 项目工程搭建和配置--(Env Kconfig)
- Shengxin weekly issue 34
- Web信息收集,互联网上的裸奔者
- Technical introduction - detailed explanation of chip manufacturing process
- 新库上线 | CnOpenData中国新房信息数据
- Longitude and latitude multipoint acquisition center point has been solved
- DGUS新升级:全面支持数字视频播放功能
- 从查询数据库性能优化谈到redis缓存-谈一谈缓存的穿透、雪崩、击穿
猜你喜欢

Duck feeding data instant collection solution resources

Region of Halcon: generation of multiple regions (4)

Qt Cmake 纯C 代码调用系统控制台输入scanf 及 中文输出乱码

MySQL book borrowing system project database creation TABLE statement (combined primary key and foreign key settings)

idea配置

Simple making of master seal

Technical introduction - detailed explanation of chip manufacturing process

Technical foreword - metauniverse

Installing MySQL databases in FreeBSD

生信周刊第33期
随机推荐
RT-Thread 项目工程搭建和配置--(Env Kconfig)
《网络是怎么样连接的》读书笔记 - 集线器、路由器和路由器(三)
Installing MySQL databases in FreeBSD
2022资料员-通用基础(资料员)考试模拟100题及在线模拟考试
15 `bs对象.节点名称.节点名称.string` 获取嵌套节点内容
新库上线 | CnOpenDataA股上市公司IPO申报发行文本数据
Maze walking
【Visual Studio Code】vscode快捷键大全
MySQL图书借阅系统项目数据库建库表语句(组合主键、外键设置)
Embedded C first learning notes
SPI protocol
Embedded C second learning notes
Qt Cmake 纯C 代码调用系统控制台输入scanf 及 中文输出乱码
Discrete Mathematics - 01 mathematical logic
MySQL例题一 综合案例(多条件组合查询)
100ask seven day IOT training camp learning notes - bare metal program framework design
Is it safe to log in the stock account on the flush? How to open a stock account in the flush
JSON实例(一)
FIFO code implemented in C language
Dgus new upgrade: fully support digital video playback function