Skip to content

Commit

Permalink
修改了接口
Browse files Browse the repository at this point in the history
  • Loading branch information
tkorays committed May 22, 2014
1 parent e3a63af commit c1ef3cd
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 34 deletions.
33 changes: 1 addition & 32 deletions FaceStorage_Test/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,41 +75,10 @@ void fr_test() {
// 识别
int rt = fr.pridect(imread(dir+"xuzhibo/small/6.jpg",CV_LOAD_IMAGE_GRAYSCALE));
// CvFrAdapter的FaceStorage是public的,可以使用其读取name
cout << "这个人是:" << cvfr.fs.getNameById(rt)<<"(加载文件法不能直接获得名字),其id是:"<< rt << endl;
cout << "这个人是:" << fr.getNameById(rt)<<"(加载文件法不能直接获得名字),其id是:"<< rt << endl;
}

void generate_xml_file() {
string dir = "E:/BigData/face_data/";
FaceStorage fs;
Face face;
face.addImage(dir + "xuzhibo/small/" + "1.jpg");
face.addImage(dir + "xuzhibo/small/" + "2.jpg");
face.addImage(dir + "xuzhibo/small/" + "3.jpg");
face.addImage(dir + "xuzhibo/small/" + "4.jpg");
face.addImage(dir + "xuzhibo/small/" + "5.jpg");
face.updata(1, "徐志博");
fs << face;

face.clearImages();
face.addImage(dir + "lyq/small/" + "1.jpg");
face.addImage(dir + "lyq/small/" + "2.jpg");
face.addImage(dir + "lyq/small/" + "3.jpg");
face.addImage(dir + "lyq/small/" + "4.jpg");
face.addImage(dir + "lyq/small/" + "5.jpg");
face.updata(2, "凌永清");
fs << face;

face.clearImages();
face.addImage(dir + "xujian/small/" + "1.jpg");
face.addImage(dir + "xujian/small/" + "2.jpg");
face.addImage(dir + "xujian/small/" + "3.jpg");
face.addImage(dir + "xujian/small/" + "4.jpg");
face.addImage(dir + "xujian/small/" + "5.jpg");
face.updata(2, "许剑");
fs << face;

fs.save(dir + "face_list.xml");
}
int main() {
fr_test();
//generate_xml_file();
Expand Down
12 changes: 12 additions & 0 deletions face.sln
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ VisualStudioVersion = 12.0.21005.1
MinimumVisualStudioVersion = 10.0.40219.1
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "FaceStorage_Test", "FaceStorage_Test\FaceStorage_Test.vcxproj", "{1BB4787D-D212-46A7-B06F-FFE847A5BBE0}"
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "generate_face_file", "generate_face_file\generate_face_file.vcxproj", "{E8F385A7-BDE2-446A-B73C-BE132263252F}"
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "face_recog_demo", "face_recog_demo\face_recog_demo.vcxproj", "{441B9F9D-9738-4AAB-84A7-2799A004041E}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Win32 = Debug|Win32
Expand All @@ -15,6 +19,14 @@ Global
{1BB4787D-D212-46A7-B06F-FFE847A5BBE0}.Debug|Win32.Build.0 = Debug|Win32
{1BB4787D-D212-46A7-B06F-FFE847A5BBE0}.Release|Win32.ActiveCfg = Release|Win32
{1BB4787D-D212-46A7-B06F-FFE847A5BBE0}.Release|Win32.Build.0 = Release|Win32
{E8F385A7-BDE2-446A-B73C-BE132263252F}.Debug|Win32.ActiveCfg = Debug|Win32
{E8F385A7-BDE2-446A-B73C-BE132263252F}.Debug|Win32.Build.0 = Debug|Win32
{E8F385A7-BDE2-446A-B73C-BE132263252F}.Release|Win32.ActiveCfg = Release|Win32
{E8F385A7-BDE2-446A-B73C-BE132263252F}.Release|Win32.Build.0 = Release|Win32
{441B9F9D-9738-4AAB-84A7-2799A004041E}.Debug|Win32.ActiveCfg = Debug|Win32
{441B9F9D-9738-4AAB-84A7-2799A004041E}.Debug|Win32.Build.0 = Debug|Win32
{441B9F9D-9738-4AAB-84A7-2799A004041E}.Release|Win32.ActiveCfg = Release|Win32
{441B9F9D-9738-4AAB-84A7-2799A004041E}.Release|Win32.Build.0 = Release|Win32
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
3 changes: 2 additions & 1 deletion face/CvFrAdapter.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,13 @@ class CvFrAdapter : public FrAdapter {
string face_storage_file; // 用于保存图片
string trained_file; // 训练好的参数
Ptr<FaceRecognizer> Fr;
public:
FaceStorage fs;
public:
CvFrAdapter();
void init();
bool train();
int pridect(Mat img);
string getNameById(int id);

void setFaceStorage(const string fn);
void loadTrainedFile(const string fn);
Expand Down
3 changes: 3 additions & 0 deletions face/CvFrAdapter_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,5 +55,8 @@ void CvFrAdapter::save(const string fn) {
void CvFrAdapter::load(const string fn) {
Fr->load(fn);
}
string CvFrAdapter::getNameById(int id) {
return fs.getNameById(id);
}

#endif // _TK_CVFRADAPTER_IMPL_H_
2 changes: 1 addition & 1 deletion face/FaceRecog.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class FaceRecog {
void setFrClass(FrAdapter* fr);
bool train();
int pridect(cv::Mat img);

string getNameById(int id);
};

#include "FaceRecog_impl.h"
Expand Down
3 changes: 3 additions & 0 deletions face/FaceRecog_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,8 @@ bool FaceRecog::train() {
int FaceRecog::pridect(Mat img) {
return Fr->pridect(img);
}
string FaceRecog::getNameById(int id) {
return Fr->getNameById(id);
}

#endif // _TK_FACERECOG_IMPL_H_
1 change: 1 addition & 0 deletions face/FrAdapter.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ class FrAdapter {
virtual void init() = 0;
virtual bool train() = 0;
virtual int pridect(cv::Mat img) = 0;
virtual string getNameById(int id) = 0;
};

#endif // _TK_FRADAPTER_H_

0 comments on commit c1ef3cd

Please sign in to comment.