From: Alexander Alekhin Date: Thu, 2 Apr 2020 18:34:38 +0000 (+0000) Subject: Merge remote-tracking branch 'upstream/3.4' into merge-3.4 X-Git-Tag: submit/tizen/20210224.033012~2^2~245 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=cf2a3c8e7430cc92569dd7f114609f9377b12d9e;p=platform%2Fupstream%2Fopencv.git Merge remote-tracking branch 'upstream/3.4' into merge-3.4 --- cf2a3c8e7430cc92569dd7f114609f9377b12d9e diff --cc modules/core/src/ocl.cpp index 3301a7d,c6b6e2f..ec27879 --- a/modules/core/src/ocl.cpp +++ b/modules/core/src/ocl.cpp @@@ -4602,15 -4607,34 +4602,34 @@@ public return u; } + 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, int /*flags*/, UMatUsageFlags usageFlags, int& createFlags, int& flags0) const + 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(0); else flags0 = UMatData::COPY_ON_MAP; } diff --cc modules/imgcodecs/test/test_read_write.cpp index aefc2d5,c53cc5a..8345198 --- a/modules/imgcodecs/test/test_read_write.cpp +++ b/modules/imgcodecs/test/test_read_write.cpp @@@ -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 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 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) diff --cc modules/videoio/src/cap_msmf.cpp index 508f4a2,119873b..f1637ba --- a/modules/videoio/src/cap_msmf.cpp +++ b/modules/videoio/src/cap_msmf.cpp @@@ -1301,12 -1297,11 +1301,13 @@@ bool CvCapture_MSMF::setProperty( int p default: return false; } + case CV_CAP_PROP_FOURCC: - return configureOutput(newFormat, (int)cvRound(value), convertFormat); ++ 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) { @@@ -1339,9 -1334,11 +1340,9 @@@ 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: