其他分享
首页 > 其他分享> > 利用图像二维熵实现视频信号丢失检测(Signal Loss Detection)

利用图像二维熵实现视频信号丢失检测(Signal Loss Detection)

作者:互联网

1 图像二维熵

2 信号丢失检测

2.1 画面对比

2.2 基于图像二维熵的图像信号丢失检测C++实现(使用OpenCV)

bool SignalLossDetection::SignalEntropyLossException(cv::Mat& inputImg, double threshold)
{
	//convert the input BGR image to GRAY iamge
	cv::cvtColor(inputImg, inputImg, cv::COLOR_BGR2GRAY);
	inputImg.convertTo(inputImg, CV_64F);
	cv::Mat imgEntropyMap= cv::Mat::zeros(256, 256, CV_64F);// 255 *256 entropy map
	//calculate the mean value of K=8 neighborhood
	cv::Mat meanKernal(3, 3, CV_16S);
	short mean[]{ 1,1,1,
		      1,0,1,
		      1,1,1 };
	meanKernal.data = (unsigned char*)mean;
	cv::Mat meanMap;
	cv::filter2D(inputImg, meanMap, -1, meanKernal, cv::Point(-1, -1), 0.0, cv::BORDER_REFLECT_101);
	meanMap /= 8;

	//calculate the (intensity, mean intensity of the K=8 neighborhood) two-tuples of the image
	inputImg.convertTo(inputImg, CV_8UC1);
	meanMap.convertTo(meanMap, CV_8UC1);
	for(int i{0};i<meanMap.rows;++i)
		for (int j{ 0 }; j < meanMap.cols; ++j) {
			imgEntropyMap.at<double>(inputImg.at<uchar>(i, j), meanMap.at<uchar>(i, j))+=1;
		}

	//calculate the two dimensional entropy of the image
	imgEntropyMap /= (inputImg.rows * inputImg.cols);
	cv::Mat logMap;
	cv::log(imgEntropyMap + 1e-7, logMap);//add delta=1e-7 to avoid overflow
	if (-cv::sum(imgEntropyMap)[0] <= threshold)//determine whether the image have the signal loss exception
		return true;
	else
		return false;
}

2.3 信号丢失检测结果分析

通过对图像计算二维熵值,并设置合理阈值(Threshold)便能达到信号丢失画面检测的目的。检测结果如下:

标签:Loss,inputImg,Signal,Detection,二维,丢失,信号,图像,cv
来源: https://www.cnblogs.com/pandalu/p/16560616.html