test_edgeboxes.cpp 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  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. #include "test_precomp.hpp"
  5. namespace opencv_test { namespace {
  6. TEST(ximgproc_Edgeboxes, regression)
  7. {
  8. //Testing Edgeboxes implementation by asking for one proposal
  9. //on a simple test image from the PASCAL VOC 2012 dataset.
  10. std::vector<Rect> boxes;
  11. std::vector<float> scores;
  12. float expectedScore = 0.48742563f;
  13. Rect expectedProposal(158, 69, 125, 154);
  14. //Using sample model file, compute orientations map for use with edge detection.
  15. cv::String testImagePath = cvtest::TS::ptr()->get_data_path() + "cv/ximgproc/" + "pascal_voc_bird.png";
  16. Mat testImg = imread(testImagePath);
  17. ASSERT_FALSE(testImg.empty()) << "Could not load input image " << testImagePath;
  18. cvtColor(testImg, testImg, COLOR_BGR2RGB);
  19. testImg.convertTo(testImg, CV_32F, 1.0 / 255.0f);
  20. //Use the model for structured edge detection that is already provided in opencv_extra.
  21. cv::String model_path = cvtest::TS::ptr()->get_data_path() + "cv/ximgproc/" + "model.yml.gz";
  22. Ptr<StructuredEdgeDetection> sed = createStructuredEdgeDetection(model_path);
  23. Mat edgeImage, edgeOrientations;
  24. sed->detectEdges(testImg, edgeImage);
  25. sed->computeOrientation(edgeImage, edgeOrientations);
  26. //Obtain one proposal and its score from Edgeboxes.
  27. Ptr<EdgeBoxes> edgeboxes = createEdgeBoxes();
  28. edgeboxes->setMaxBoxes(1);
  29. edgeboxes->getBoundingBoxes(edgeImage, edgeOrientations, boxes, scores);
  30. //We asked for one proposal and thus one score, we better get one back only.
  31. ASSERT_TRUE(boxes.size() == 1);
  32. ASSERT_TRUE(scores.size() == 1);
  33. //Check the proposal and its score.
  34. EXPECT_NEAR(scores[0], expectedScore, 1e-8);
  35. EXPECT_EQ(expectedProposal.x, boxes[0].x);
  36. EXPECT_EQ(expectedProposal.y, boxes[0].y);
  37. EXPECT_EQ(expectedProposal.height, boxes[0].height);
  38. EXPECT_EQ(expectedProposal.width, boxes[0].width);
  39. }
  40. }} // namespace