当前位置:网站首页>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);
}

边栏推荐
- Shell regular expression
- JSON introduction
- Flex & Bison 开始
- STM32 key development foundation
- MySQL book borrowing system project database creation TABLE statement (combined primary key and foreign key settings)
- Mpu6050 reads the ID incorrectly and 0xd1 occurs (the correct ID should be 0x68 or 0x69). Solution.
- QT cmake pure C code calls the system console to input scanf and Chinese output garbled code
- 【Visual Studio Code】vscode快捷键大全
- 2021 - 1 - 15 notes de pêche Ctrl + C / V
- Oracle database complete uninstallation steps (no screenshot)
猜你喜欢

多接口调用,使用Promise.all、Promise.race和Promise.any

CityJSON

Online gadget sharing (updated from time to time, current quantity: 2)

Idea configuration

ETCD数据库源码分析——集群通信初始化

CityJSON

The kth largest element in the array

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

Data analysis slicer, PivotTable and PivotChart (necessary in the workplace)

Shengxin weekly issue 33
随机推荐
2021-1-15 摸魚做的筆記Ctrl+c /v來的
Region of Halcon: generation of multiple regions (4)
超详细SSM框架实现增删改查功能项目整体流程
Is it safe to open a fund account? Are there any risks?
MySQL book borrowing system project database creation TABLE statement (combined primary key and foreign key settings)
使用Gin框架运行Demo时报错“ listen tcp :8080: bind: An attempt was made to access a socket in a way forbidden”
STM32 key development foundation
shell正则表达式
Camera - 02 image sensor
Duck feeding data instant collection solution resources
MySQL例题一 综合案例(多条件组合查询)
Web信息收集,互联网上的裸奔者
What is the process of opening a mobile card account? Is it safe to open an account online?
**MySQL example 1 (query by multiple conditions according to different problems)**
剑指 Offer II 096. 字符串交织
STM32GPIO
Common basic Oracle commands
在FreeBSD中安装MySQL数据库
JSON introduction
物联网?快来看 Arduino 上云啦