模式识别 - 有害视频检测程序的策略
2014-05-22 19:39
239 查看
有害(色情\恐怖\暴力)视频, 严重危害网络的健康, 需要进行检测和过滤.
检测色情\恐怖视频, 通过检测程序, 检测出多个场景的概率, 然后进行排序, 当场景多余6个时, 只取最大的6个场景;
返回的概率值是前3个最大检测值场景的概率的均值;
色情\恐怖汇总时, 首先检测色情, 如果为色情视频, 则不进行恐怖的检测, 否则继续检测恐怖, 如果都不时, 则为未知视频.
代码:
[cpp] view plaincopy
#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;
}
检测色情\恐怖视频, 通过检测程序, 检测出多个场景的概率, 然后进行排序, 当场景多余6个时, 只取最大的6个场景;
返回的概率值是前3个最大检测值场景的概率的均值;
色情\恐怖汇总时, 首先检测色情, 如果为色情视频, 则不进行恐怖的检测, 否则继续检测恐怖, 如果都不时, 则为未知视频.
代码:
[cpp] view plaincopy
#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;
}
相关文章推荐
- 模式识别 - 有害视频检測程序的策略
- 模式识别 - 有害视频检测程序的策略
- window 7 运行asp.net程序出错-IIS7.0 检测到在集成的托管管道模式下不适用的ASP.NET设置 的解决方法
- 复杂事件模式检测策略小结
- 模式识别开发之项目---计算机视觉目标检测的框架与过程
- CSDN登陆校验码模式识别程序
- 模式识别之车牌识别---基于背景差分和邻帧检测
- 程序和行为模式识别技术
- CSDN登陆校验码模式识别程序
- 行人检测识别车载视频实测
- 我收集的一些目标检测、跟踪、识别标准测试视频集和图像数据库
- 【小程序】用策略模式完成自定义类的排序
- 简述C语言中的存储模式(字节顺序)以及程序检测
- 收集的一些目标检测、跟踪、识别标准测试视频集和图像数据库
- 跟我学设计模式视频教程——策略模式,命令模式
- DSP 实现模式识别小程序
- 特征检测、描述、匹配,视频跟踪,物体识别
- opencv实践程序3——打开摄像头视频及轮廓检测的简单程序
- OpenCV 实践程序12——用分类器对视频进行人脸检测
- 视频追踪之目标选择(一)------边缘检测值程序