1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65
|
Classify {#tutorial_feature_classification}
===============
Goal
----
In this tutorial you will learn how to
- How to extract feature from an image
- How to extract features from images under a given root path
- How to make a prediction using reference images and target image
Code
----
@include cnn_3dobj/samples/classify.cpp
Explanation
-----------
Here is the general structure of the program:
- Initialize a net work with Device.
@code{.cpp}
cv::cnn_3dobj::descriptorExtractor descriptor(device);
@endcode
- Load net with the caffe trained net work parameter and structure.
@code{.cpp}
if (strcmp(mean_file.c_str(), "no") == 0)
descriptor.loadNet(network_forIMG, caffemodel);
else
descriptor.loadNet(network_forIMG, caffemodel, mean_file);
@endcode
- List the file names under a given path.
@code{.cpp}
listDir(src_dir.c_str(), name_gallery, false);
for (unsigned int i = 0; i < name_gallery.size(); i++)
{
name_gallery[i] = src_dir + name_gallery[i];
}
@endcode
- Extract feature from a set of images.
@code{.cpp}
descriptor.extract(img_gallery, feature_reference, feature_blob);
@endcode
- Initialize a matcher which using L2 distance.
@code{.cpp}
cv::BFMatcher matcher(NORM_L2);
std::vector<std::vector<cv::DMatch> > matches;
@endcode
- Have a KNN match on the target and reference images.
@code{.cpp}
matcher.knnMatch(feature_test, feature_reference, matches, num_candidate);
@endcode
- Print features of the reference images.
@code{.cpp}std::cout << std::endl << "---------- Features of target image: " << target_img << "----------" << endl << feature_test << std::endl;
@endcode
Results
-------
|