| 175 | return cv_img; |
| 176 | } |
| 177 | cv::Mat DecodeDatumToCVMat(const Datum& datum, bool is_color) { |
| 178 | cv::Mat cv_img; |
| 179 | CHECK(datum.encoded()) << "Datum not encoded"; |
| 180 | const string& data = datum.data(); |
| 181 | std::vector<char> vec_data(data.c_str(), data.c_str() + data.size()); |
| 182 | int cv_read_flag = (is_color ? CV_LOAD_IMAGE_COLOR : |
| 183 | CV_LOAD_IMAGE_GRAYSCALE); |
| 184 | cv_img = cv::imdecode(vec_data, cv_read_flag); |
| 185 | if (!cv_img.data) { |
| 186 | LOG(ERROR) << "Could not decode datum "; |
| 187 | } |
| 188 | return cv_img; |
| 189 | } |
| 190 | |
| 191 | // If Datum is encoded will decoded using DecodeDatumToCVMat and CVMatToDatum |
| 192 | // If Datum is not encoded will do nothing |