【发布时间】:2024-01-20 22:34:01
【问题描述】:
我正在研究熵,我正在从 .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);
}
据我的页面工作告诉我,这是仅计算当前图像的一个图像的熵,并在下一个图像进入处理时成为前一个图像。当我像这样entropy -= binEntry * log2(binEntry); 使用它时,它在 log2 中出现错误,请您帮我告诉当熵为零时如何忽略帧,以便 .mp4 继续运行,我是否需要使用 cvwaitkey(2)在 2 秒后检查 .mp4,意味着 .mp4 正在运行,但我忽略了帧
忽略意味着当它从前一帧中减去当前帧并且熵为0时,前一帧保持前一帧,当前未变为前一帧,前一帧等待下一个当前图像2秒,然后对其执行任务
【问题讨论】:
标签: image opencv image-processing computer-vision entropy