Commit 6ae9809b authored by RAJKIRAN NATARAJAN's avatar RAJKIRAN NATARAJAN Committed by Alexander Alekhin

Merge pull request #2178 from saskatchewancatch:opencv_contrib_edgeboxes_testimage

Add test for ximgproc/edgeboxes and fix up Python sample to work with returning scores

* Test for Edgeboxes implementation

* Fix and enhance edgeboxes_demo.py

* Make double literal a float literal

* Address review feedback
parent 91859e81
......@@ -27,10 +27,17 @@ if __name__ == '__main__':
edge_boxes = cv.ximgproc.createEdgeBoxes()
edge_boxes.setMaxBoxes(30)
boxes = edge_boxes.getBoundingBoxes(edges, orimap)
for b in boxes:
x, y, w, h = b
cv.rectangle(im, (x, y), (x+w, y+h), (0, 255, 0), 1, cv.LINE_AA)
boxes, scores = edge_boxes.getBoundingBoxes(edges, orimap)
if len(boxes) > 0:
boxes_scores = zip(boxes, scores)
for b_s in boxes_scores:
box = b_s[0]
x, y, w, h = box
cv.rectangle(im, (x, y), (x+w, y+h), (0, 255, 0), 1, cv.LINE_AA)
score = b_s[1][0]
cv.putText(im, "{:.2f}".format(score), (x, y), cv.FONT_HERSHEY_PLAIN, 0.8, (255, 255, 255), 1, cv.LINE_AA)
print("Box at (x,y)=({:d},{:d}); score={:f}".format(x, y, score))
cv.imshow("edges", edges)
cv.imshow("edgeboxes", im)
......
// 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(ximpgroc_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
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment