gapi: Full calcOpticalFlowPyrLK implementation (2 overloads) and tests

- opencv_gapi module is linked with opencv_video module (optional dependency)
     - kernels added to a new cv::gapi::video namespace and a brand new files created to provide gapi_video environment
     - there are 2 different kernels as G-API should provide GMat AND GArray<GMat> implementation: cv::calcOptFlowPyrLK doesn't calculate pyramids if vector<Mat> is given so just the cast GMat -> GArray<GMat> wouldn't represent all the cv:: functionality
     - tests to check both kernels (based on cv::video tests for cv::calcOpticalFlowPyrLK())
     - tests for internal purposes added
     - vectors<T> comparison in tests implemented
     - new (and old too) common test structures refactored to avoid code copypasting
     - "modules/gapi/test/common/gapi_video_tests_common.hpp" created to share some code snippets between perf and acc tests and avoid code copypasting
This commit is contained in:
OrestChura
2020-04-08 17:05:43 +03:00
parent acede976e4
commit d50c21e571
22 changed files with 921 additions and 26 deletions
+45
View File
@@ -0,0 +1,45 @@
// 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.
//
// Copyright (C) 2020 Intel Corporation
#include "precomp.hpp"
#include <opencv2/gapi/video.hpp>
namespace cv { namespace gapi {
using namespace video;
GOptFlowLKOutput calcOpticalFlowPyrLK(const GMat &prevImg,
const GMat &nextImg,
const cv::GArray<cv::Point2f> &prevPts,
const cv::GArray<cv::Point2f> &predPts,
const Size &winSize,
int maxLevel,
const TermCriteria &criteria,
int flags,
double minEigThresh)
{
return GCalcOptFlowLK::on(prevImg, nextImg, prevPts, predPts, winSize, maxLevel,
criteria, flags, minEigThresh);
}
GOptFlowLKOutput calcOpticalFlowPyrLK(const cv::GArray<cv::GMat> &prevPyr,
const cv::GArray<cv::GMat> &nextPyr,
const cv::GArray<cv::Point2f> &prevPts,
const cv::GArray<cv::Point2f> &predPts,
const Size &winSize,
int maxLevel,
const TermCriteria &criteria,
int flags,
double minEigThresh)
{
return GCalcOptFlowLKForPyr::on(prevPyr, nextPyr, prevPts, predPts, winSize, maxLevel,
criteria, flags, minEigThresh);
}
} //namespace gapi
} //namespace cv
@@ -0,0 +1,80 @@
// 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.
//
// Copyright (C) 2020 Intel Corporation
#include "precomp.hpp"
#include <opencv2/gapi/video.hpp>
#include <opencv2/gapi/cpu/video.hpp>
#include <opencv2/gapi/cpu/gcpukernel.hpp>
#ifdef HAVE_OPENCV_VIDEO
#include <opencv2/video.hpp>
#endif // HAVE_OPENCV_VIDEO
#ifdef HAVE_OPENCV_VIDEO
GAPI_OCV_KERNEL(GCPUCalcOptFlowLK, cv::gapi::video::GCalcOptFlowLK)
{
static void run(const cv::Mat &prevImg,
const cv::Mat &nextImg,
const std::vector<cv::Point2f> &prevPts,
const std::vector<cv::Point2f> &predPts,
const cv::Size &winSize,
int maxLevel,
const cv::TermCriteria &criteria,
int flags,
double minEigThresh,
std::vector<cv::Point2f> &outPts,
std::vector<uchar> &status,
std::vector<float> &err)
{
if (flags & cv::OPTFLOW_USE_INITIAL_FLOW)
outPts = predPts;
cv::calcOpticalFlowPyrLK(prevImg, nextImg, prevPts, outPts, status, err, winSize, maxLevel,
criteria, flags, minEigThresh);
}
};
GAPI_OCV_KERNEL(GCPUCalcOptFlowLKForPyr, cv::gapi::video::GCalcOptFlowLKForPyr)
{
static void run(const std::vector<cv::Mat> &prevPyr,
const std::vector<cv::Mat> &nextPyr,
const std::vector<cv::Point2f> &prevPts,
const std::vector<cv::Point2f> &predPts,
const cv::Size &winSize,
int maxLevel,
const cv::TermCriteria &criteria,
int flags,
double minEigThresh,
std::vector<cv::Point2f> &outPts,
std::vector<uchar> &status,
std::vector<float> &err)
{
if (flags & cv::OPTFLOW_USE_INITIAL_FLOW)
outPts = predPts;
cv::calcOpticalFlowPyrLK(prevPyr, nextPyr, prevPts, outPts, status, err, winSize, maxLevel,
criteria, flags, minEigThresh);
}
};
cv::gapi::GKernelPackage cv::gapi::video::cpu::kernels()
{
static auto pkg = cv::gapi::kernels
< GCPUCalcOptFlowLK
, GCPUCalcOptFlowLKForPyr
>();
return pkg;
}
#else
cv::gapi::GKernelPackage cv::gapi::video::cpu::kernels()
{
return GKernelPackage();
}
#endif // HAVE_OPENCV_VIDEO
+7 -6
View File
@@ -2,7 +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.
//
// Copyright (C) 2018 Intel Corporation
// Copyright (C) 2018-2020 Intel Corporation
#include "precomp.hpp"
@@ -38,8 +38,9 @@
// <FIXME:>
#if !defined(GAPI_STANDALONE)
#include <opencv2/gapi/cpu/core.hpp> // Also directly refer to Core
#include <opencv2/gapi/cpu/imgproc.hpp> // ...and Imgproc kernel implementations
#include <opencv2/gapi/cpu/core.hpp> // Also directly refer to Core,
#include <opencv2/gapi/cpu/imgproc.hpp> // ...Imgproc
#include <opencv2/gapi/cpu/video.hpp> // ...and Video kernel implementations
#include <opencv2/gapi/render/render.hpp> // render::ocv::backend()
#endif // !defined(GAPI_STANDALONE)
// </FIXME:>
@@ -66,9 +67,9 @@ namespace
static auto ocv_pkg =
#if !defined(GAPI_STANDALONE)
// FIXME add N-arg version combine
combine(combine(cv::gapi::core::cpu::kernels(),
cv::gapi::imgproc::cpu::kernels()),
combine(cv::gapi::core::cpu::kernels(),
cv::gapi::imgproc::cpu::kernels(),
cv::gapi::video::cpu::kernels(),
cv::gapi::render::ocv::kernels());
#else
cv::gapi::GKernelPackage();