-
大小: 5KB文件類型: .rar金幣: 2下載: 0 次發布日期: 2021-05-20
- 語言: C/C++
- 標簽: CTensorFLow??facenet??
資源簡介
c++簡單調用 facenet模型,并對比歐式距離.使用了opencv做人臉檢測.其中一些參數暫時寫死了.目前的效果一般般.因為 opencv對人臉的不同姿態檢測并不是太準.(暫時依賴于Qt的QString 和 QImage )

代碼片段和文件信息
#include?“TensorFlow.h“
CTensorFlow::CTensorFlow()
{
m_strxmlPath?=?“E:/SmartCity2015/AI/testTensorFlow/opencv/lib/haarcascade_frontalface_default.xml“;
}
CTensorFlow::~CTensorFlow()
{
}
bool?CTensorFlow::Create()
{
//? m_pLabel1?=?pLabel1;
//? m_pLabel2?=?pLabel2;
Scope?m_root?=?Scope::NewRootScope();
Status?status?=?NewSession(SessionOptions()?&m_pSession);//創建新會話Session
QString?strModelPath?=?“E:/SmartCity2015/AI/testTensorFlow/x64/Debug/20170512-110547.pb“;
GraphDef?graphdef;?//Graph?Definition?for?current?model
Status?status_load?=?ReadBinaryProto(Env::Default()?strModelPath.toStdString()?&graphdef);?//從pb文件中讀取圖模型;
if?(!status_load.ok())?{
std::cout?<“ERROR:?Loading?model?failed...“?< std::cout?< return?false;
}
Status?status_create?=?m_pSession->Create(graphdef);?//將模型導入會話Session中;
if?(!status_create.ok())?{
std::cout?<“ERROR:?Creating?graph?in?session?failed...“?< m_bIsSessionOk?=?false;
return?false;
}
cout?<“Session?successfully?created.“?<
m_bIsSessionOk?=?true;
return?true;
}
void?CTensorFlow::Destroy()
{
if?(m_pSession)
{
m_pSession->Close();
delete?m_pSession;
m_pSession?=?NULL;
}
m_bIsSessionOk?=?false;
}
int?CTensorFlow::Run(const?string&?strPicture1?const?string&?strPicture2?float&?fDistance?vector&?arrFaces1?vector&?arrFaces2)
{
if?(m_bIsSessionOk?==?false)
{
return?-1;
}
m_strPicture1?=?strPicture1;
m_strPicture2?=?strPicture2;
int?nHeight?=?160;
int?nWidth?=?160;
m_nTotalRecognition++;
Tensor?tensorPic1;
Tensor?tensorPic2;
bool?bRet?=?GetPicTensor(strPicture1?nHeight?nWidth?tensorPic1?arrFaces1);
if?(bRet?==?false)
{
m_nRecognitionFail++;
return?0;
}
bRet?=?GetPicTensor(strPicture2?nHeight?nWidth?tensorPic2?arrFaces2);
if?(bRet?==?false)
{
m_nRecognitionFail++;
return?0;
}
vector?arrData1;
GetValueFromTensor(tensorPic1?arrData1);
vector?arrData2;
GetValueFromTensor(tensorPic2?arrData2);
fDistance?=?Euclidean(arrData1?arrData2);
std::cout?<“Euclidean?fDistance:?“?<
if?(fDistance?>?m_fThreshold)
{
m_nMoreThenThreshold++;
}
return?1;
}
int?CTensorFlow::Run(const?unsigned?char*?pPictureData1?const?unsigned?char*?pPictureData2?float&?fDistance)
{
if?(m_bIsSessionOk?==?false)
{
return?-1;
}
int?nHeight?=?160;
int?nWidth?=?160;
Tensor?tensorPicture1;
Tensor?tensorPicture2;
bool?bRet?=?GetPicTensor(pPictureData1?nHeight?nWidth?tensorPicture1);
if?(bRet?==?false)
{
m_nRecognitionFail++;
return?0;
}
bRet?=?GetPicTensor(pPictureData2?nHeight?nWidth?tensorPicture2);
if?(bRet?==?false)
{
m_nRecognitionFail++;
return?0;
}
vector?arrData1;
GetValueFromTensor(tensorPicture1?
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????文件??????17626??2018-07-20?15:44??TensorFlow.cpp
?????文件???????3739??2018-07-20?15:40??TensorFlow.h
-----------?---------??----------?-----??----
????????????????21365????????????????????2
評論
共有 條評論