bool SignalLossDetection::SignalEntropyLossException(cv::Mat& inputImg, double threshold){//convert the input BGR image to GRAY iamgecv::cvtColor(inputImg, inputImg, cv::COLOR_BGR2GRAY);inputImg.convertTo(inputImg, CV_64F);cv::Mat imgEntropyMap= cv::Mat::zeros(256, 256, CV_64F);// 256 * 256 entropy map//calculate the mean value of K=8 neighborhoodcv::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 imageinputImg.convertTo(inputImg, CV_8UC1);meanMap.convertTo(meanMap, CV_8UC1);for(int i{0};i(inputImg.at(i, j), meanMap.at(i, j))+=1;}//calculate the two dimensional entropy of the imageimgEntropyMap /= (inputImg.rows * inputImg.cols);cv::Mat logMap;cv::log(imgEntropyMap + 1e-7, logMap);//add delta=1e-7 to avoid overflowif (-cv::sum(imgEntropyMap)[0] <= threshold)//determine whether the image have the signal loss exceptionreturn true;elsereturn false;}
通过对图像计算二维熵值,并设置合理阈值(Threshold)便能达到信号丢失画面检测的目的。检测结果如下:
文章来自https://www.cnblogs.com/pandalu/p/16560616.html
留言与评论(共有 0 条评论) “” |