|
| 1 | +// This file is part of OpenCV project. |
| 2 | +// It is subject to the license terms in the LICENSE file found in the top-level directory |
| 3 | +// of this distribution and at http://opencv.org/license.html. |
| 4 | +// |
| 5 | +// Copyright (C) 2017, Intel Corporation, all rights reserved. |
| 6 | +// Third party copyrights are property of their respective owners. |
| 7 | + |
| 8 | +#include "test_precomp.hpp" |
| 9 | + |
| 10 | +namespace cvtest |
| 11 | +{ |
| 12 | + |
| 13 | +TEST(NMS, Accuracy) |
| 14 | +{ |
| 15 | + //reference results obtained using tf.image.non_max_suppression with iou_threshold=0.5 |
| 16 | + std::string dataPath = findDataFile("dnn/nms_reference.yml"); |
| 17 | + FileStorage fs(dataPath, FileStorage::READ); |
| 18 | + |
| 19 | + std::vector<Rect> bboxes; |
| 20 | + std::vector<float> scores; |
| 21 | + std::vector<int> ref_indices; |
| 22 | + |
| 23 | + fs["boxes"] >> bboxes; |
| 24 | + fs["probs"] >> scores; |
| 25 | + fs["output"] >> ref_indices; |
| 26 | + |
| 27 | + const float nms_thresh = .5f; |
| 28 | + const float score_thresh = .01f; |
| 29 | + std::vector<int> indices; |
| 30 | + cv::dnn::NMSBoxes(bboxes, scores, score_thresh, nms_thresh, indices); |
| 31 | + |
| 32 | + ASSERT_EQ(ref_indices.size(), indices.size()); |
| 33 | + |
| 34 | + std::sort(indices.begin(), indices.end()); |
| 35 | + std::sort(ref_indices.begin(), ref_indices.end()); |
| 36 | + |
| 37 | + for(size_t i = 0; i < indices.size(); i++) |
| 38 | + ASSERT_EQ(indices[i], ref_indices[i]); |
| 39 | +} |
| 40 | + |
| 41 | +}//cvtest |
0 commit comments