周五晚上十二点接到这个任务,周六下午刷qq 看到老师的留言。要求周一交一个版本
开始理解的是要交一个windows 版本的,后来发现是要交一个linux 版本的--坑。
然后我在网上找到微软发布的windows-caffe 下载下来 然后也下载了第三方库
想法是我先生成一个libcaffe 的.dll 文件 然后在imageclasssifaction 下面调用
检测的话使用opencv 版本的或者之前LZ的版本 都ok
周六下午下载下来windows 版本的caffe 后,在生成libcaffe 的时候 卡在下载第三方库的地方 一直卡着不动
在网上百度了方法。---后来最后的方法是找zl 要了一打包的版本。
目测打包caffe 已经不像去年那么麻烦,已经有比较现成可以借鉴的方案 大概会是一天的工作量的样子
void * handle = FGV_Init("CPU");
这句话实现在:
int m_FGV::Init(string mode)
{
TimeCheck();
cout << "come here" << endl;
//face extract model Init
string protoArray = "LightenedCNN_B_deploy.prototxt";
ctools = Ctools_Init(mode, protoArray, "LightenedCNN_B.caffemodel", 0);
if (ctools == NULL || !TimeCheck())
{
printf("feature extract handle init failed!");
return -1;
}
return 1;
}
这个有三个作用
A. 使用CPU 或者是使用gpu
B. 传入deploy 文件和caffemodel 文件
deploy 文件的传输方式有2种
一种是通过vector
一种是通过路径 本文采用的是直接传入路径的方式
注意事项:
deploy 文件的格式为:
这是与matlab 的使用是不一样的。
特征提取部分为:
double m_FGV::Extraction_Feature(cv::Mat img, double * feature)
{
imshow("imgimg", img);
waitKey(0);
//CTOOLS_Result * result = new CTOOLS_Result;
cout << "img.channels()" << img.channels() << endl;
Ctools_ClassifyAndFeaExtract(ctools, img.data, img.cols, img.rows, img.channels(),NULL,feature, "LAST");
cout << feature << " ";
return 0;
//printf("index = %d, prob = %f\n", result->index, result->maxprob);
//return feature;
}
可以发现 最重要的是函数:
FUNCTION: Ctools_ClassifyAndFeaExtract
* PURPOSE: 分类预测&&提取特征
* PARAM:
[in] tools - 操作句柄
[in] imgdata - 图像数据
[in] width - 图像宽度
[in] height - 图像高度
[in] channels - 图像通道数
[in] result - 分类预测结果 注:result = NULL->不进行分类预测; 目前分类预测结果只取最后一层的结果。
[in] feature - 提取特征结果 注:feature = NULL->不进行特征提取
[in] layer - 提取指定层特征 注:feature = last->最后一层提取特征(对特征提取生效)
[in] datapreprocess- 数据预处理 注:datapreprocess = NULL->不进行预处理(对特征提取和分类生效)
* RETURN: 0: 处理失败; 1: 处理成功; -1: 图像数据出错。
* NOTES:
*************************************************************************/
LIBUCTOOLS_API int Ctools_ClassifyAndFeaExtract(void * tools, unsigned char * imgdata, int width, int height, int channels,CTOOLS_Result * result = NULL, double *feature = NULL, string layer = "last", preprocess datapreprocess = NULL);