显示每帧更新的视频直方图
displaying updated video histogram with each fram
我想显示视频文件中每帧的更新直方图,
视频文件被捕获,然后传递给直方图计算函数
我已经对下面的代码做了一些修改,但是它不能像我想要的那样工作。
感谢你的帮助
对
#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;
}
下面的代码将绘制灰度图像的直方图。如果你想为彩色图像绘制直方图,你必须将图像分割成单独的通道,并可以将这些单独的通道单独绘制直方图。
#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;
}
相关文章:
- 如何在c++中录制具有精确帧时间戳的视频
- 使用 IMFSinkWriter 编码的视频的播放速度会根据宽度而变化
- 二进制图像的空间直方图
- 如何在c++中仅使用for循环打印此代码的垂直直方图
- 如何实时捕获相机的视频?
- 帧提取 使用OpenCV的视频文件开头只有几秒钟
- 使用 OpenCV C++ 每 1 分钟创建新的视频文件
- 从iPhone相机拍摄的视频似乎被OpenCV旋转了90度?我该如何解决这个问题?
- OpenCV没有显示来自Macbook网络摄像头的视频
- 在何处更改参考代码以从 HEVC 编码的视频中提取运动矢量
- 如何使用FFMPEG从编码的视频中提取AVPACKET的重要信息
- 我的视频流程在运行darknet.exe以进行检测对象时崩溃了
- 如何使用Raspberry Pi相机作为C ++ OpenCV中的视频输入
- OpenCV噪声消除静态摄像机的视频
- 如何使用FFMPEG与C拦截编码的视频数据
- 从opencv的视频关注和标量拍摄的图像之间的整数划分
- ARtoolkit加载从4k相机索尼捕获的视频文件
- openCV读取.avi文件的视频捕获获取空框架
- 如何为 OpenCV 的视频编写器动态选择可用的编解码器?
- 显示每帧更新的视频直方图