将两个 1D 直方图合并为一个
Merging two 1d histograms into one
我得到了两个使用标准 openCV 函数 calcHist 创建的直方图:
int getModels(string filename) {
Mat src = imread(filename, 1);
if(!src.data) { return -1; }
Mat imageHSV;
cvtColor(src, imageHSV, COLOR_BGR2HSV);
vector<Mat> bgr_planes;
split(imageHSV, bgr_planes);
int histSize = 256;
float range[] = { 0, 256 } ;
const float* histRange = { range };
bool uniform = true; bool accumulate = false;
Mat g_hist, r_hist;
calcHist( &bgr_planes[1], 1, 0, Mat(), g_hist, 1, &histSize, &histRange, uniform, accumulate );
calcHist( &bgr_planes[2], 1, 0, Mat(), r_hist, 1, &histSize, &histRange, uniform, accumulate );
cv::Mat combined_hist = g_hist + r_hist;
int hist_w = 512; int hist_h = 400;
int bin_w = cvRound( (double) hist_w/histSize );
Mat histImage(hist_h, hist_w, CV_8UC3, Scalar( 0,0,0) );
for( int i = 0; i < histSize; i++ )
{
line( histImage, Point( bin_w*(i-1), cvRound(combined_hist.at<float>(i-1)) ) ,
Point( bin_w*(i), cvRound(combined_hist.at<float>(i)) ),
Scalar( 19,90,87), 2, 8, 0 );
}
/// Display
namedWindow(filename, CV_WINDOW_AUTOSIZE );
imshow(filename, histImage );
return 0;
}
有没有办法将它们合并成一个combined_hist
直方图?
是的,你可以。OpenCV有cv::add
可以像这样使用:
cv::Mat combined_hist;
cv::add(g_hist, r_hist, combined_hist);
但是,由于cv::Mat
具有重载运算符,因此您可以这样做:
cv::Mat combined_hist = g_hist + r_hist;
希望对您有所帮助。
相关文章:
- 如何将一个数组值合并为一个整数c++
- 如何将不同的可执行文件合并到一个窗口框架中进行编码?像浏览器一样
- 为什么在排序链表上的这种合并实现总是将两个列表都设置为 NULL,而只有一个应该设置一个列表?
- 将两个 cpp 文件合并为一个 cpp 文件
- 将所有 *.txt 文件合并到一个文本文件中,其名称由用户使用 C++ 提供
- C++ 如何将两个 makefile 对象目标规则(位于另一个文件夹中)合并到一个目标/规则中?
- 将两个列表合并为一个蛇形列表
- 使用迭代器进行合并排序中的一个缓冲区
- 如何通过通用引用或std::forward将这三个c++模板函数合并为一个
- C将链接库合并为一个库
- 是否可以将前向声明和常规声明合并到一个文件中,然后像分开一样使用它?
- 我正在编写一个拆分为 3 的合并排序,我不知道为什么它不起作用
- 两个 cin / cout 语句合并为一个
- 我想将四个字节合并为一个数字以进行串行传输
- 将两个 1D 直方图合并为一个
- 如何合并两个双重链接列表(访问下一个链接)
- 将 3 个列表合并到一个大列表中
- C++全局常量数组:是否保证合并(优化)到一个副本中
- 将多个 stl 文件合并为一个
- 我写了一个合并排序,但它有一些错误