Commit cf2a3c8e authored by Alexander Alekhin's avatar Alexander Alekhin

Merge remote-tracking branch 'upstream/3.4' into merge-3.4

parents 277f0d27 6216bf92
......@@ -146,6 +146,141 @@ OCL_PERF_TEST_P(CopyToFixture, CopyToWithMaskUninit,
SANITY_CHECK(dst);
}
enum ROIType {
ROI_FULL,
ROI_2_RECT,
ROI_2_TOP, // contiguous memory block
ROI_2_LEFT,
ROI_4,
ROI_16,
};
static Rect getROI(enum ROIType t, const Size& sz)
{
switch (t)
{
case ROI_FULL: return Rect(0, 0, sz.width, sz.height);
case ROI_2_RECT: return Rect(0, 0, sz.width * 71 / 100, sz.height * 71 / 100); // 71 = sqrt(1/2) * 100
case ROI_2_TOP: return Rect(0, 0, sz.width, sz.height / 2); // 71 = sqrt(1/2) * 100
case ROI_2_LEFT: return Rect(0, 0, sz.width / 2, sz.height); // 71 = sqrt(1/2) * 100
case ROI_4: return Rect(0, 0, sz.width / 2, sz.height / 2);
case ROI_16: return Rect(0, 0, sz.width / 4, sz.height / 4);
}
CV_Assert(false);
}
typedef TestBaseWithParam< tuple<cv::Size, MatType, ROIType> > OpenCLBuffer;
static inline void PrintTo(const tuple<cv::Size, MatType, enum ROIType>& v, std::ostream* os)
{
*os << "(" << get<0>(v) << ", " << typeToString(get<1>(v)) << ", ";
enum ROIType roiType = get<2>(v);
if (roiType == ROI_FULL)
*os << "ROI_100_FULL";
else if (roiType == ROI_2_RECT)
*os << "ROI_050_RECT_HALF";
else if (roiType == ROI_2_TOP)
*os << "ROI_050_TOP_HALF";
else if (roiType == ROI_2_LEFT)
*os << "ROI_050_LEFT_HALF";
else if (roiType == ROI_4)
*os << "ROI_025_1/4";
else
*os << "ROI_012_1/16";
*os << ")";
}
PERF_TEST_P_(OpenCLBuffer, cpu_write)
{
const Size srcSize = get<0>(GetParam());
const int type = get<1>(GetParam());
const Rect roi = getROI(get<2>(GetParam()), srcSize);
checkDeviceMaxMemoryAllocSize(srcSize, type);
UMat src(srcSize, type);
declare.in(src(roi), WARMUP_NONE);
OCL_TEST_CYCLE()
{
Mat m = src(roi).getMat(ACCESS_WRITE);
m.setTo(Scalar(1, 2, 3, 4));
}
SANITY_CHECK_NOTHING();
}
PERF_TEST_P_(OpenCLBuffer, cpu_read)
{
const Size srcSize = get<0>(GetParam());
const int type = get<1>(GetParam());
const Rect roi = getROI(get<2>(GetParam()), srcSize);
checkDeviceMaxMemoryAllocSize(srcSize, type);
UMat src(srcSize, type, Scalar(1, 2, 3, 4));
declare.in(src(roi), WARMUP_NONE);
OCL_TEST_CYCLE()
{
unsigned counter = 0;
Mat m = src(roi).getMat(ACCESS_READ);
for (int y = 0; y < m.rows; y++)
{
uchar* ptr = m.ptr(y);
size_t width_bytes = m.cols * m.elemSize();
for (size_t x_bytes = 0; x_bytes < width_bytes; x_bytes++)
counter += (unsigned)(ptr[x_bytes]);
}
}
SANITY_CHECK_NOTHING();
}
PERF_TEST_P_(OpenCLBuffer, cpu_update)
{
const Size srcSize = get<0>(GetParam());
const int type = get<1>(GetParam());
const Rect roi = getROI(get<2>(GetParam()), srcSize);
checkDeviceMaxMemoryAllocSize(srcSize, type);
UMat src(srcSize, type, Scalar(1, 2, 3, 4));
declare.in(src(roi), WARMUP_NONE);
OCL_TEST_CYCLE()
{
Mat m = src(roi).getMat(ACCESS_READ | ACCESS_WRITE);
for (int y = 0; y < m.rows; y++)
{
uchar* ptr = m.ptr(y);
size_t width_bytes = m.cols * m.elemSize();
for (size_t x_bytes = 0; x_bytes < width_bytes; x_bytes++)
ptr[x_bytes] += 1;
}
}
SANITY_CHECK_NOTHING();
}
INSTANTIATE_TEST_CASE_P(/*FULL*/, OpenCLBuffer,
testing::Combine(
testing::Values(szVGA, sz720p, sz1080p, sz2160p),
testing::Values(CV_8UC1, CV_8UC2, CV_8UC3, CV_8UC4),
testing::Values(ROI_FULL)
)
);
INSTANTIATE_TEST_CASE_P(ROI, OpenCLBuffer,
testing::Combine(
testing::Values(sz1080p, sz2160p),
testing::Values(CV_8UC1),
testing::Values(ROI_16, ROI_4, ROI_2_RECT, ROI_2_LEFT, ROI_2_TOP, ROI_FULL)
)
);
} } // namespace opencv_test::ocl
#endif // HAVE_OPENCL
......@@ -10,6 +10,7 @@
// */
#include "precomp.hpp"
#include <opencv2/core/utils/logger.hpp>
namespace cv
{
......@@ -1319,10 +1320,18 @@ void MatOp_AddEx::assign(const MatExpr& e, Mat& m, int _type) const
cv::add(dst, e.s, dst);
}
else
{
if (e.a.channels() > 1)
CV_LOG_ONCE_WARNING(NULL, "OpenCV/MatExpr: processing of multi-channel arrays might be changed in the future: "
"https://github.com/opencv/opencv/issues/16739");
cv::addWeighted(e.a, e.alpha, e.b, e.beta, e.s[0], dst);
}
}
else if( e.s.isReal() && (dst.data != m.data || fabs(e.alpha) != 1))
{
if (e.a.channels() > 1)
CV_LOG_ONCE_WARNING(NULL, "OpenCV/MatExpr: processing of multi-channel arrays might be changed in the future: "
"https://github.com/opencv/opencv/issues/16739");
e.a.convertTo(m, _type, e.alpha, e.s[0]);
return;
}
......
......@@ -4602,6 +4602,17 @@ 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, AccessFlag /*flags*/, UMatUsageFlags usageFlags, int& createFlags, UMatData::MemoryFlag& flags0) const
{
const Device& dev = ctx.device(0);
......@@ -4609,7 +4620,15 @@ public:
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 = static_cast<UMatData::MemoryFlag>(0);
else
flags0 = UMatData::COPY_ON_MAP;
......
// 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"
#include "test_common.hpp"
namespace opencv_test {
static
Mat generateTestImageBGR_()
{
Size sz(640, 480);
Mat result(sz, CV_8UC3, Scalar::all(0));
const string fname = cvtest::findDataFile("../cv/shared/baboon.png");
Mat image = imread(fname, IMREAD_COLOR);
CV_Assert(!image.empty());
CV_CheckEQ(image.size(), Size(512, 512), "");
Rect roi((640-512) / 2, 0, 512, 480);
image(Rect(0, 0, 512, 480)).copyTo(result(roi));
result(Rect(0, 0, 5, 5)).setTo(Scalar(0, 0, 255)); // R
result(Rect(5, 0, 5, 5)).setTo(Scalar(0, 255, 0)); // G
result(Rect(10, 0, 5, 5)).setTo(Scalar(255, 0, 0)); // B
result(Rect(0, 5, 5, 5)).setTo(Scalar(128, 128, 128)); // gray
//imshow("test_image", result); waitKey();
return result;
}
Mat generateTestImageBGR()
{
static Mat image = generateTestImageBGR_(); // initialize once
CV_Assert(!image.empty());
return image;
}
static
Mat generateTestImageGrayscale_()
{
Mat imageBGR = generateTestImageBGR();
CV_Assert(!imageBGR.empty());
Mat result;
cvtColor(imageBGR, result, COLOR_BGR2GRAY);
return result;
}
Mat generateTestImageGrayscale()
{
static Mat image = generateTestImageGrayscale_(); // initialize once
return image;
}
} // namespace
// 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
#ifndef OPENCV_TEST_IMGCODECS_COMMON_HPP
#define OPENCV_TEST_IMGCODECS_COMMON_HPP
namespace opencv_test {
Mat generateTestImageBGR();
Mat generateTestImageGrayscale();
} // namespace
#endif // OPENCV_TEST_IMGCODECS_COMMON_HPP
......@@ -2,6 +2,7 @@
// 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"
#include "test_common.hpp"
namespace opencv_test { namespace {
......@@ -145,45 +146,6 @@ TEST(Imgcodecs_Image, read_write_bmp)
typedef string Ext;
typedef testing::TestWithParam<Ext> Imgcodecs_Image;
TEST_P(Imgcodecs_Image, read_write)
{
const string ext = this->GetParam();
const string full_name = cv::tempfile(ext.c_str());
const string _name = TS::ptr()->get_data_path() + "../cv/shared/baboon.png";
const double thresDbell = 32;
Mat image = imread(_name);
image.convertTo(image, CV_8UC3);
ASSERT_FALSE(image.empty());
imwrite(full_name, image);
Mat loaded = imread(full_name);
ASSERT_FALSE(loaded.empty());
double psnr = cvtest::PSNR(loaded, image);
EXPECT_GT(psnr, thresDbell);
vector<uchar> from_file;
FILE *f = fopen(full_name.c_str(), "rb");
fseek(f, 0, SEEK_END);
long len = ftell(f);
from_file.resize((size_t)len);
fseek(f, 0, SEEK_SET);
from_file.resize(fread(&from_file[0], 1, from_file.size(), f));
fclose(f);
vector<uchar> buf;
imencode("." + ext, image, buf);
ASSERT_EQ(buf, from_file);
Mat buf_loaded = imdecode(Mat(buf), 1);
ASSERT_FALSE(buf_loaded.empty());
psnr = cvtest::PSNR(buf_loaded, image);
EXPECT_GT(psnr, thresDbell);
EXPECT_EQ(0, remove(full_name.c_str()));
}
const string exts[] = {
#ifdef HAVE_PNG
"png",
......@@ -210,6 +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)
......
......@@ -59,8 +59,8 @@ class resizeNNInvokerAVX4 CV_FINAL :
public ParallelLoopBody
{
public:
resizeNNInvokerAVX4(const Mat& _src, Mat &_dst, int *_x_ofs, int _pix_size4, double _ify) :
ParallelLoopBody(), src(_src), dst(_dst), x_ofs(_x_ofs), pix_size4(_pix_size4),
resizeNNInvokerAVX4(const Mat& _src, Mat &_dst, int *_x_ofs, double _ify) :
ParallelLoopBody(), src(_src), dst(_dst), x_ofs(_x_ofs),
ify(_ify)
{
}
......@@ -129,9 +129,9 @@ public:
}
private:
const Mat src;
Mat dst;
int* x_ofs, pix_size4;
const Mat& src;
Mat& dst;
int* x_ofs;
double ify;
resizeNNInvokerAVX4(const resizeNNInvokerAVX4&);
......@@ -142,8 +142,8 @@ class resizeNNInvokerAVX2 CV_FINAL :
public ParallelLoopBody
{
public:
resizeNNInvokerAVX2(const Mat& _src, Mat &_dst, int *_x_ofs, int _pix_size4, double _ify) :
ParallelLoopBody(), src(_src), dst(_dst), x_ofs(_x_ofs), pix_size4(_pix_size4),
resizeNNInvokerAVX2(const Mat& _src, Mat &_dst, int *_x_ofs, double _ify) :
ParallelLoopBody(), src(_src), dst(_dst), x_ofs(_x_ofs),
ify(_ify)
{
}
......@@ -235,24 +235,24 @@ public:
}
private:
const Mat src;
Mat dst;
int* x_ofs, pix_size4;
const Mat& src;
Mat& dst;
int* x_ofs;
double ify;
resizeNNInvokerAVX2(const resizeNNInvokerAVX2&);
resizeNNInvokerAVX2& operator=(const resizeNNInvokerAVX2&);
};
void resizeNN2_AVX2(const Range& range, const Mat& src, Mat &dst, int *x_ofs, int pix_size4, double ify)
void resizeNN2_AVX2(const Range& range, const Mat& src, Mat &dst, int *x_ofs, double ify)
{
resizeNNInvokerAVX2 invoker(src, dst, x_ofs, pix_size4, ify);
resizeNNInvokerAVX2 invoker(src, dst, x_ofs, ify);
parallel_for_(range, invoker, dst.total() / (double)(1 << 16));
}
void resizeNN4_AVX2(const Range& range, const Mat& src, Mat &dst, int *x_ofs, int pix_size4, double ify)
void resizeNN4_AVX2(const Range& range, const Mat& src, Mat &dst, int *x_ofs, double ify)
{
resizeNNInvokerAVX4 invoker(src, dst, x_ofs, pix_size4, ify);
resizeNNInvokerAVX4 invoker(src, dst, x_ofs, ify);
parallel_for_(range, invoker, dst.total() / (double)(1 << 16));
}
......
......@@ -970,8 +970,8 @@ class resizeNNInvoker :
public ParallelLoopBody
{
public:
resizeNNInvoker(const Mat& _src, Mat &_dst, int *_x_ofs, int _pix_size4, double _ify) :
ParallelLoopBody(), src(_src), dst(_dst), x_ofs(_x_ofs), pix_size4(_pix_size4),
resizeNNInvoker(const Mat& _src, Mat &_dst, int *_x_ofs, double _ify) :
ParallelLoopBody(), src(_src), dst(_dst), x_ofs(_x_ofs),
ify(_ify)
{
}
......@@ -1043,19 +1043,18 @@ public:
default:
for( x = 0; x < dsize.width; x++, D += pix_size )
{
const int* _tS = (const int*)(S + x_ofs[x]);
int* _tD = (int*)D;
for( int k = 0; k < pix_size4; k++ )
_tD[k] = _tS[k];
const uchar* _tS = S + x_ofs[x];
for (int k = 0; k < pix_size; k++)
D[k] = _tS[k];
}
}
}
}
private:
const Mat src;
Mat dst;
int* x_ofs, pix_size4;
const Mat& src;
Mat& dst;
int* x_ofs;
double ify;
resizeNNInvoker(const resizeNNInvoker&);
......@@ -1069,7 +1068,6 @@ resizeNN( const Mat& src, Mat& dst, double fx, double fy )
AutoBuffer<int> _x_ofs(dsize.width);
int* x_ofs = _x_ofs.data();
int pix_size = (int)src.elemSize();
int pix_size4 = (int)(pix_size / sizeof(int));
double ifx = 1./fx, ify = 1./fy;
int x;
......@@ -1084,9 +1082,9 @@ resizeNN( const Mat& src, Mat& dst, double fx, double fy )
if(CV_CPU_HAS_SUPPORT_AVX2 && ((pix_size == 2) || (pix_size == 4)))
{
if(pix_size == 2)
opt_AVX2::resizeNN2_AVX2(range, src, dst, x_ofs, pix_size4, ify);
opt_AVX2::resizeNN2_AVX2(range, src, dst, x_ofs, ify);
else
opt_AVX2::resizeNN4_AVX2(range, src, dst, x_ofs, pix_size4, ify);
opt_AVX2::resizeNN4_AVX2(range, src, dst, x_ofs, ify);
}
else
#endif
......@@ -1094,14 +1092,14 @@ resizeNN( const Mat& src, Mat& dst, double fx, double fy )
if(CV_CPU_HAS_SUPPORT_SSE4_1 && ((pix_size == 2) || (pix_size == 4)))
{
if(pix_size == 2)
opt_SSE4_1::resizeNN2_SSE4_1(range, src, dst, x_ofs, pix_size4, ify);
opt_SSE4_1::resizeNN2_SSE4_1(range, src, dst, x_ofs, ify);
else
opt_SSE4_1::resizeNN4_SSE4_1(range, src, dst, x_ofs, pix_size4, ify);
opt_SSE4_1::resizeNN4_SSE4_1(range, src, dst, x_ofs, ify);
}
else
#endif
{
resizeNNInvoker invoker(src, dst, x_ofs, pix_size4, ify);
resizeNNInvoker invoker(src, dst, x_ofs, ify);
parallel_for_(range, invoker, dst.total()/(double)(1<<16));
}
}
......
......@@ -56,16 +56,16 @@ namespace cv
namespace opt_AVX2
{
#if CV_TRY_AVX2
void resizeNN2_AVX2(const Range&, const Mat&, Mat&, int*, int, double);
void resizeNN4_AVX2(const Range&, const Mat&, Mat&, int*, int, double);
void resizeNN2_AVX2(const Range&, const Mat&, Mat&, int*, double);
void resizeNN4_AVX2(const Range&, const Mat&, Mat&, int*, double);
#endif
}
namespace opt_SSE4_1
{
#if CV_TRY_SSE4_1
void resizeNN2_SSE4_1(const Range&, const Mat&, Mat&, int*, int, double);
void resizeNN4_SSE4_1(const Range&, const Mat&, Mat&, int*, int, double);
void resizeNN2_SSE4_1(const Range&, const Mat&, Mat&, int*, double);
void resizeNN4_SSE4_1(const Range&, const Mat&, Mat&, int*, double);
int VResizeLanczos4Vec_32f16u_SSE41(const float** src, ushort* dst, const float* beta, int width);
#endif
......
......@@ -59,8 +59,8 @@ class resizeNNInvokerSSE2 :
public ParallelLoopBody
{
public:
resizeNNInvokerSSE2(const Mat& _src, Mat &_dst, int *_x_ofs, int _pix_size4, double _ify) :
ParallelLoopBody(), src(_src), dst(_dst), x_ofs(_x_ofs), pix_size4(_pix_size4),
resizeNNInvokerSSE2(const Mat& _src, Mat &_dst, int *_x_ofs, double _ify) :
ParallelLoopBody(), src(_src), dst(_dst), x_ofs(_x_ofs),
ify(_ify)
{
}
......@@ -110,9 +110,9 @@ public:
}
private:
const Mat src;
Mat dst;
int* x_ofs, pix_size4;
const Mat& src;
Mat& dst;
int* x_ofs;
double ify;
resizeNNInvokerSSE2(const resizeNNInvokerSSE2&);
......@@ -123,8 +123,8 @@ class resizeNNInvokerSSE4 :
public ParallelLoopBody
{
public:
resizeNNInvokerSSE4(const Mat& _src, Mat &_dst, int *_x_ofs, int _pix_size4, double _ify) :
ParallelLoopBody(), src(_src), dst(_dst), x_ofs(_x_ofs), pix_size4(_pix_size4),
resizeNNInvokerSSE4(const Mat& _src, Mat &_dst, int *_x_ofs, double _ify) :
ParallelLoopBody(), src(_src), dst(_dst), x_ofs(_x_ofs),
ify(_ify)
{
}
......@@ -165,24 +165,24 @@ public:
}
private:
const Mat src;
Mat dst;
int* x_ofs, pix_size4;
const Mat& src;
Mat& dst;
int* x_ofs;
double ify;
resizeNNInvokerSSE4(const resizeNNInvokerSSE4&);
resizeNNInvokerSSE4& operator=(const resizeNNInvokerSSE4&);
};
void resizeNN2_SSE4_1(const Range& range, const Mat& src, Mat &dst, int *x_ofs, int pix_size4, double ify)
void resizeNN2_SSE4_1(const Range& range, const Mat& src, Mat &dst, int *x_ofs, double ify)
{
resizeNNInvokerSSE2 invoker(src, dst, x_ofs, pix_size4, ify);
resizeNNInvokerSSE2 invoker(src, dst, x_ofs, ify);
parallel_for_(range, invoker, dst.total() / (double)(1 << 16));
}
void resizeNN4_SSE4_1(const Range& range, const Mat& src, Mat &dst, int *x_ofs, int pix_size4, double ify)
void resizeNN4_SSE4_1(const Range& range, const Mat& src, Mat &dst, int *x_ofs, double ify)
{
resizeNNInvokerSSE4 invoker(src, dst, x_ofs, pix_size4, ify);
resizeNNInvokerSSE4 invoker(src, dst, x_ofs, ify);
parallel_for_(range, invoker, dst.total() / (double)(1 << 16));
}
......
......@@ -1413,7 +1413,7 @@ TEST(Resize, lanczos4_regression_16192)
EXPECT_EQ(cvtest::norm(dst, expected, NORM_INF), 0) << dst(Rect(0,0,8,8));
}
TEST(Resize, DISABLED_nearest_regression_15075) // reverted https://github.com/opencv/opencv/pull/16497
TEST(Resize, nearest_regression_15075)
{
const int C = 5;
const int i1 = 5, j1 = 5;
......
......@@ -778,7 +778,9 @@ void DpSeamFinder::computeCosts(
{
for (int x = roi.x; x < roi.br().x+1; ++x)
{
if (labels_(y, x) == l && x > 0 && labels_(y, x-1) == l)
if (x > 0 && x < labels_.cols &&
labels_(y, x) == l && labels_(y, x-1) == l
)
{
float costColor = (diff(image1, y + dy1, x + dx1 - 1, image2, y + dy2, x + dx2) +
diff(image1, y + dy1, x + dx1, image2, y + dy2, x + dx2 - 1)) / 2;
......@@ -802,7 +804,9 @@ void DpSeamFinder::computeCosts(
{
for (int x = roi.x; x < roi.br().x; ++x)
{
if (labels_(y, x) == l && y > 0 && labels_(y-1, x) == l)
if (y > 0 && y < labels_.rows &&
labels_(y, x) == l && labels_(y-1, x) == l
)
{
float costColor = (diff(image1, y + dy1 - 1, x + dx1, image2, y + dy2, x + dx2) +
diff(image1, y + dy1, x + dx1, image2, y + dy2 - 1, x + dx2)) / 2;
......
......@@ -585,7 +585,7 @@ public:
virtual bool isOpened() const CV_OVERRIDE { return isOpen; }
virtual int getCaptureDomain() CV_OVERRIDE { return CV_CAP_MSMF; }
protected:
bool configureOutput(MediaType newType, cv::uint32_t outFormat, bool convertToFormat);
bool configureOutput(MediaType newType, cv::uint32_t outFormat);
bool setTime(double time, bool rough);
bool configureHW(bool enable);
......@@ -772,7 +772,7 @@ bool CvCapture_MSMF::configureHW(bool enable)
#endif
}
bool CvCapture_MSMF::configureOutput(MediaType newType, cv::uint32_t outFormat, bool convertToFormat)
bool CvCapture_MSMF::configureOutput(MediaType newType, cv::uint32_t outFormat)
{
FormatStorage formats;
formats.read(videoFileSource.Get());
......@@ -780,7 +780,7 @@ bool CvCapture_MSMF::configureOutput(MediaType newType, cv::uint32_t outFormat,
dwStreamIndex = bestMatch.first.stream;
nativeFormat = bestMatch.second;
MediaType newFormat = nativeFormat;
if (convertToFormat)
if (convertFormat)
{
switch (outFormat)
{
......@@ -840,7 +840,7 @@ bool CvCapture_MSMF::open(int index)
camid = index;
readCallback = cb;
duration = 0;
if (configureOutput(MediaType::createDefault(), outputFormat, convertFormat))
if (configureOutput(MediaType::createDefault(), outputFormat))
{
frameStep = captureFormat.getFrameStep();
}
......@@ -861,7 +861,7 @@ bool CvCapture_MSMF::open(const cv::String& _filename)
{
isOpen = true;
sampleTime = 0;
if (configureOutput(MediaType(), outputFormat, convertFormat))
if (configureOutput(MediaType(), outputFormat))
{
frameStep = captureFormat.getFrameStep();
filename = _filename;
......@@ -1302,44 +1302,45 @@ bool CvCapture_MSMF::setProperty( int property_id, double value )
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)
{
newFormat.aspectRatioNum = (UINT32)cvRound(value);
return configureOutput(newFormat, outputFormat, convertFormat);
return configureOutput(newFormat, outputFormat);
}
break;
case CV_CAP_PROP_SAR_DEN:
if (value > 0)
{
newFormat.aspectRatioDenom = (UINT32)cvRound(value);
return configureOutput(newFormat, outputFormat, convertFormat);
return configureOutput(newFormat, outputFormat);
}
break;
case CV_CAP_PROP_FRAME_WIDTH:
if (value >= 0)
{
newFormat.width = (UINT32)cvRound(value);
return configureOutput(newFormat, outputFormat, convertFormat);
return configureOutput(newFormat, outputFormat);
}
break;
case CV_CAP_PROP_FRAME_HEIGHT:
if (value >= 0)
{
newFormat.height = (UINT32)cvRound(value);
return configureOutput(newFormat, outputFormat, convertFormat);
return configureOutput(newFormat, outputFormat);
}
break;
case CV_CAP_PROP_FPS:
if (value >= 0)
{
newFormat.setFramerate(value);
return configureOutput(newFormat, outputFormat, convertFormat);
return configureOutput(newFormat, outputFormat);
}
break;
case CV_CAP_PROP_FRAME_COUNT:
......@@ -1569,7 +1570,7 @@ bool CvVideoWriter_MSMF::open( const cv::String& filename, int fourcc,
SUCCEEDED(mediaTypeOut->SetUINT32(MF_MT_AVG_BITRATE, bitRate)) &&
SUCCEEDED(mediaTypeOut->SetUINT32(MF_MT_INTERLACE_MODE, MFVideoInterlace_Progressive)) &&
SUCCEEDED(MFSetAttributeSize(mediaTypeOut.Get(), MF_MT_FRAME_SIZE, videoWidth, videoHeight)) &&
SUCCEEDED(MFSetAttributeRatio(mediaTypeOut.Get(), MF_MT_FRAME_RATE, (UINT32)fps, 1)) &&
SUCCEEDED(MFSetAttributeRatio(mediaTypeOut.Get(), MF_MT_FRAME_RATE, (UINT32)(fps * 1000), 1000)) &&
SUCCEEDED(MFSetAttributeRatio(mediaTypeOut.Get(), MF_MT_PIXEL_ASPECT_RATIO, 1, 1)) &&
// Set the input media type.
SUCCEEDED(MFCreateMediaType(&mediaTypeIn)) &&
......@@ -1578,7 +1579,7 @@ bool CvVideoWriter_MSMF::open( const cv::String& filename, int fourcc,
SUCCEEDED(mediaTypeIn->SetUINT32(MF_MT_INTERLACE_MODE, MFVideoInterlace_Progressive)) &&
SUCCEEDED(mediaTypeIn->SetUINT32(MF_MT_DEFAULT_STRIDE, 4 * videoWidth)) && //Assume BGR32 input
SUCCEEDED(MFSetAttributeSize(mediaTypeIn.Get(), MF_MT_FRAME_SIZE, videoWidth, videoHeight)) &&
SUCCEEDED(MFSetAttributeRatio(mediaTypeIn.Get(), MF_MT_FRAME_RATE, (UINT32)fps, 1)) &&
SUCCEEDED(MFSetAttributeRatio(mediaTypeIn.Get(), MF_MT_FRAME_RATE, (UINT32)(fps * 1000), 1000)) &&
SUCCEEDED(MFSetAttributeRatio(mediaTypeIn.Get(), MF_MT_PIXEL_ASPECT_RATIO, 1, 1)) &&
// Set sink writer parameters
SUCCEEDED(MFCreateAttributes(&spAttr, 10)) &&
......@@ -1599,7 +1600,7 @@ bool CvVideoWriter_MSMF::open( const cv::String& filename, int fourcc,
{
initiated = true;
rtStart = 0;
MFFrameRateToAverageTimePerFrame((UINT32)fps, 1, &rtDuration);
MFFrameRateToAverageTimePerFrame((UINT32)(fps * 1000), 1000, &rtDuration);
return true;
}
}
......
......@@ -402,7 +402,8 @@ class Builder:
rm_one(os.path.join(package_opencv, item))
with open(str(self.package_dir / 'README.md'), 'w') as f:
f.write('See licensing/copying statements in "build/etc/licenses"')
f.write('See licensing/copying statements in "build/etc/licenses"\n')
f.write('Wiki page: https://github.com/opencv/opencv/wiki/Intel%27s-Deep-Learning-Inference-Engine-backend\n')
log.info('Package OpenCV sources - DONE')
......
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