Changed variable name: iscolor to is_color.

This commit is contained in:
Jerod Weinman 2014-06-08 15:46:23 -05:00
Родитель d21da02474
Коммит 781761eb74
3 изменённых файлов: 10 добавлений и 9 удалений

Просмотреть файл

@ -61,7 +61,7 @@ inline void WriteProtoToBinaryFile(
} }
bool ReadImageToDatum(const string& filename, const int label, bool ReadImageToDatum(const string& filename, const int label,
const int height, const int width, const bool iscolor, Datum* datum); const int height, const int width, const bool is_color, Datum* datum);
inline bool ReadImageToDatum(const string& filename, const int label, inline bool ReadImageToDatum(const string& filename, const int label,
const int height, const int width, Datum* datum) { const int height, const int width, Datum* datum) {

Просмотреть файл

@ -72,9 +72,10 @@ void WriteProtoToBinaryFile(const Message& proto, const char* filename) {
} }
bool ReadImageToDatum(const string& filename, const int label, bool ReadImageToDatum(const string& filename, const int label,
const int height, const int width, const bool iscolor, Datum* datum) { const int height, const int width, const bool is_color, Datum* datum) {
cv::Mat cv_img; cv::Mat cv_img;
int cv_read_flag = (iscolor ? CV_LOAD_IMAGE_COLOR : CV_LOAD_IMAGE_GRAYSCALE); int cv_read_flag = (is_color ? CV_LOAD_IMAGE_COLOR :
CV_LOAD_IMAGE_GRAYSCALE);
if (height > 0 && width > 0) { if (height > 0 && width > 0) {
cv::Mat cv_img_origin = cv::imread(filename, cv_read_flag); cv::Mat cv_img_origin = cv::imread(filename, cv_read_flag);
cv::resize(cv_img_origin, cv_img, cv::Size(height, width)); cv::resize(cv_img_origin, cv_img, cv::Size(height, width));
@ -85,7 +86,7 @@ bool ReadImageToDatum(const string& filename, const int label,
LOG(ERROR) << "Could not open or find file " << filename; LOG(ERROR) << "Could not open or find file " << filename;
return false; return false;
} }
int num_channels = (iscolor ? 3 : 1); int num_channels = (is_color ? 3 : 1);
datum->set_channels(num_channels); datum->set_channels(num_channels);
datum->set_height(cv_img.rows); datum->set_height(cv_img.rows);
datum->set_width(cv_img.cols); datum->set_width(cv_img.cols);
@ -93,7 +94,7 @@ bool ReadImageToDatum(const string& filename, const int label,
datum->clear_data(); datum->clear_data();
datum->clear_float_data(); datum->clear_float_data();
string* datum_string = datum->mutable_data(); string* datum_string = datum->mutable_data();
if (iscolor) { if (is_color) {
for (int c = 0; c < num_channels; ++c) { for (int c = 0; c < num_channels; ++c) {
for (int h = 0; h < cv_img.rows; ++h) { for (int h = 0; h < cv_img.rows; ++h) {
for (int w = 0; w < cv_img.cols; ++w) { for (int w = 0; w < cv_img.cols; ++w) {
@ -102,7 +103,7 @@ bool ReadImageToDatum(const string& filename, const int label,
} }
} }
} }
} else { // Faster than repeatedly testing iscolor for each pixel w/i loop } else { // Faster than repeatedly testing is_color for each pixel w/i loop
for (int h = 0; h < cv_img.rows; ++h) { for (int h = 0; h < cv_img.rows; ++h) {
for (int w = 0; w < cv_img.cols; ++w) { for (int w = 0; w < cv_img.cols; ++w) {
datum_string->push_back( datum_string->push_back(

Просмотреть файл

@ -45,8 +45,8 @@ int main(int argc, char** argv) {
} }
// Test whether argv[1] == "-g" // Test whether argv[1] == "-g"
bool iscolor= !(string("-g") == string(argv[1])); bool is_color= !(string("-g") == string(argv[1]));
int arg_offset = (iscolor ? 0 : 1); int arg_offset = (is_color ? 0 : 1);
std::ifstream infile(argv[arg_offset+2]); std::ifstream infile(argv[arg_offset+2]);
std::vector<std::pair<string, int> > lines; std::vector<std::pair<string, int> > lines;
string filename; string filename;
@ -89,7 +89,7 @@ int main(int argc, char** argv) {
bool data_size_initialized = false; bool data_size_initialized = false;
for (int line_id = 0; line_id < lines.size(); ++line_id) { for (int line_id = 0; line_id < lines.size(); ++line_id) {
if (!ReadImageToDatum(root_folder + lines[line_id].first, if (!ReadImageToDatum(root_folder + lines[line_id].first,
lines[line_id].second, resize_height, resize_width, iscolor, &datum)) { lines[line_id].second, resize_height, resize_width, is_color, &datum)) {
continue; continue;
} }
if (!data_size_initialized) { if (!data_size_initialized) {