Skip to content

Commit

Permalink
change im2rec
Browse files Browse the repository at this point in the history
  • Loading branch information
winstywang committed May 6, 2015
1 parent c9dab91 commit ebfdc58
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions tools/im2rec.cc
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ int main(int argc, char *argv[]) {
}
}
if (new_size > 0) {
LOG(INFO) << "New Image Size: " << new_size << "x" << new_size;
LOG(INFO) << "New Image Size: Short Edge " << new_size;
} else {
LOG(INFO) << "Keep origin image size";
}
Expand All @@ -56,7 +56,7 @@ int main(int argc, char *argv[]) {
std::vector<unsigned char> encode_buf;
std::vector<int> encode_params;
encode_params.push_back(CV_IMWRITE_JPEG_QUALITY);
encode_params.push_back(100);
encode_params.push_back(80);
while (is >> rec.header.image_id[0] >> rec.header.label) {
for (int k = 1; k < label_width; ++ k) {
float tmp;
Expand Down Expand Up @@ -85,8 +85,13 @@ int main(int argc, char *argv[]) {
CHECK(img.data != NULL) << "OpenCV decode fail:" << path;
cv::Mat res;
if (new_size > 0) {
cv::resize(img, res, cv::Size(new_size, new_size),
0, 0, CV_INTER_CUBIC);
if (img.rows > img.cols) {
cv::resize(img, res, cv::Size(img.rows * new_size / img.cols,
new_size), 0, 0, CV_INTER_LINEAR);
} else {
cv::resize(img, res, cv::Size(new_size, new_size * img.cols
/ img.rows), 0, 0, CV_INTER_LINEAR);
d }
} else {
res = img;
}
Expand Down

0 comments on commit ebfdc58

Please sign in to comment.