add test for feature extraction using CNN

pull/276/head
Wangyida 9 years ago
parent ba770cd524
commit a0d5630117
  1. 4
      modules/cnn_3dobj/README.md
  2. 70
      modules/cnn_3dobj/test/test_cnn_3dobj_feature_extract.cpp
  3. 3
      modules/cnn_3dobj/test/test_main.cpp
  4. 18
      modules/cnn_3dobj/test/test_precomp.hpp

@ -21,7 +21,7 @@ $ cmake -D CMAKE_INSTALL_PREFIX=/usr/local ..
$ make all -j4
$ sudo make install
```
###After all these steps, the headers and libs of CAFFE will be set on /usr/local/ path, and when you compiling opencv with opencv_contrib modules as below, the protobuf and caffe will be recognized as already installed while building. Protobuf is
###After all these steps, the headers and libs of CAFFE will be set on /usr/local/ path, and when you compiling opencv with opencv_contrib modules as below, the protobuf and caffe will be recognized as already installed while building. Protobuf is needed.
#Compiling OpenCV
```
@ -57,7 +57,7 @@ $ make
```
$ ./sphereview_test -plymodel=../3Dmodel/ape.ply -label_class=0
```
###press 'Q' to start 2D image genaration
###press 'Q' to start 2D image genaration
```
$ ./sphereview_test -plymodel=../3Dmodel/ant.ply -label_class=1
```

@ -0,0 +1,70 @@
/*
* Created on: Aug 14, 2015
* Author: yidawang
*/
#include "test_precomp.hpp"
using namespace cv;
using namespace cv::cnn_3dobj;
class CV_CNN_Feature_Test : public cvtest::BaseTest
{
public:
CV_CNN_Feature_Test();
protected:
void run(int);
};
CV_CNN_Feature_Test::CV_CNN_Feature_Test()
{
}
/**
* This test checks the following:
* Feature extraction by the triplet trained CNN model
*/
void CV_CNN_Feature_Test::run(int)
{
string caffemodel = ts->get_data_path() + "cnn_3dobj/samples/data/3d_triplet_iter_20000.caffemodel";
string network_forIMG = ts->get_data_path() + "cnn_3dobj/samples/data/3d_triplet_testIMG.prototxt";
string mean_file = "no";
string target_img = ts->get_data_path() + "cnn_3dobj/samples/data/images_all/2_24.png";
string feature_blob = "feat";
string device = "CPU";
int dev_id = 0;
cv::cnn_3dobj::descriptorExtractor descriptor;
bool set_succeed = descriptor.setNet(device, dev_id);
if (!set_succeed) {
ts->printf(cvtest::TS::LOG, "Net parameters which is GPU or CPU could not be set");
ts->set_failed_test_info(cvtest::TS::FAIL_MISSING_TEST_DATA);
return;
}
int net_ready;
if (strcmp(mean_file.c_str(), "no") == 0)
net_ready = descriptor.loadNet(set_succeed, network_forIMG, caffemodel);
else
net_ready = descriptor.loadNet(set_succeed, network_forIMG, caffemodel, mean_file);
if (!net_ready) {
ts->printf(cvtest::TS::LOG, "No model loaded");
ts->set_failed_test_info(cvtest::TS::FAIL_MISSING_TEST_DATA);
return;
}
cv::Mat img = cv::imread(target_img, -1);
if (img.empty()) {
ts->printf(cvtest::TS::LOG, "could not read image %s\n", target_img.c_str());
ts->set_failed_test_info(cvtest::TS::FAIL_MISSING_TEST_DATA);
return;
}
cv::Mat feature_test;
descriptor.extract(net_ready, img, feature_test, feature_blob);
if (feature_test.empty()) {
ts->printf(cvtest::TS::LOG, "could not extract feature from image %s\n", target_img.c_str());
ts->set_failed_test_info(cvtest::TS::FAIL_MISSING_TEST_DATA);
return;
}
}
TEST(VIDEO_BGSUBGMG, accuracy) { CV_CNN_Feature_Test test; test.safe_run(); }

@ -0,0 +1,3 @@
#include "test_precomp.hpp"
CV_TEST_MAIN("cv")

@ -0,0 +1,18 @@
#ifdef __GNUC__
# pragma GCC diagnostic ignored "-Wmissing-declarations"
# if defined __clang__ || defined __APPLE__
# pragma GCC diagnostic ignored "-Wmissing-prototypes"
# pragma GCC diagnostic ignored "-Wextra"
# endif
#endif
#ifndef __OPENCV_TEST_PRECOMP_HPP__
#define __OPENCV_TEST_PRECOMP_HPP__
#include <iostream>
#include "opencv2/ts.hpp"
#include "opencv2/imgproc.hpp"
#include "opencv2/cnn_3dobj_config.hpp"
#include "opencv2/cnn_3dobj.hpp"
#endif
Loading…
Cancel
Save