我正在尝试比较视频Feed中的连续帧。在每一帧,我都会做以下检查:
bool
DMSUSBVideoDevicePlugin::_hasImageChanged()
{
using namespace cv;
Mat src = cv::Mat(_captureHeight, _captureWidth, CV_8UC3, (void*) _imageData);
/// Separate the image in 3 places ( B, G and R )
vector<Mat> bgr_planes;
split( src, bgr_planes );
/// Establish the number of bins
int histSize = 256;
/// Set the ranges ( for B,G,R) )
float range[] = { 0, 256 };
const float* histRange = { range };
bool uniform = true;
bool accumulate = false;
Mat g_hist;
/// Compute the histograms:
calcHist(&bgr_planes[1], 1, 0, Mat(), g_hist, 1, &histSize, &histRange, uniform, accumulate);
// Draw the histograms for Green channel alone since we know that that's where all the action is
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(g_hist, g_hist, 0.0, histImage.rows, 32, -1, Mat());
static bool isFirstFrame = true;
if(isFirstFrame)
{
_lastGreenHistogram = g_hist;
isFirstFrame = false;
return true;
}
double diff = compareHist(g_hist, _lastGreenHistogram, CV_COMP_BHATTACHARYYA);
_lastGreenHistogram = g_hist;
std::cout << "Diff val: " << diff << std::endl;
if(diff > 1.f)
{
return true;
}
return false;
}
即使视频内容发生剧烈变化,从当前帧获得的直方图值也没有变化,即从前一个帧获得的viz-a-viz(基本上,diff值总是静态的)。
以下是我用不同方法得到的值:
CV_COMP_CORREL 0
CV_COMP_CHISQR 1
CV_COMP_INTERSECT 400
CV_COMP_BHATTACHARYYA 0
有人可以帮我指出我做错了吗?