test_gdal.cpp 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  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. #include "test_common.hpp"
  6. namespace opencv_test { namespace {
  7. #ifdef HAVE_GDAL
  8. static void test_gdal_read(const string filename, bool required = true) {
  9. const string path = cvtest::findDataFile(filename);
  10. Mat img;
  11. ASSERT_NO_THROW(img = imread(path, cv::IMREAD_LOAD_GDAL | cv::IMREAD_ANYDEPTH | cv::IMREAD_ANYCOLOR));
  12. if(!required && img.empty())
  13. {
  14. throw SkipTestException("GDAL is built wihout required back-end support");
  15. }
  16. ASSERT_FALSE(img.empty());
  17. EXPECT_EQ(3, img.cols);
  18. EXPECT_EQ(5, img.rows);
  19. EXPECT_EQ(CV_MAKETYPE(CV_32F, 7), img.type());
  20. EXPECT_EQ(101.125, (img.at<Vec<float, 7>>(0, 0)[0]));
  21. EXPECT_EQ(203.500, (img.at<Vec<float, 7>>(2, 1)[3]));
  22. EXPECT_EQ(305.875, (img.at<Vec<float, 7>>(4, 2)[6]));
  23. }
  24. TEST(Imgcodecs_gdal, read_envi)
  25. {
  26. test_gdal_read("../cv/gdal/envi_test.raw");
  27. }
  28. TEST(Imgcodecs_gdal, read_fits)
  29. {
  30. // .fit test is optional because GDAL may be built wihtout CFITSIO library support
  31. test_gdal_read("../cv/gdal/fits_test.fit", false);
  32. }
  33. #endif // HAVE_GDAL
  34. }} // namespace