Commit 8eebfa09227abc8f22699325fd3b8a5e326a857b
1 parent
806f710b
support storing floating-point data
Showing
1 changed file
with
13 additions
and
1 deletions
openbr/plugins/gallery/lmdb.cpp
| @@ -112,7 +112,19 @@ class lmdbGallery : public Gallery | @@ -112,7 +112,19 @@ class lmdbGallery : public Gallery | ||
| 112 | foreach(const Template &t, working) { | 112 | foreach(const Template &t, working) { |
| 113 | // add current image to transaction | 113 | // add current image to transaction |
| 114 | caffe::Datum datum; | 114 | caffe::Datum datum; |
| 115 | - caffe::CVMatToDatum(t.m(), &datum); | 115 | + |
| 116 | + const cv::Mat &m = t.m(); | ||
| 117 | + if (m.depth() == CV_32F) { | ||
| 118 | + datum.set_channels(m.channels()); | ||
| 119 | + datum.set_height(m.rows); | ||
| 120 | + datum.set_width(m.cols); | ||
| 121 | + for (int i=0; i<m.channels(); i++) // Follow Caffe's channel-major ordering convention | ||
| 122 | + for (int j=0; j<m.rows; j++) | ||
| 123 | + for (int k=0; k<m.cols; k++) | ||
| 124 | + datum.add_float_data(m.ptr<float>(j)[k*m.channels()+i]); | ||
| 125 | + } else { | ||
| 126 | + caffe::CVMatToDatum(m, &datum); | ||
| 127 | + } | ||
| 116 | 128 | ||
| 117 | QVariant base_label = t.file.value("Label"); | 129 | QVariant base_label = t.file.value("Label"); |
| 118 | QString label_str = base_label.toString(); | 130 | QString label_str = base_label.toString(); |