Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/126.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 显示每个fram的更新视频直方图_C++_Opencv - Fatal编程技术网

C++ 显示每个fram的更新视频直方图

C++ 显示每个fram的更新视频直方图,c++,opencv,C++,Opencv,我想显示视频文件中每帧的更新直方图 捕获视频文件,然后将其传递给直方图计算功能 我已经对下面的代码做了一些更改。但是它没有按照我想要的那样工作 谢谢你的帮助 问候 #include "opencv2/core/core.hpp" #include "opencv2/highgui/highgui.hpp" #include "opencv2/imgproc/imgproc.hpp" #include "iostream" #include "opencv2/highgui/highgui.hpp

我想显示视频文件中每帧的更新直方图

捕获视频文件,然后将其传递给直方图计算功能


我已经对下面的代码做了一些更改。但是它没有按照我想要的那样工作

谢谢你的帮助

问候

#include "opencv2/core/core.hpp"
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/imgproc/imgproc.hpp"
#include "iostream"
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/imgproc/imgproc.hpp"
#include <iostream>
#include <stdio.h>

using namespace cv;
using namespace std;

 void histogramcalculation(const Mat &Image, Mat &histoImage)
{  
 int histSize = 255;
 // Set the ranges ( for B,G,R) )

float range[] = { 0, 256 } ;
const float* histRange = { range };
bool uniform = true; bool accumulate = false;
Mat b_hist, g_hist, r_hist;


 // Compute the histograms:

calcHist( &Image, 1, 0, Mat(), b_hist, 1, &histSize,  &histRange,    uniform, accumulate );


// Draw the histogram

  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) );

// Normalize the result to [ 0, histImage.rows ]

normalize(b_hist, b_hist, 0, histImage.rows, NORM_MINMAX, -1, Mat());


   // Draw 

  for( int i = 1; i < histSize; i++ )

 {
 line( histImage, Point( bin_w*(i-1), hist_h - cvRound(b_hist.at<float>   (i-1)) ) , Point( bin_w*(i), hist_h - cvRound(b_hist.at<float>(i)) ),   Scalar( 255, 0, 0), 2, 8, 0 );



  }
 histoImage= histImage;

 }

int main( )
 {

 Mat histImage;

VideoCapture cap("eye.mp4"); // open video
if(!cap.isOpened())  // check if we succeeded
    return -1;

 namedWindow("Video",1);
 namedWindow("ycbcr",1);
 while(1)
 {
    Mat frame;

    cap >> frame; // get a new frame

   imshow( "video", frame );

// Calculate the histogram

 histogramcalculation(frame, histImage);

// Display the histogram 

 imshow("Colour Image Histogram", histImage );

 // Wait until user exits the program

 waitKey();

  }
return 0;
}
#包括“opencv2/core/core.hpp”
#包括“opencv2/highgui/highgui.hpp”
#包括“opencv2/imgproc/imgproc.hpp”
#包括“iostream”
#包括“opencv2/highgui/highgui.hpp”
#包括“opencv2/imgproc/imgproc.hpp”
#包括
#包括
使用名称空间cv;
使用名称空间std;
空洞组织图像计算(常数矩阵和图像、矩阵和组织图像)
{  
int histSize=255;
//设置范围(对于B、G、R))
浮动范围[]={0,256};
常量浮点*histRange={range};
布尔一致=真;布尔累积=假;
Mat b_hist、g_hist、r_hist;
//计算直方图:
calcHist(&Image,1,0,Mat(),b_hist,1,&histSize,&histRange,uniform,累加);
//绘制柱状图
int hist_w=512;int hist_h=400;
int bin_w=cvRound((双)hist_w/histSize);
Mat histImage(hist_h,hist_w,CV_8UC3,标量(0,0,0));
//将结果规格化为[0,histImage.rows]
规范化(b_hist,b_hist,0,histImage.rows,NORM_MINMAX,-1,Mat());
//画
对于(int i=1;i>帧;//获取新帧
imshow(“视频”,帧);
//计算直方图
组织图像计算(帧、组织图像);
//显示直方图
imshow(“彩色图像直方图”,histImage);
//等待用户退出程序
waitKey();
}
返回0;
}

