Skip to content

Commit ceb6852

Browse files
committed
Merge remote-tracking branch 'upstream/3.4' into merge-3.4
2 parents f6a6e1f + 8fde8d7 commit ceb6852

File tree

2 files changed

+47
-12
lines changed

2 files changed

+47
-12
lines changed

.travis.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ compiler:
44
- clang
55
before_script:
66
- cd ../
7-
- git clone --depth=1 https://github.com/opencv/opencv.git
7+
- git clone --branch master --depth=1 https://github.com/opencv/opencv.git
88
- mkdir build-opencv
99
- cd build-opencv
1010
- cmake

modules/datasets/samples/pd_inria.cpp

+46-11
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,20 @@ using namespace cv::datasets;
1010
int main(int argc, char *argv[])
1111
{
1212
const char *keys =
13-
"{ help h usage ? | | show this message }"
14-
"{ path p |true| path to dataset }";
13+
"{ help h usage ? | | show this message }"
14+
"{ path p |true | path to dataset }"
15+
"{ save s |false| save resized positive images }"
16+
"{ rwidth rw |64 | width of resized positive images }"
17+
"{ rheight rh |128 | height of resized positive images }"
18+
"{ padding |8 | vertical padding of resized positive images }";
1519

1620
CommandLineParser parser(argc, argv, keys);
21+
bool savebbox = parser.get<bool>("save");
22+
int rwidth = parser.get<int>("rwidth");
23+
int rheight = parser.get<int>("rheight");
24+
int padding = parser.get<int>("padding");
1725
string path(parser.get<string>("path"));
26+
1827
if (parser.has("help") || path=="true")
1928
{
2029
parser.printMessage();
@@ -29,6 +38,8 @@ int main(int argc, char *argv[])
2938
cout << "train size: " << train_size << endl;
3039
cout << "test size: " << test_size << endl;
3140

41+
int bbox_count = 0;
42+
3243
for( size_t i = 0; i < train_size; i++ )
3344
{
3445
PD_inriaObj *example = static_cast<PD_inriaObj *>(dataset->getTrain()[i].get());
@@ -46,18 +57,42 @@ int main(int argc, char *argv[])
4657
// bounding boxes
4758
for ( size_t j = 0; j < example->bndboxes.size(); j++ )
4859
{
49-
cout << "object " << j << endl;
50-
int x = example->bndboxes[j].x;
51-
int y = example->bndboxes[j].y;
52-
cout << " - xmin = " << x << endl;
53-
cout << " - ymin = " << y << endl;
54-
cout << " - xmax = " << example->bndboxes[j].width + x << endl;
55-
cout << " - ymax = " << example->bndboxes[j].height + y << endl;
56-
rectangle( img, example->bndboxes[j], Scalar( 0, 0, 255 ), 2 );
60+
Rect obj_bndbox = example->bndboxes[j]; // bounding box of object
61+
cout << " - bounding box: " << j << " - " << obj_bndbox << endl;
62+
63+
int vpadding, hpadding;
64+
Rect ex_bndbox; // variable used for calculating expanded bounding box
65+
66+
vpadding = cvRound(padding * obj_bndbox.height / rheight); // calculate vertical padding
67+
ex_bndbox.y = obj_bndbox.y - vpadding;
68+
ex_bndbox.height = 2 * vpadding + obj_bndbox.height;
69+
ex_bndbox.x = obj_bndbox.x + (obj_bndbox.width / 2);
70+
ex_bndbox.width = ex_bndbox.height * rwidth / rheight;
71+
ex_bndbox.x -= (ex_bndbox.width + 1) / 2;
72+
73+
if (obj_bndbox.width > ex_bndbox.width)
74+
{
75+
obj_bndbox.x += (obj_bndbox.width - ex_bndbox.width + 1) / 2;
76+
obj_bndbox.width = ex_bndbox.width;
77+
}
78+
79+
hpadding = obj_bndbox.x - ex_bndbox.x; // calculate horizontal padding
80+
81+
if(savebbox)
82+
{
83+
Mat dst;
84+
copyMakeBorder(img(obj_bndbox), dst, vpadding, vpadding, hpadding, hpadding, BORDER_REFLECT);
85+
resize(dst, dst, Size(rwidth, rheight), 0, 0, INTER_AREA);
86+
imwrite(path + format("person_%04d.png", bbox_count++), dst);
87+
}
88+
else
89+
rectangle(img, obj_bndbox, Scalar(0, 0, 255), 2);
5790
}
5891

59-
imshow("INRIAPerson Dataset Train Images", img);
92+
if (savebbox)
93+
continue; // skip UI updates
6094

95+
imshow("INRIAPerson Dataset Train Images", img);
6196
cout << "\nPress a key to continue or ESC to exit." << endl;
6297
int key = waitKey();
6398
if( key == 27 ) break;

0 commit comments

Comments
 (0)