test_structured_edge_detection.cpp 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  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_StructuredEdgeDetection, regression)
  7. {
  8. cv::String subfolder = "cv/ximgproc/";
  9. cv::String dir = cvtest::TS::ptr()->get_data_path() + subfolder;
  10. int nTests = 12;
  11. float threshold = 0.01f;
  12. cv::String modelName = dir + "model.yml.gz";
  13. cv::Ptr<cv::ximgproc::StructuredEdgeDetection> pDollar =
  14. cv::ximgproc::createStructuredEdgeDetection(modelName);
  15. for (int i = 0; i < nTests; ++i)
  16. {
  17. cv::String srcName = dir + cv::format( "sources/%02d.png", i + 1);
  18. cv::Mat src = cv::imread( srcName, 1 );
  19. ASSERT_TRUE(!src.empty());
  20. cv::String previousResultName = dir + cv::format( "results/%02d.png", i + 1 );
  21. cv::Mat previousResult = cv::imread( previousResultName, 0 );
  22. previousResult.convertTo( previousResult, CV_32F, 1/255.0 );
  23. src.convertTo( src, CV_32F, 1/255.0 );
  24. cv::Mat currentResult( src.size(), src.type() );
  25. pDollar->detectEdges( src, currentResult );
  26. cv::Mat sqrError = ( currentResult - previousResult )
  27. .mul( currentResult - previousResult );
  28. cv::Scalar mse = cv::sum(sqrError) / cv::Scalar::all( double( sqrError.total() ) );
  29. EXPECT_LE( mse[0], threshold );
  30. }
  31. }
  32. }} // namespace