File: test_edgeboxes.cpp

package info (click to toggle)
opencv 4.5.1%2Bdfsg-5
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 268,248 kB
  • sloc: cpp: 969,170; xml: 682,525; python: 36,732; lisp: 30,170; java: 25,155; ansic: 7,927; javascript: 5,643; objc: 2,041; sh: 935; cs: 601; perl: 494; makefile: 145
file content (48 lines) | stat: -rw-r--r-- 2,089 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
// This file is part of OpenCV project.
// It is subject to the license terms in the LICENSE file found in the top-level directory
// of this distribution and at http://opencv.org/license.html.
#include "test_precomp.hpp"

namespace opencv_test { namespace {

TEST(ximgproc_Edgeboxes, regression)
{
    //Testing Edgeboxes implementation by asking for one proposal
    //on a simple test image from the PASCAL VOC 2012 dataset.
    std::vector<Rect> boxes;
    std::vector<float> scores;
    float expectedScore = 0.48742563f;
    Rect expectedProposal(158, 69, 125, 154);

    //Using sample model file, compute orientations map for use with edge detection.
    cv::String testImagePath = cvtest::TS::ptr()->get_data_path() + "cv/ximgproc/" + "pascal_voc_bird.png";
    Mat testImg = imread(testImagePath);
    ASSERT_FALSE(testImg.empty()) << "Could not load input image " << testImagePath;
    cvtColor(testImg, testImg, COLOR_BGR2RGB);
    testImg.convertTo(testImg, CV_32F, 1.0 / 255.0f);

    //Use the model for structured edge detection that is already provided in opencv_extra.
    cv::String model_path = cvtest::TS::ptr()->get_data_path() + "cv/ximgproc/" + "model.yml.gz";
    Ptr<StructuredEdgeDetection> sed = createStructuredEdgeDetection(model_path);
    Mat edgeImage, edgeOrientations;
    sed->detectEdges(testImg, edgeImage);
    sed->computeOrientation(edgeImage, edgeOrientations);

    //Obtain one proposal and its score from Edgeboxes.
    Ptr<EdgeBoxes> edgeboxes = createEdgeBoxes();
    edgeboxes->setMaxBoxes(1);
    edgeboxes->getBoundingBoxes(edgeImage, edgeOrientations, boxes, scores);

    //We asked for one proposal and thus one score, we better get one back only.
    ASSERT_TRUE(boxes.size() == 1);
    ASSERT_TRUE(scores.size() == 1);

    //Check the proposal and its score.
    EXPECT_NEAR(scores[0], expectedScore, 1e-8);
    EXPECT_EQ(expectedProposal.x, boxes[0].x);
    EXPECT_EQ(expectedProposal.y, boxes[0].y);
    EXPECT_EQ(expectedProposal.height, boxes[0].height);
    EXPECT_EQ(expectedProposal.width, boxes[0].width);
}

}} // namespace