From cdb57cb679dac18154faeb5c5f4b84dfa7f5dd11 Mon Sep 17 00:00:00 2001 From: Suleyman TURKMEN Date: Mon, 7 Oct 2019 22:12:39 +0300 Subject: [PATCH 1/2] Update pd_inria.cpp --- modules/datasets/samples/pd_inria.cpp | 57 +++++++++++++++++++++------ 1 file changed, 46 insertions(+), 11 deletions(-) diff --git a/modules/datasets/samples/pd_inria.cpp b/modules/datasets/samples/pd_inria.cpp index da86e5ca8..4c823421b 100644 --- a/modules/datasets/samples/pd_inria.cpp +++ b/modules/datasets/samples/pd_inria.cpp @@ -10,11 +10,20 @@ using namespace cv::datasets; int main(int argc, char *argv[]) { const char *keys = - "{ help h usage ? | | show this message }" - "{ path p |true| path to dataset }"; + "{ help h usage ? | | show this message }" + "{ path p |true | path to dataset }" + "{ save s |false| save resized positive images }" + "{ rwidth rw |64 | width of resized positive images }" + "{ rheight rh |128 | height of resized positive images }" + "{ padding |8 | vertical padding of resized positive images }"; CommandLineParser parser(argc, argv, keys); + bool savebbox = parser.get("save"); + int rwidth = parser.get("rwidth"); + int rheight = parser.get("rheight"); + int padding = parser.get("padding"); string path(parser.get("path")); + if (parser.has("help") || path=="true") { parser.printMessage(); @@ -29,6 +38,8 @@ int main(int argc, char *argv[]) cout << "train size: " << train_size << endl; cout << "test size: " << test_size << endl; + int bbox_count = 0; + for( size_t i = 0; i < train_size; i++ ) { PD_inriaObj *example = static_cast(dataset->getTrain()[i].get()); @@ -46,18 +57,42 @@ int main(int argc, char *argv[]) // bounding boxes for ( size_t j = 0; j < example->bndboxes.size(); j++ ) { - cout << "object " << j << endl; - int x = example->bndboxes[j].x; - int y = example->bndboxes[j].y; - cout << " - xmin = " << x << endl; - cout << " - ymin = " << y << endl; - cout << " - xmax = " << example->bndboxes[j].width + x << endl; - cout << " - ymax = " << example->bndboxes[j].height + y << endl; - rectangle( img, example->bndboxes[j], Scalar( 0, 0, 255 ), 2 ); + Rect obj_bndbox = example->bndboxes[j]; // bounding box of object + cout << " - bounding box: " << j << " - " << obj_bndbox << endl; + + int vpadding, hpadding; + Rect ex_bndbox; // variable used for calculating expanded bounding box + + vpadding = cvRound(padding * obj_bndbox.height / rheight); // calculate vertical padding + ex_bndbox.y = obj_bndbox.y - vpadding; + ex_bndbox.height = 2 * vpadding + obj_bndbox.height; + ex_bndbox.x = obj_bndbox.x + (obj_bndbox.width / 2); + ex_bndbox.width = ex_bndbox.height * rwidth / rheight; + ex_bndbox.x -= (ex_bndbox.width + 1) / 2; + + if (obj_bndbox.width > ex_bndbox.width) + { + obj_bndbox.x += (obj_bndbox.width - ex_bndbox.width + 1) / 2; + obj_bndbox.width = ex_bndbox.width; + } + + hpadding = obj_bndbox.x - ex_bndbox.x; // calculate horizontal padding + + if(savebbox) + { + Mat dst; + copyMakeBorder(img(obj_bndbox), dst, vpadding, vpadding, hpadding, hpadding, BORDER_REFLECT); + resize(dst, dst, Size(rwidth, rheight), 0, 0, INTER_AREA); + imwrite(path + format("person_%04d.png", bbox_count++), dst); + } + else + rectangle(img, obj_bndbox, Scalar(0, 0, 255), 2); } - imshow("INRIAPerson Dataset Train Images", img); + if (savebbox) + continue; // skip UI updates + imshow("INRIAPerson Dataset Train Images", img); cout << "\nPress a key to continue or ESC to exit." << endl; int key = waitKey(); if( key == 27 ) break; From f48a0e8225035b73e3667929132128b1ed46a820 Mon Sep 17 00:00:00 2001 From: Suleyman TURKMEN Date: Sun, 13 Oct 2019 21:08:24 +0300 Subject: [PATCH 2/2] Update .travis.yml --- .travis.yml | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index 5c603efde..de69f1a5a 100644 --- a/.travis.yml +++ b/.travis.yml @@ -4,10 +4,15 @@ compiler: - clang before_script: - cd ../ - - git clone https://github.com/opencv/opencv.git + - git clone --branch 3.4 --depth=1 https://github.com/opencv/opencv.git - mkdir build-opencv - cd build-opencv - - cmake -DOPENCV_EXTRA_MODULES_PATH=../opencv_contrib/modules ../opencv + - cmake + -DBUILD_EXAMPLES=ON + -DBUILD_PERF_TESTS=OFF + -DBUILD_TESTS=OFF + -DOPENCV_EXTRA_MODULES_PATH=../opencv_contrib/modules + ../opencv script: - make -j5 notifications: