模式识别 - 有害视频检测程序的策略
2014-05-20 10:36
183 查看
有害视频检测程序的策略
本文地址: http://blog.csdn.net/caroline_wendy/article/details/26346831有害(色情\恐怖\暴力)视频, 严重危害网络的健康, 需要进行检测和过滤.
检测色情\恐怖视频, 通过检测程序, 检测出多个场景的概率, 然后进行排序, 当场景多余6个时, 只取最大的6个场景;
返回的概率值是前3个最大检测值场景的概率的均值;
色情\恐怖汇总时, 首先检测色情, 如果为色情视频, 则不进行恐怖的检测, 否则继续检测恐怖, 如果都不时, 则为未知视频.
代码:
#include "stdafx.h" #include "VideoDetector.h" using namespace std; double detectPornVideo( std::vector<PornSceneInfo>& infosSet, const std::string _fileName, const std::string _imagePath, const std::string _imageName, const std::string _modelPath) { struct bigger { bool operator() (PornSceneInfo i, PornSceneInfo j) { return (i.prop>j.prop); } } mybigger; double finalResult(0.0); const int FirstNum(3); //计算最大3个的概率 const int MaxImageNum(6); //最多返回6个结构体 std::vector<PornSceneInfo> vResults; const std::string fileName(_fileName); const std::string imagePath(_imagePath); //提前新建文件夹 const std::string imageName(_imageName); const std::string modelPath(_modelPath); const std::size_t shotInterval(100); const std::size_t sceneShotNum(20); std::size_t num = PornVideoSceneNum(fileName.c_str(), shotInterval, sceneShotNum); PornSceneInfo* resultSet = new PornSceneInfo[num]; if (PornVideoDetector_Info(resultSet, imagePath.c_str(), fileName.c_str(), imageName.c_str(), modelPath.c_str(), shotInterval, sceneShotNum)) { for (std::size_t i=0; i<num; ++i) { vResults.push_back(resultSet[i]); } } else { std::cout << " Failed to detect the video! " << std::endl; } delete[] resultSet; resultSet = nullptr; if (num > MaxImageNum) { std::sort(vResults.begin(), vResults.end(), mybigger); for(int i=0; i<MaxImageNum; ++i) { infosSet.push_back(vResults[i]); //从大到小排列, 最多包涵MaxImageNum个 } } else { std::sort(vResults.begin(), vResults.end(), mybigger); infosSet = vResults; } if (num > FirstNum) { std::sort(vResults.begin(), vResults.end(), mybigger); for(int i=0; i<FirstNum; ++i) { finalResult += vResults[i].prop; //大于3个只取前3个 } finalResult /= FirstNum; } else { for(std::size_t i=0; i<num; ++i) { finalResult += vResults[i].prop; } finalResult /= num; } return finalResult; } double detectHorrorVideo( std::vector<HorrorSceneInfo>& infosSet, const std::string _fileName, const std::string _imagePath, const std::string _imageName, const std::string _modelPath) { struct bigger { bool operator() (HorrorSceneInfo i, HorrorSceneInfo j) { return (i.prop>j.prop); } } mybigger; double finalResult(0.0); const int FirstNum(3); //计算最大3个的概率 const int MaxImageNum(6); //最多返回6个结构体 std::vector<HorrorSceneInfo> vResults; const std::string fileName(_fileName); const std::string imagePath(_imagePath); //提前新建文件夹 const std::string imageName(_imageName); const std::string modelPath(_modelPath); const std::size_t shotInterval(100); const std::size_t sceneShotNum(20); std::size_t num = HorrorVideoSceneNum(fileName.c_str(), shotInterval, sceneShotNum); HorrorSceneInfo* resultSet = new HorrorSceneInfo[num]; if (HorrorVideoDetector_Info(resultSet, imagePath.c_str(), fileName.c_str(), imageName.c_str(), modelPath.c_str(), shotInterval, sceneShotNum)) { for (std::size_t i=0; i<num; ++i) { vResults.push_back(resultSet[i]); } } else { std::cout << " Failed to detect the video! " << std::endl; } delete[] resultSet; resultSet = nullptr; if (num > MaxImageNum) { std::sort(vResults.begin(), vResults.end(), mybigger); for(int i=0; i<MaxImageNum; ++i) { infosSet.push_back(vResults[i]); } } else { std::sort(vResults.begin(), vResults.end(), mybigger); infosSet = vResults; } if (num > FirstNum) { std::sort(vResults.begin(), vResults.end(), mybigger); for(int i=0; i<FirstNum; ++i) { finalResult += vResults[i].prop; } finalResult /= FirstNum; } else { for(std::size_t i=0; i<num; ++i) { finalResult += vResults[i].prop; } finalResult /= num; } return finalResult; } void videoDetector( const char* const _fileName, /*文件名*/ const char* const _imagePath, /*图片路径*/ const char* const _imageName, /*图片名称*/ int& _signal, /*标志位, 0未知, 1色情, 2恐怖*/ double& _prop, /*概率*/ std::vector<SceneInfo>& _infosSet ) { _signal = 0; _prop = 0.0; const std::string fileName(_fileName); const std::string imagePath(_imagePath); //提前新建文件夹 const std::string imageName(_imageName); const std::string modelPath("./models"); double pornResult(-1.0); double horrorResult(-1.0); std::vector<PornSceneInfo> pornInfosSet; std::vector<HorrorSceneInfo> horrorInfosSet; try { pornResult = detectPornVideo(pornInfosSet, fileName, imagePath, imageName, modelPath); } catch (std::exception ex) { std::cout << ex.what() << std::endl; } std::vector<SceneInfo> infosSet(pornInfosSet.size()); for (std::size_t i=0; i<pornInfosSet.size(); ++i) { std::cout << " Scene[" << i << "] Prop : " << pornInfosSet[i].prop << std::endl; std::cout << " Scene[" << i << "] Image Path : " << pornInfosSet[i].imagePath << std::endl; std::cout << " Scene[" << i << "] Begin Time : " << pornInfosSet[i].btime << std::endl; std::cout << " Scene[" << i << "] End Time : " << pornInfosSet[i].etime << std::endl; std::cout << " Scene[" << i << "] Begin Pos : " << pornInfosSet[i].bpos << std::endl; std::cout << " Scene[" << i << "] End Pos : " << pornInfosSet[i].epos << std::endl; infosSet[i].prop = pornInfosSet[i].prop; strcpy(infosSet[i].imagePath, pornInfosSet[i].imagePath); infosSet[i].btime = pornInfosSet[i].btime; infosSet[i].etime = pornInfosSet[i].etime; infosSet[i].bpos = pornInfosSet[i].bpos; infosSet[i].epos = pornInfosSet[i].epos; } if (pornResult > 0.7) { //返回色情 std::cout << "Porn Result = " << pornResult << std::endl; _signal = 1; _prop = pornResult; _infosSet = infosSet; return; } try { horrorResult = detectHorrorVideo(horrorInfosSet, fileName, imagePath, imageName, modelPath); } catch (std::exception ex) { std::cout << ex.what() << std::endl; } for (std::size_t i=0; i<horrorInfosSet.size(); ++i) { std::cout << " Scene[" << i << "] Prop : " << horrorInfosSet[i].prop << std::endl; std::cout << " Scene[" << i << "] Image Path : " << horrorInfosSet[i].imagePath << std::endl; std::cout << " Scene[" << i << "] Begin Time : " << horrorInfosSet[i].btime << std::endl; std::cout << " Scene[" << i << "] End Time : " << horrorInfosSet[i].etime << std::endl; std::cout << " Scene[" << i << "] Begin Pos : " << horrorInfosSet[i].bpos << std::endl; std::cout << " Scene[" << i << "] End Pos : " << horrorInfosSet[i].epos << std::endl; infosSet[i].prop = horrorInfosSet[i].prop; strcpy(infosSet[i].imagePath,horrorInfosSet[i].imagePath); infosSet[i].btime = horrorInfosSet[i].btime; infosSet[i].etime = horrorInfosSet[i].etime; infosSet[i].bpos = horrorInfosSet[i].bpos; infosSet[i].epos = horrorInfosSet[i].epos; } if (horrorResult > 0.6) { //返回恐怖 std::cout << "Horror Result = " << horrorResult << std::endl; _signal = 2; _prop = horrorResult; _infosSet = infosSet; return; } _infosSet = infosSet; std::cout << "Porn Result = " << pornResult << std::endl; std::cout << "Horror Result = " << horrorResult << std::endl; return; }
相关文章推荐
- 模式识别 - 有害视频检测程序的策略
- 模式识别 - 有害视频检測程序的策略
- opencv程序十五:实时视频轮廓检测
- 安装win7旗舰版,一直卡在安装程序正在检测视频性能
- opencv实践程序3——打开摄像头视频及轮廓检测的简单程序
- 视频追踪之目标选择(一)------边缘检测值程序
- OpenCV 实践程序12——用分类器对视频进行人脸检测
- 人脸检测的测试程序(视频和摄像头)
- OpenCV成长之路1:将canny边缘检测应用于视频的程序
- 点对点视频会议程序:VideoNet
- 在Direct3D程序中运用碰撞检测
- PHP+SQLITE制作简单的视频点播程序
- 一个简单的摄像头视频浏览和捕获的程序
- MPEG-4中的视频对象检测技术研究
- 简单的用directshow播放一些视频和音频流的程序
- 安装程序检测到另一个程序要求计算机重启
- 检测到指定的WEB服务器运行的不是ASP.NET 1.1版,您无法运行ASP.NET应用程序或服务和创建ASP.NET程序时候发生错误 HTTP/1.0 500 Server Error的解决方法
- 多线程WIN32程序如何检查死锁(二)-检查死锁的策略
- 做一个检测钩子程序的工具
- 检测系统是否已经运行了相同的程序