Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/opencv/3.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
Image 如何处理.mp4中两幅图像的熵_Image_Opencv_Image Processing_Computer Vision_Entropy - Fatal编程技术网

Image 如何处理.mp4中两幅图像的熵

Image 如何处理.mp4中两幅图像的熵,image,opencv,image-processing,computer-vision,entropy,Image,Opencv,Image Processing,Computer Vision,Entropy,我正在研究熵,我正在从.mp4文件中获取连续帧,我想计算当前帧与前一帧的熵,如果它们之间的熵不为零,则应检查帧,否则应忽略帧,应保存前一帧,并在2秒后获取当前帧,如果熵为零,则应忽略它,然后再次等待2秒,这是我的代码: capture.open("recog.mp4"); if (!capture.isOpened()) { cerr << "can not open camera or video file" << endl; } while(1) {

我正在研究熵,我正在从.mp4文件中获取连续帧,我想计算当前帧与前一帧的熵,如果它们之间的熵不为零,则应检查帧,否则应忽略帧,应保存前一帧,并在2秒后获取当前帧,如果熵为零,则应忽略它,然后再次等待2秒,这是我的代码:

capture.open("recog.mp4");
if (!capture.isOpened()) {
    cerr << "can not open camera or video file" << endl;
}

while(1)
{
    capture >> current_frame;
    if (current_frame.empty())
        break;
    if (! previous_frame.empty())  {
       subtract(current_frame, previous_frame, pre_img);
       Mat hist;
       int channels[] = {0};
       int histSize[] = {32};
       float range[] = { 0, 256 };
       const float* ranges[] = { range };

       calcHist( &pre_img, 1, channels, Mat(), // do not use mask
                 hist, 1, histSize, ranges,
                 true, // the histogram is uniform
                 false );

       Mat histNorm = hist / (pre_img.rows * pre_img.cols);
       double entropy = 0.0;
       for (int i=0; i<histNorm.rows; i++)
       {
          float binEntry = histNorm.at<float>(i,0);
          if (binEntry != 0.0)
          {
            entropy -= binEntry * log(binEntry);
          }
          else
          {
            //ignore the frame andgo for next , but how to code it ? is any function with ignore ?
          }
waitKey(10);
current_frame.copyTo(previous_frame); 
}
capture.open(“recog.mp4”);
如果(!capture.isOpened()){
当前帧;
if(当前_frame.empty())
打破
如果(!previous_frame.empty()){
减去(当前帧、上一帧、前一帧);
Mat hist;
int通道[]={0};
int histSize[]={32};
浮动范围[]={0,256};
常量浮点*范围[]={range};
calcHist(&pre_img,1,channels,Mat(),//不使用掩码
历史,1,历史大小,范围,
true,//直方图是一致的
假);
Mat histNorm=hist/(预模拟行*预模拟列);
双熵=0.0;

对于(inti=0;i忽略一定数量的帧,只需从流中读取它们

for(int i=0; i<60; i++)
    capture >> current_frame;
我使用了一个阈值,因为由于噪声,不同帧之间的熵可能永远不会为零


如果您的编译器不提供
log2
函数,您只需按照说明对其进行模拟。

要忽略一定数量的帧,只需从流中读取它们

for(int i=0; i<60; i++)
    capture >> current_frame;
我使用了一个阈值,因为由于噪声,不同帧之间的熵可能永远不会为零


如果您的编译器不提供
log2
函数,您可以简单地按照描述对其进行模拟。

@soetschie但主要问题仍然存在,如何处理.mp4视频中的两个连续帧,当我为当前帧分配熵值时,当前帧将成为下一次迭代中的前一帧,值m那么如何给它们赋值,这样我就可以减去两个当前帧和前一帧的值,我想从前一帧的熵中减去当前帧的熵。你可以像处理帧一样处理它:用两个变量前一帧熵和当前帧熵。但是你已经在计算了g两幅图像差异的熵。那么你想监控变化的变化吗?两幅图像的差异是为了减去背景,这个减法是为了检测帧中的变化,如果帧更大,比如它包含的车辆超过了它应该处理的帧,你确定公式使用了日志吗2?还是它的简单日志?因为我得到了不同的公式's@sietschie你确定答案中的循环吗?@soetschie但主要问题仍然存在,如何处理.mp4视频中的两个连续帧,当我为当前帧分配熵值时,当前帧将成为下一次迭代中的前一帧,value mix,那么如何给它们赋值,这样我就可以减去当前帧和前两帧的值,我想从前一帧的熵中减去当前帧的熵。你可以像处理帧一样处理它:用两个变量,前一帧熵和当前帧熵。但是你已经是com把熵放在两幅图像的差异上。那么你想监控变化的变化吗?两幅图像的差异是为了减去背景,这个减法是为了检测帧中的变化,如果帧更大,比如它包含的车辆比它应该处理的帧大,你确定公式使用了e log2?还是它的简单对数?因为我得到了不同的公式's@sietschie你确定答案中的循环吗?