下面的代码将绘制灰度图像的直方图。如果要为彩色图像绘制直方图,必须将图像分割为单独的通道,并可以使用这些单独的通道单独绘制直方图

#include "opencv2/core/core.hpp"
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/imgproc/imgproc.hpp"
#include "iostream"
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/imgproc/imgproc.hpp"
#include <iostream>
#include <stdio.h>

using namespace cv;
using namespace std;

 void histogramcalculation(const Mat &Image, Mat &histoImage)
{  
 int histSize = 255;
 // Set the ranges ( for B,G,R) )

float range[] = { 0, 256 } ;
const float* histRange = { range };
bool uniform = true; bool accumulate = false;
Mat b_hist, g_hist, r_hist;


 // Compute the histograms:

calcHist( &Image, 1, 0, Mat(), b_hist, 1, &histSize,  &histRange,    uniform, accumulate );


// Draw the histogram

  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) );

// Normalize the result to [ 0, histImage.rows ]

normalize(b_hist, b_hist, 0, histImage.rows, NORM_MINMAX, -1, Mat());


   // Draw 

  for( int i = 1; i < histSize; i++ )

 {
 line( histImage, Point( bin_w*(i-1), hist_h - cvRound(b_hist.at<float>   (i-1)) ) , Point( bin_w*(i), hist_h - cvRound(b_hist.at<float>(i)) ),   Scalar( 255, 0, 0), 2, 8, 0 );



  }
 histoImage= histImage;

 }

int main( )
 {

 Mat histImage;

VideoCapture cap("test1.avi"); // open video
if(!cap.isOpened())  // check if we succeeded
    return -1;

 while(1)
 {
    Mat frame;

    cap >> frame; // get a new frame


   imshow( "video", frame );
   cvtColor(frame, frame, CV_BGR2GRAY );

// Calculate the histogram

 histogramcalculation(frame, histImage);

// Display the histogram 

 imshow("Gray Scale Image Histogram", histImage );

 // Wait until user exits the program

 waitKey(5);

  }
return 0;
}
#包括“opencv2/core/core.hpp”
#包括“opencv2/highgui/highgui.hpp”
#包括“opencv2/imgproc/imgproc.hpp”
#包括“iostream”
#包括“opencv2/highgui/highgui.hpp”
#包括“opencv2/imgproc/imgproc.hpp”
#包括
#包括
使用名称空间cv;
使用名称空间std;
空洞组织图像计算(常数矩阵和图像、矩阵和组织图像)
{  
int histSize=255;
//设置范围(对于B、G、R))
浮动范围[]={0,256};
常量浮点*histRange={range};
布尔一致=真;布尔累积=假;
Mat b_hist、g_hist、r_hist;
//计算直方图:
calcHist(&Image,1,0,Mat(),b_hist,1,&histSize,&histRange,uniform,累加);
//绘制柱状图
int hist_w=512;int hist_h=400;
int bin_w=cvRound((双)hist_w/histSize);
Mat histImage(hist_h,hist_w,CV_8UC3,标量(0,0,0));
//将结果规格化为[0,histImage.rows]
规范化(b_hist,b_hist,0,histImage.rows,NORM_MINMAX,-1,Mat());
//画
对于(int i=1;i>帧;//获取新帧
imshow(“视频”,帧);
CVT颜色(边框、边框、CV_BGR2GRAY);
//计算直方图
组织图像计算(帧、组织图像);
//显示直方图
imshow(“灰度图像直方图”,histImage);
//等待用户退出程序
等待键(5);
}
返回0;
}

“。但它没有按我所希望的那样工作。”@sarmadm您忘了将图像转换为灰度。!!请接受向上投票的答案。!!