Merge remote-tracking branch 'upstream/3.4' into merge-3.4
authorAlexander Alekhin <alexander.a.alekhin@gmail.com>
Thu, 2 Apr 2020 18:34:38 +0000 (18:34 +0000)
committerAlexander Alekhin <alexander.a.alekhin@gmail.com>
Thu, 2 Apr 2020 21:52:32 +0000 (21:52 +0000)
1  2 
modules/core/src/ocl.cpp
modules/imgcodecs/test/test_read_write.cpp
modules/imgproc/test/test_imgwarp.cpp
modules/stitching/src/seam_finders.cpp
modules/videoio/src/cap_msmf.cpp

@@@ -4602,15 -4607,34 +4602,34 @@@ public
          return u;
      }
  
 -    void getBestFlags(const Context& ctx, int /*flags*/, UMatUsageFlags usageFlags, int& createFlags, int& flags0) const
+     static bool isOpenCLMapForced()  // force clEnqueueMapBuffer / clEnqueueUnmapMemObject OpenCL API
+     {
+         static bool value = cv::utils::getConfigurationParameterBool("OPENCV_OPENCL_BUFFER_FORCE_MAPPING", false);
+         return value;
+     }
+     static bool isOpenCLCopyingForced()  // force clEnqueueReadBuffer[Rect] / clEnqueueWriteBuffer[Rect] OpenCL API
+     {
+         static bool value = cv::utils::getConfigurationParameterBool("OPENCV_OPENCL_BUFFER_FORCE_COPYING", false);
+         return value;
+     }
 +    void getBestFlags(const Context& ctx, AccessFlag /*flags*/, UMatUsageFlags usageFlags, int& createFlags, UMatData::MemoryFlag& flags0) const
      {
          const Device& dev = ctx.device(0);
          createFlags = 0;
          if ((usageFlags & USAGE_ALLOCATE_HOST_MEMORY) != 0)
              createFlags |= CL_MEM_ALLOC_HOST_PTR;
  
-         if( dev.hostUnifiedMemory() )
+         if (!isOpenCLCopyingForced() &&
+             (isOpenCLMapForced() ||
+                 (dev.hostUnifiedMemory()
+ #ifndef __APPLE__
+                 || dev.isIntel()
+ #endif
+                 )
+             )
+         )
 -            flags0 = 0;
 +            flags0 = static_cast<UMatData::MemoryFlag>(0);
          else
              flags0 = UMatData::COPY_ON_MAP;
      }
@@@ -210,6 -171,90 +172,98 @@@ const string exts[] = 
  #endif
  };
  
+ static
+ void test_image_io(const Mat& image, const std::string& fname, const std::string& ext, int imreadFlag, double psnrThreshold)
+ {
+     vector<uchar> buf;
+     ASSERT_NO_THROW(imencode("." + ext, image, buf));
+     ASSERT_NO_THROW(imwrite(fname, image));
+     FILE *f = fopen(fname.c_str(), "rb");
+     fseek(f, 0, SEEK_END);
+     long len = ftell(f);
+     cout << "File size: " << len << " bytes" << endl;
+     EXPECT_GT(len, 1024) << "File is small. Test or implementation is broken";
+     fseek(f, 0, SEEK_SET);
+     vector<uchar> file_buf((size_t)len);
+     EXPECT_EQ(len, (long)fread(&file_buf[0], 1, (size_t)len, f));
+     fclose(f); f = NULL;
+     EXPECT_EQ(buf, file_buf) << "imwrite() / imencode() calls must provide the same output (bit-exact)";
+     Mat buf_loaded = imdecode(Mat(buf), imreadFlag);
+     EXPECT_FALSE(buf_loaded.empty());
+     Mat loaded = imread(fname, imreadFlag);
+     EXPECT_FALSE(loaded.empty());
+     EXPECT_EQ(0, cv::norm(loaded, buf_loaded, NORM_INF)) << "imread() and imdecode() calls must provide the same result (bit-exact)";
+     double psnr = cvtest::PSNR(loaded, image);
+     EXPECT_GT(psnr, psnrThreshold);
+     // not necessary due bitexact check above
+     //double buf_psnr = cvtest::PSNR(buf_loaded, image);
+     //EXPECT_GT(buf_psnr, psnrThreshold);
+ #if 0  // debug
+     if (psnr <= psnrThreshold /*|| buf_psnr <= thresDbell*/)
+     {
+         cout << "File: " << fname << endl;
+         imshow("origin", image);
+         imshow("imread", loaded);
+         imshow("imdecode", buf_loaded);
+         waitKey();
+     }
+ #endif
+ }
+ TEST_P(Imgcodecs_Image, read_write_BGR)
+ {
+     const string ext = this->GetParam();
+     const string fname = cv::tempfile(ext.c_str());
+     double psnrThreshold = 100;
+     if (ext == "jpg")
+         psnrThreshold = 32;
++#ifdef HAVE_JASPER
++    if (ext == "jp2")
++        psnrThreshold = 95;
++#endif
+     Mat image = generateTestImageBGR();
+     EXPECT_NO_THROW(test_image_io(image, fname, ext, IMREAD_COLOR, psnrThreshold));
+     EXPECT_EQ(0, remove(fname.c_str()));
+ }
+ TEST_P(Imgcodecs_Image, read_write_GRAYSCALE)
+ {
+     const string ext = this->GetParam();
+     if (false
+         || ext == "ppm"  // grayscale is not implemented
+         || ext == "ras"  // broken (black result)
+     )
+         throw SkipTestException("GRAYSCALE mode is not supported");
+     const string fname = cv::tempfile(ext.c_str());
+     double psnrThreshold = 100;
+     if (ext == "jpg")
+         psnrThreshold = 40;
++#ifdef HAVE_JASPER
++    if (ext == "jp2")
++        psnrThreshold = 70;
++#endif
+     Mat image = generateTestImageGrayscale();
+     EXPECT_NO_THROW(test_image_io(image, fname, ext, IMREAD_GRAYSCALE, psnrThreshold));
+     EXPECT_EQ(0, remove(fname.c_str()));
+ }
  INSTANTIATE_TEST_CASE_P(imgcodecs, Imgcodecs_Image, testing::ValuesIn(exts));
  
  TEST(Imgcodecs_Image, regression_9376)
Simple merge
@@@ -1301,12 -1297,11 +1301,13 @@@ bool CvCapture_MSMF::setProperty( int p
              default:
                  return false;
              }
-             return configureOutput(newFormat, (int)cvRound(value), convertFormat);
 +        case CV_CAP_PROP_FOURCC:
++            return configureOutput(newFormat, (int)cvRound(value));
          case CV_CAP_PROP_FORMAT:
-             return configureOutput(newFormat, (int)cvRound(value), convertFormat);
+             return configureOutput(newFormat, (int)cvRound(value));
          case CV_CAP_PROP_CONVERT_RGB:
-             return configureOutput(newFormat, outputFormat, value != 0);
+             convertFormat = (value != 0);
+             return configureOutput(newFormat, outputFormat);
          case CV_CAP_PROP_SAR_NUM:
              if (value > 0)
              {
              if (value >= 0)
              {
                  newFormat.setFramerate(value);
-                 return configureOutput(newFormat, outputFormat, convertFormat);
+                 return configureOutput(newFormat, outputFormat);
              }
              break;
 -            case CV_CAP_PROP_FOURCC:
 -                break;
          case CV_CAP_PROP_FRAME_COUNT:
              break;
          case CV_CAP_PROP_POS_AVI_RATIO: