1
0
mirror of https://github.com/opencv/opencv.git synced 2026-07-31 00:03:03 +04:00

Merge branch 4.x

This commit is contained in:
Alexander Alekhin
2023-01-09 11:08:02 +00:00
880 changed files with 83958 additions and 9368 deletions
+2 -2
View File
@@ -41,7 +41,7 @@ inline std::ostream& operator<<(std::ostream& os, mathOp op)
CASE(SUB);
CASE(MUL);
CASE(DIV);
default: GAPI_Assert(false && "unknown mathOp value");
default: GAPI_Error("unknown mathOp value");
}
#undef CASE
return os;
@@ -57,7 +57,7 @@ inline std::ostream& operator<<(std::ostream& os, bitwiseOp op)
CASE(OR);
CASE(XOR);
CASE(NOT);
default: GAPI_Assert(false && "unknown bitwiseOp value");
default: GAPI_Error("unknown bitwiseOp value");
}
#undef CASE
return os;
@@ -34,7 +34,7 @@ inline std::ostream& operator<<(std::ostream& os, operation op)
CASE(GTR); CASE(LTR); CASE(GER); CASE(LER); CASE(EQR); CASE(NER);
CASE(AND); CASE(OR); CASE(XOR);
CASE(ANDR); CASE(ORR); CASE(XORR);
default: GAPI_Assert(false && "unknown operation value");
default: GAPI_Error("unknown operation value");
}
#undef CASE
return os;
@@ -187,7 +187,7 @@ struct g_api_ocv_pair_mat_scalar {
CASE(GTR); CASE(LTR); CASE(GER); CASE(LER); CASE(EQR); CASE(NER);
CASE(AND); CASE(OR); CASE(XOR);
CASE(ANDR); CASE(ORR); CASE(XORR);
default: GAPI_Assert(false && "unknown operation value");
default: GAPI_Error("unknown operation value");
}
}
#undef CASE
@@ -214,7 +214,7 @@ struct g_api_ocv_pair_mat_mat {
CASE(ADD); CASE(SUB); CASE(DIV);
CASE(GT); CASE(LT); CASE(GE); CASE(LE); CASE(EQ); CASE(NE);
CASE(AND); CASE(OR); CASE(XOR);
default: GAPI_Assert(false && "unknown operation value");
default: GAPI_Error("unknown operation value");
}
}
#undef CASE
@@ -25,7 +25,7 @@ TEST_P(TestGAPIStereo, DisparityDepthTest)
case format::DEPTH_FLOAT16: dtype = CV_16FC1; break;
case format::DEPTH_FLOAT32: dtype = CV_32FC1; break;
case format::DISPARITY_FIXED16_12_4: dtype = CV_16SC1; break;
default: GAPI_Assert(false && "Unsupported format in test");
default: GAPI_Error("Unsupported format in test");
}
initOutMats(sz, dtype);
@@ -61,7 +61,7 @@ TEST_P(TestGAPIStereo, DisparityDepthTest)
case format::DISPARITY_FIXED16_12_4:
break;
default:
GAPI_Assert(false && "Unsupported format in test");
GAPI_Error("Unsupported format in test");
}
EXPECT_TRUE(cmpF(out_mat_gapi, out_mat_ocv));
@@ -373,7 +373,7 @@ public:
initMatByPointsVectorRandU<Pt<cv::float16_t>>(sz_in);
break;
default:
GAPI_Assert(false && "Unsupported depth");
GAPI_Error("Unsupported depth");
break;
}
}
@@ -1065,7 +1065,7 @@ inline std::ostream& operator<<(std::ostream& os, CmpTypes op)
CASE(CMP_LT);
CASE(CMP_LE);
CASE(CMP_NE);
default: GAPI_Assert(false && "unknown CmpTypes value");
default: GAPI_Error("unknown CmpTypes value");
}
#undef CASE
return os;
@@ -1084,7 +1084,7 @@ inline std::ostream& operator<<(std::ostream& os, NormTypes op)
CASE(NORM_HAMMING2);
CASE(NORM_RELATIVE);
CASE(NORM_MINMAX);
default: GAPI_Assert(false && "unknown NormTypes value");
default: GAPI_Error("unknown NormTypes value");
}
#undef CASE
return os;
@@ -1100,7 +1100,7 @@ inline std::ostream& operator<<(std::ostream& os, RetrievalModes op)
CASE(RETR_CCOMP);
CASE(RETR_TREE);
CASE(RETR_FLOODFILL);
default: GAPI_Assert(false && "unknown RetrievalModes value");
default: GAPI_Error("unknown RetrievalModes value");
}
#undef CASE
return os;
@@ -1115,7 +1115,7 @@ inline std::ostream& operator<<(std::ostream& os, ContourApproximationModes op)
CASE(CHAIN_APPROX_SIMPLE);
CASE(CHAIN_APPROX_TC89_L1);
CASE(CHAIN_APPROX_TC89_KCOS);
default: GAPI_Assert(false && "unknown ContourApproximationModes value");
default: GAPI_Error("unknown ContourApproximationModes value");
}
#undef CASE
return os;
@@ -1134,7 +1134,7 @@ inline std::ostream& operator<<(std::ostream& os, MorphTypes op)
CASE(MORPH_TOPHAT);
CASE(MORPH_BLACKHAT);
CASE(MORPH_HITMISS);
default: GAPI_Assert(false && "unknown MorphTypes value");
default: GAPI_Error("unknown MorphTypes value");
}
#undef CASE
return os;
@@ -1153,7 +1153,7 @@ inline std::ostream& operator<<(std::ostream& os, DistanceTypes op)
CASE(DIST_FAIR);
CASE(DIST_WELSCH);
CASE(DIST_HUBER);
default: GAPI_Assert(false && "unknown DistanceTypes value");
default: GAPI_Error("unknown DistanceTypes value");
}
#undef CASE
return os;
@@ -1176,7 +1176,7 @@ inline std::ostream& operator<<(std::ostream& os, KmeansFlags op)
case KmeansFlags::KMEANS_PP_CENTERS | KmeansFlags::KMEANS_USE_INITIAL_LABELS:
os << "KMEANS_PP_CENTERS | KMEANS_USE_INITIAL_LABELS";
break;
default: GAPI_Assert(false && "unknown KmeansFlags value");
default: GAPI_Error("unknown KmeansFlags value");
}
return os;
}
@@ -435,7 +435,7 @@ inline cv::GComputation runOCVnGAPIBuildOptFlowPyramid(TestFunctional&,
BuildOpticalFlowPyramidTestOutput&,
BuildOpticalFlowPyramidTestOutput&)
{
GAPI_Assert(0 && "This function shouldn't be called without opencv_video");
GAPI_Error("This function shouldn't be called without opencv_video");
}
inline cv::GComputation runOCVnGAPIOptFlowLK(TestFunctional&,
@@ -444,7 +444,7 @@ inline cv::GComputation runOCVnGAPIOptFlowLK(TestFunctional&,
OptFlowLKTestOutput&,
OptFlowLKTestOutput&)
{
GAPI_Assert(0 && "This function shouldn't be called without opencv_video");
GAPI_Error("This function shouldn't be called without opencv_video");
}
inline cv::GComputation runOCVnGAPIOptFlowLKForPyr(TestFunctional&,
@@ -454,7 +454,7 @@ inline cv::GComputation runOCVnGAPIOptFlowLKForPyr(TestFunctional&,
OptFlowLKTestOutput&,
OptFlowLKTestOutput&)
{
GAPI_Assert(0 && "This function shouldn't be called without opencv_video");
GAPI_Error("This function shouldn't be called without opencv_video");
}
inline GComputation runOCVnGAPIOptFlowPipeline(TestFunctional&,
@@ -463,7 +463,7 @@ inline GComputation runOCVnGAPIOptFlowPipeline(TestFunctional&,
OptFlowLKTestOutput&,
std::vector<Point2f>&)
{
GAPI_Assert(0 && "This function shouldn't be called without opencv_video");
GAPI_Error("This function shouldn't be called without opencv_video");
}
#endif // HAVE_OPENCV_VIDEO
@@ -481,7 +481,7 @@ inline std::ostream& operator<<(std::ostream& os, const BackgroundSubtractorType
{
CASE(TYPE_BS_MOG2);
CASE(TYPE_BS_KNN);
default: GAPI_Assert(false && "unknown BackgroundSubtractor type");
default: GAPI_Error("unknown BackgroundSubtractor type");
}
#undef CASE
return os;
@@ -50,7 +50,7 @@ TEST(TBBExecutor, Basic) {
});
q.push(&n);
execute(q);
EXPECT_EQ(true, executed);
EXPECT_TRUE(executed);
}
TEST(TBBExecutor, SerialExecution) {
@@ -117,8 +117,8 @@ TEST(TBBExecutor, AsyncBasic) {
async_thread.join();
EXPECT_EQ(true, callback_called);
EXPECT_EQ(true, master_was_blocked_until_callback_called);
EXPECT_TRUE(callback_called);
EXPECT_TRUE(master_was_blocked_until_callback_called);
}
TEST(TBBExecutor, Dependencies) {
+1
View File
@@ -13,6 +13,7 @@
#include <condition_variable>
#include <stdexcept>
#include <thread>
namespace opencv_test
{
+101 -1
View File
@@ -304,7 +304,7 @@ struct InferWithReshape: public ::testing::Test {
InferenceEngine::CNNNetwork net;
InferenceEngine::Core plugin;
InferWithReshape() {
void SetUp() {
// FIXME: it must be cv::imread(findDataFile("../dnn/grace_hopper_227.png", false));
m_in_mat = cv::Mat(cv::Size(320, 240), CV_8UC3);
cv::randu(m_in_mat, 0, 255);
@@ -386,6 +386,7 @@ struct InferWithReshapeNV12: public InferWithReshape {
cv::Mat m_in_uv;
cv::Mat m_in_y;
void SetUp() {
InferWithReshape::SetUp();
cv::Size sz{320, 240};
m_in_y = cv::Mat{sz, CV_8UC1};
cv::randu(m_in_y, 0, 255);
@@ -2956,6 +2957,105 @@ TEST(TestAgeGender, ThrowBlobAndInputPrecisionMismatchStreaming)
}
}
struct AgeGenderInferTest: public ::testing::Test {
cv::Mat m_in_mat;
cv::Mat m_gapi_age;
cv::Mat m_gapi_gender;
cv::gimpl::ie::wrap::Plugin m_plugin;
IE::CNNNetwork m_net;
cv::gapi::ie::detail::ParamDesc m_params;
using AGInfo = std::tuple<cv::GMat, cv::GMat>;
G_API_NET(AgeGender, <AGInfo(cv::GMat)>, "test-age-gender");
void SetUp() {
initDLDTDataPath();
m_params.model_path = findDataFile(SUBDIR + "age-gender-recognition-retail-0013.xml");
m_params.weights_path = findDataFile(SUBDIR + "age-gender-recognition-retail-0013.bin");
m_params.device_id = "CPU";
m_plugin = cv::gimpl::ie::wrap::getPlugin(m_params);
m_net = cv::gimpl::ie::wrap::readNetwork(m_params);
setNetParameters(m_net);
m_in_mat = cv::Mat(cv::Size(320, 240), CV_8UC3);
cv::randu(m_in_mat, 0, 255);
}
cv::GComputation buildGraph() {
cv::GMat in, age, gender;
std::tie(age, gender) = cv::gapi::infer<AgeGender>(in);
return cv::GComputation(cv::GIn(in), cv::GOut(age, gender));
}
void validate() {
IE::Blob::Ptr ie_age, ie_gender;
{
auto this_network = cv::gimpl::ie::wrap::loadNetwork(m_plugin, m_net, m_params);
auto infer_request = this_network.CreateInferRequest();
infer_request.SetBlob("data", cv::gapi::ie::util::to_ie(m_in_mat));
infer_request.Infer();
ie_age = infer_request.GetBlob("age_conv3");
ie_gender = infer_request.GetBlob("prob");
}
// Validate with IE itself (avoid DNN module dependency here)
normAssert(cv::gapi::ie::util::to_ocv(ie_age), m_gapi_age, "Test age output" );
normAssert(cv::gapi::ie::util::to_ocv(ie_gender), m_gapi_gender, "Test gender output");
}
};
TEST_F(AgeGenderInferTest, SyncExecution) {
auto pp = cv::gapi::ie::Params<AgeGender> {
m_params.model_path, m_params.weights_path, m_params.device_id
}.cfgOutputLayers({ "age_conv3", "prob" })
.cfgInferMode(cv::gapi::ie::InferMode::Sync);
buildGraph().apply(cv::gin(m_in_mat), cv::gout(m_gapi_age, m_gapi_gender),
cv::compile_args(cv::gapi::networks(pp)));
validate();
}
TEST_F(AgeGenderInferTest, ThrowSyncWithNireqNotEqualToOne) {
auto pp = cv::gapi::ie::Params<AgeGender> {
m_params.model_path, m_params.weights_path, m_params.device_id
}.cfgOutputLayers({ "age_conv3", "prob" })
.cfgInferMode(cv::gapi::ie::InferMode::Sync)
.cfgNumRequests(4u);
EXPECT_ANY_THROW(buildGraph().apply(cv::gin(m_in_mat), cv::gout(m_gapi_age, m_gapi_gender),
cv::compile_args(cv::gapi::networks(pp))));
}
TEST_F(AgeGenderInferTest, ChangeOutputPrecision) {
auto pp = cv::gapi::ie::Params<AgeGender> {
m_params.model_path, m_params.weights_path, m_params.device_id
}.cfgOutputLayers({ "age_conv3", "prob" })
.cfgOutputPrecision(CV_8U);
for (auto it : m_net.getOutputsInfo()) {
it.second->setPrecision(IE::Precision::U8);
}
buildGraph().apply(cv::gin(m_in_mat), cv::gout(m_gapi_age, m_gapi_gender),
cv::compile_args(cv::gapi::networks(pp)));
validate();
}
TEST_F(AgeGenderInferTest, ChangeSpecificOutputPrecison) {
auto pp = cv::gapi::ie::Params<AgeGender> {
m_params.model_path, m_params.weights_path, m_params.device_id
}.cfgOutputLayers({ "age_conv3", "prob" })
.cfgOutputPrecision({{"prob", CV_8U}});
m_net.getOutputsInfo().at("prob")->setPrecision(IE::Precision::U8);
buildGraph().apply(cv::gin(m_in_mat), cv::gout(m_gapi_age, m_gapi_gender),
cv::compile_args(cv::gapi::networks(pp)));
validate();
}
} // namespace opencv_test
#endif // HAVE_INF_ENGINE
@@ -114,7 +114,7 @@ inline int toCV(ONNXTensorElementDataType prec) {
case ONNX_TENSOR_ELEMENT_DATA_TYPE_FLOAT: return CV_32F;
case ONNX_TENSOR_ELEMENT_DATA_TYPE_INT32: return CV_32S;
case ONNX_TENSOR_ELEMENT_DATA_TYPE_INT64: return CV_32S;
default: GAPI_Assert(false && "Unsupported data type");
default: GAPI_Error("Unsupported data type");
}
return -1;
}
@@ -142,7 +142,7 @@ void copyFromONNX(Ort::Value &v, cv::Mat& mat) {
[](int64_t el) { return static_cast<int>(el); });
break;
}
default: GAPI_Assert(false && "ONNX. Unsupported data type");
default: GAPI_Error("ONNX. Unsupported data type");
}
}
+2 -2
View File
@@ -554,7 +554,7 @@ TEST_F(S11N_Basic, Test_RunArgs_MatScalar) {
EXPECT_EQ(scalar, out_scalar);
} break;
default:
GAPI_Assert(false && "This value type is not supported!"); // ...maybe because of STANDALONE mode.
GAPI_Error("This value type is not supported!"); // ...maybe because of STANDALONE mode.
break;
}
i++;
@@ -587,7 +587,7 @@ TEST_F(S11N_Basic, Test_Bind_RunArgs_MatScalar) {
EXPECT_EQ(out_scalar->val[2], scalar.val[2]);
} break;
default:
GAPI_Assert(false && "This value type is not supported!"); // ...maybe because of STANDALONE mode.
GAPI_Error("This value type is not supported!"); // ...maybe because of STANDALONE mode.
break;
}
}
@@ -138,9 +138,9 @@ TEST(GStreamerPipelineFacadeTest, IsPlayingUnitTest)
"video/x-raw,width=1920,height=1080,framerate=3/1 ! "
"appsink name=sink2");
EXPECT_EQ(false, pipelineFacade.isPlaying());
EXPECT_FALSE(pipelineFacade.isPlaying());
pipelineFacade.play();
EXPECT_EQ(true, pipelineFacade.isPlaying());
EXPECT_TRUE(pipelineFacade.isPlaying());
}
TEST(GStreamerPipelineFacadeTest, MTSafetyUnitTest)
@@ -49,7 +49,7 @@ std::ostream& operator<< (std::ostream &os, const KernelPackage &e)
_C(OCL);
_C(OCL_FLUID);
#undef _C
default: GAPI_Assert(false);
default: GAPI_Error("InternalError");
}
return os;
}
@@ -298,7 +298,7 @@ void checkPullOverload(const cv::Mat& ref,
out_mat = *opt_mat;
break;
}
default: GAPI_Assert(false && "Incorrect type of Args");
default: GAPI_Error("Incorrect type of Args");
}
EXPECT_EQ(0., cv::norm(ref, out_mat, cv::NORM_INF));
@@ -2420,7 +2420,7 @@ TEST(GAPI_Streaming, TestPythonAPI)
switch (args.index()) {
case RunArgs::index_of<cv::GRunArgs>():
out_args = util::get<cv::GRunArgs>(args); break;
default: GAPI_Assert(false && "Incorrect type of return value");
default: GAPI_Error("Incorrect type of return value");
}
ASSERT_EQ(1u, out_args.size());
@@ -8,6 +8,7 @@
#include "../test_precomp.hpp"
#include "../common/gapi_streaming_tests_common.hpp"
#include "../common/gapi_tests_common.hpp"
#include <chrono>
#include <future>
@@ -29,6 +30,7 @@
#ifdef HAVE_ONEVPL
#include <opencv2/gapi/streaming/onevpl/data_provider_interface.hpp>
#include <opencv2/gapi/streaming/onevpl/default.hpp>
#include "streaming/onevpl/file_data_provider.hpp"
#include "streaming/onevpl/cfg_param_device_selector.hpp"
@@ -327,6 +329,72 @@ TEST(OneVPL_Source_CPU_FrameAdapter, InitFrameAdapter)
EXPECT_TRUE(0 == surf->get_locks_count());
}
TEST(OneVPL_Source_Default_Source_With_OCL_Backend, Accuracy)
{
using namespace cv::gapi::wip::onevpl;
auto create_from_string = [](const std::string& line){
std::string::size_type name_endline_pos = line.find(':');
std::string name = line.substr(0, name_endline_pos);
std::string value = line.substr(name_endline_pos + 1);
return CfgParam::create(name, value);
};
std::vector<CfgParam> source_cfgs;
source_cfgs.push_back(create_from_string("mfxImplDescription.AccelerationMode:MFX_ACCEL_MODE_VIA_D3D11"));
// Create VPL-based source
std::shared_ptr<IDeviceSelector> default_device_selector = getDefaultDeviceSelector(source_cfgs);
cv::gapi::wip::IStreamSource::Ptr source;
cv::gapi::wip::IStreamSource::Ptr source_cpu;
auto input = findDataFile("cv/video/768x576.avi");
try {
source = cv::gapi::wip::make_onevpl_src(input, source_cfgs, default_device_selector);
source_cpu = cv::gapi::wip::make_onevpl_src(input, source_cfgs, default_device_selector);
} catch(...) {
throw SkipTestException("Video file can not be opened");
}
// Build the graph w/ OCL backend
cv::GFrame in; // input frame from VPL source
auto bgr_gmat = cv::gapi::streaming::BGR(in); // conversion from VPL source frame to BGR UMat
auto out = cv::gapi::blur(bgr_gmat, cv::Size(4,4)); // ocl kernel of blur operation
cv::GStreamingCompiled pipeline = cv::GComputation(cv::GIn(in), cv::GOut(out))
.compileStreaming(std::move(cv::compile_args(cv::gapi::core::ocl::kernels())));
pipeline.setSource(std::move(source));
cv::GStreamingCompiled pipeline_cpu = cv::GComputation(cv::GIn(in), cv::GOut(out))
.compileStreaming(std::move(cv::compile_args(cv::gapi::core::cpu::kernels())));
pipeline_cpu.setSource(std::move(source_cpu));
// The execution part
cv::Mat out_mat;
std::vector<cv::Mat> ocl_mats, cpu_mats;
// Run the pipelines
pipeline.start();
while (pipeline.pull(cv::gout(out_mat)))
{
ocl_mats.push_back(out_mat);
}
pipeline_cpu.start();
while (pipeline_cpu.pull(cv::gout(out_mat)))
{
cpu_mats.push_back(out_mat);
}
// Compare results
// FIXME: investigate why 2 sources produce different number of frames sometimes
for (size_t i = 0; i < std::min(ocl_mats.size(), cpu_mats.size()); ++i)
{
EXPECT_TRUE(AbsTolerance(1).to_compare_obj()(ocl_mats[i], cpu_mats[i]));
}
}
TEST(OneVPL_Source_CPU_Accelerator, InitDestroy)
{
using cv::gapi::wip::onevpl::VPLCPUAccelerationPolicy;