2012-04-30 22:33:52 +08:00
|
|
|
/*M///////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
//
|
|
|
|
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
|
|
|
|
//
|
|
|
|
// By downloading, copying, installing or using the software you agree to this license.
|
|
|
|
// If you do not agree to this license, do not download, install,
|
|
|
|
// copy or use the software.
|
|
|
|
//
|
|
|
|
//
|
|
|
|
// Intel License Agreement
|
|
|
|
// For Open Source Computer Vision Library
|
|
|
|
//
|
|
|
|
// Copyright (C) 2000, Intel Corporation, all rights reserved.
|
|
|
|
// Third party copyrights are property of their respective owners.
|
|
|
|
//
|
|
|
|
// Redistribution and use in source and binary forms, with or without modification,
|
|
|
|
// are permitted provided that the following conditions are met:
|
|
|
|
//
|
|
|
|
// * Redistribution's of source code must retain the above copyright notice,
|
|
|
|
// this list of conditions and the following disclaimer.
|
|
|
|
//
|
|
|
|
// * Redistribution's in binary form must reproduce the above copyright notice,
|
|
|
|
// this list of conditions and the following disclaimer in the documentation
|
|
|
|
// and/or other materials provided with the distribution.
|
|
|
|
//
|
|
|
|
// * The name of Intel Corporation may not be used to endorse or promote products
|
|
|
|
// derived from this software without specific prior written permission.
|
|
|
|
//
|
|
|
|
// This software is provided by the copyright holders and contributors "as is" and
|
|
|
|
// any express or implied warranties, including, but not limited to, the implied
|
|
|
|
// warranties of merchantability and fitness for a particular purpose are disclaimed.
|
|
|
|
// In no event shall the Intel Corporation or contributors be liable for any direct,
|
|
|
|
// indirect, incidental, special, exemplary, or consequential damages
|
|
|
|
// (including, but not limited to, procurement of substitute goods or services;
|
|
|
|
// loss of use, data, or profits; or business interruption) however caused
|
|
|
|
// and on any theory of liability, whether in contract, strict liability,
|
|
|
|
// or tort (including negligence or otherwise) arising in any way out of
|
|
|
|
// the use of this software, even if advised of the possibility of such damage.
|
|
|
|
//
|
|
|
|
//M*/
|
|
|
|
|
2012-08-20 14:15:36 +08:00
|
|
|
#include "test_precomp.hpp"
|
|
|
|
|
|
|
|
#ifdef HAVE_CUDA
|
2012-04-30 22:33:52 +08:00
|
|
|
|
|
|
|
//#define DUMP
|
|
|
|
|
2012-06-05 21:32:04 +08:00
|
|
|
//////////////////////////////////////////////////////
|
2012-04-30 22:33:52 +08:00
|
|
|
// BroxOpticalFlow
|
|
|
|
|
|
|
|
#define BROX_OPTICAL_FLOW_DUMP_FILE "opticalflow/brox_optical_flow.bin"
|
|
|
|
#define BROX_OPTICAL_FLOW_DUMP_FILE_CC20 "opticalflow/brox_optical_flow_cc20.bin"
|
|
|
|
|
|
|
|
struct BroxOpticalFlow : testing::TestWithParam<cv::gpu::DeviceInfo>
|
|
|
|
{
|
|
|
|
cv::gpu::DeviceInfo devInfo;
|
|
|
|
|
|
|
|
virtual void SetUp()
|
|
|
|
{
|
|
|
|
devInfo = GetParam();
|
|
|
|
|
|
|
|
cv::gpu::setDevice(devInfo.deviceID());
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
TEST_P(BroxOpticalFlow, Regression)
|
|
|
|
{
|
2012-12-18 20:59:00 +08:00
|
|
|
try
|
|
|
|
{
|
|
|
|
cv::Mat frame0 = readImageType("opticalflow/frame0.png", CV_32FC1);
|
|
|
|
ASSERT_FALSE(frame0.empty());
|
2012-04-30 22:33:52 +08:00
|
|
|
|
2012-12-18 20:59:00 +08:00
|
|
|
cv::Mat frame1 = readImageType("opticalflow/frame1.png", CV_32FC1);
|
|
|
|
ASSERT_FALSE(frame1.empty());
|
2012-04-30 22:33:52 +08:00
|
|
|
|
2012-12-18 20:59:00 +08:00
|
|
|
cv::gpu::BroxOpticalFlow brox(0.197f /*alpha*/, 50.0f /*gamma*/, 0.8f /*scale_factor*/,
|
|
|
|
10 /*inner_iterations*/, 77 /*outer_iterations*/, 10 /*solver_iterations*/);
|
2012-04-30 22:33:52 +08:00
|
|
|
|
2012-12-18 20:59:00 +08:00
|
|
|
cv::gpu::GpuMat u;
|
|
|
|
cv::gpu::GpuMat v;
|
|
|
|
brox(loadMat(frame0), loadMat(frame1), u, v);
|
2012-04-30 22:33:52 +08:00
|
|
|
|
2012-12-18 20:59:00 +08:00
|
|
|
#ifndef DUMP
|
|
|
|
std::string fname(cvtest::TS::ptr()->get_data_path());
|
|
|
|
if (devInfo.majorVersion() >= 2)
|
|
|
|
fname += BROX_OPTICAL_FLOW_DUMP_FILE_CC20;
|
|
|
|
else
|
|
|
|
fname += BROX_OPTICAL_FLOW_DUMP_FILE;
|
2012-04-30 22:33:52 +08:00
|
|
|
|
2012-12-18 20:59:00 +08:00
|
|
|
std::ifstream f(fname.c_str(), std::ios_base::binary);
|
2012-04-30 22:33:52 +08:00
|
|
|
|
2012-12-18 20:59:00 +08:00
|
|
|
int rows, cols;
|
2012-04-30 22:33:52 +08:00
|
|
|
|
2012-12-18 20:59:00 +08:00
|
|
|
f.read((char*)&rows, sizeof(rows));
|
|
|
|
f.read((char*)&cols, sizeof(cols));
|
2012-04-30 22:33:52 +08:00
|
|
|
|
2012-12-18 20:59:00 +08:00
|
|
|
cv::Mat u_gold(rows, cols, CV_32FC1);
|
2012-04-30 22:33:52 +08:00
|
|
|
|
2012-12-18 20:59:00 +08:00
|
|
|
for (int i = 0; i < u_gold.rows; ++i)
|
|
|
|
f.read(u_gold.ptr<char>(i), u_gold.cols * sizeof(float));
|
2012-04-30 22:33:52 +08:00
|
|
|
|
2012-12-18 20:59:00 +08:00
|
|
|
cv::Mat v_gold(rows, cols, CV_32FC1);
|
2012-04-30 22:33:52 +08:00
|
|
|
|
2012-12-18 20:59:00 +08:00
|
|
|
for (int i = 0; i < v_gold.rows; ++i)
|
|
|
|
f.read(v_gold.ptr<char>(i), v_gold.cols * sizeof(float));
|
2012-04-30 22:33:52 +08:00
|
|
|
|
2012-12-18 20:59:00 +08:00
|
|
|
EXPECT_MAT_NEAR(u_gold, u, 0);
|
|
|
|
EXPECT_MAT_NEAR(v_gold, v, 0);
|
|
|
|
#else
|
|
|
|
std::string fname(cvtest::TS::ptr()->get_data_path());
|
|
|
|
if (devInfo.majorVersion() >= 2)
|
|
|
|
fname += BROX_OPTICAL_FLOW_DUMP_FILE_CC20;
|
|
|
|
else
|
|
|
|
fname += BROX_OPTICAL_FLOW_DUMP_FILE;
|
2012-04-30 22:33:52 +08:00
|
|
|
|
2012-12-18 20:59:00 +08:00
|
|
|
std::ofstream f(fname.c_str(), std::ios_base::binary);
|
2012-04-30 22:33:52 +08:00
|
|
|
|
2012-12-18 20:59:00 +08:00
|
|
|
f.write((char*)&u.rows, sizeof(u.rows));
|
|
|
|
f.write((char*)&u.cols, sizeof(u.cols));
|
2012-04-30 22:33:52 +08:00
|
|
|
|
2012-12-18 20:59:00 +08:00
|
|
|
cv::Mat h_u(u);
|
|
|
|
cv::Mat h_v(v);
|
2012-04-30 22:33:52 +08:00
|
|
|
|
2012-12-18 20:59:00 +08:00
|
|
|
for (int i = 0; i < u.rows; ++i)
|
|
|
|
f.write(h_u.ptr<char>(i), u.cols * sizeof(float));
|
2012-04-30 22:33:52 +08:00
|
|
|
|
2012-12-18 20:59:00 +08:00
|
|
|
for (int i = 0; i < v.rows; ++i)
|
|
|
|
f.write(h_v.ptr<char>(i), v.cols * sizeof(float));
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
catch (...)
|
|
|
|
{
|
|
|
|
cv::gpu::resetDevice();
|
|
|
|
throw;
|
|
|
|
}
|
2012-04-30 22:33:52 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
INSTANTIATE_TEST_CASE_P(GPU_Video, BroxOpticalFlow, ALL_DEVICES);
|
|
|
|
|
2012-06-05 21:32:04 +08:00
|
|
|
//////////////////////////////////////////////////////
|
2012-04-30 22:33:52 +08:00
|
|
|
// GoodFeaturesToTrack
|
|
|
|
|
|
|
|
IMPLEMENT_PARAM_CLASS(MinDistance, double)
|
|
|
|
|
|
|
|
PARAM_TEST_CASE(GoodFeaturesToTrack, cv::gpu::DeviceInfo, MinDistance)
|
|
|
|
{
|
|
|
|
cv::gpu::DeviceInfo devInfo;
|
|
|
|
double minDistance;
|
|
|
|
|
|
|
|
virtual void SetUp()
|
|
|
|
{
|
|
|
|
devInfo = GET_PARAM(0);
|
|
|
|
minDistance = GET_PARAM(1);
|
|
|
|
|
|
|
|
cv::gpu::setDevice(devInfo.deviceID());
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
TEST_P(GoodFeaturesToTrack, Accuracy)
|
|
|
|
{
|
2012-12-18 20:59:00 +08:00
|
|
|
try
|
|
|
|
{
|
|
|
|
cv::Mat image = readImage("opticalflow/frame0.png", cv::IMREAD_GRAYSCALE);
|
|
|
|
ASSERT_FALSE(image.empty());
|
2012-04-30 22:33:52 +08:00
|
|
|
|
2012-12-18 20:59:00 +08:00
|
|
|
int maxCorners = 1000;
|
|
|
|
double qualityLevel = 0.01;
|
2012-04-30 22:33:52 +08:00
|
|
|
|
2012-12-18 20:59:00 +08:00
|
|
|
cv::gpu::GoodFeaturesToTrackDetector_GPU detector(maxCorners, qualityLevel, minDistance);
|
2012-04-30 22:33:52 +08:00
|
|
|
|
|
|
|
cv::gpu::GpuMat d_pts;
|
|
|
|
detector(loadMat(image), d_pts);
|
|
|
|
|
|
|
|
std::vector<cv::Point2f> pts(d_pts.cols);
|
|
|
|
cv::Mat pts_mat(1, d_pts.cols, CV_32FC2, (void*)&pts[0]);
|
|
|
|
d_pts.download(pts_mat);
|
|
|
|
|
|
|
|
std::vector<cv::Point2f> pts_gold;
|
|
|
|
cv::goodFeaturesToTrack(image, pts_gold, maxCorners, qualityLevel, minDistance);
|
|
|
|
|
|
|
|
ASSERT_EQ(pts_gold.size(), pts.size());
|
|
|
|
|
|
|
|
size_t mistmatch = 0;
|
|
|
|
for (size_t i = 0; i < pts.size(); ++i)
|
|
|
|
{
|
|
|
|
cv::Point2i a = pts_gold[i];
|
|
|
|
cv::Point2i b = pts[i];
|
|
|
|
|
|
|
|
bool eq = std::abs(a.x - b.x) < 1 && std::abs(a.y - b.y) < 1;
|
|
|
|
|
|
|
|
if (!eq)
|
|
|
|
++mistmatch;
|
|
|
|
}
|
|
|
|
|
|
|
|
double bad_ratio = static_cast<double>(mistmatch) / pts.size();
|
|
|
|
|
|
|
|
ASSERT_LE(bad_ratio, 0.01);
|
|
|
|
}
|
2012-12-18 20:59:00 +08:00
|
|
|
catch (...)
|
|
|
|
{
|
|
|
|
cv::gpu::resetDevice();
|
|
|
|
throw;
|
|
|
|
}
|
2012-04-30 22:33:52 +08:00
|
|
|
}
|
|
|
|
|
2012-11-29 15:17:04 +08:00
|
|
|
TEST_P(GoodFeaturesToTrack, EmptyCorners)
|
|
|
|
{
|
2012-12-18 20:59:00 +08:00
|
|
|
try
|
|
|
|
{
|
|
|
|
int maxCorners = 1000;
|
|
|
|
double qualityLevel = 0.01;
|
2012-11-29 15:17:04 +08:00
|
|
|
|
2012-12-18 20:59:00 +08:00
|
|
|
cv::gpu::GoodFeaturesToTrackDetector_GPU detector(maxCorners, qualityLevel, minDistance);
|
2012-11-29 15:17:04 +08:00
|
|
|
|
2012-12-18 20:59:00 +08:00
|
|
|
cv::gpu::GpuMat src(100, 100, CV_8UC1, cv::Scalar::all(0));
|
|
|
|
cv::gpu::GpuMat corners(1, maxCorners, CV_32FC2);
|
2012-11-29 15:17:04 +08:00
|
|
|
|
2012-12-18 20:59:00 +08:00
|
|
|
detector(src, corners);
|
2012-11-29 15:17:04 +08:00
|
|
|
|
2012-12-18 20:59:00 +08:00
|
|
|
ASSERT_TRUE( corners.empty() );
|
|
|
|
}
|
|
|
|
catch (...)
|
|
|
|
{
|
|
|
|
cv::gpu::resetDevice();
|
|
|
|
throw;
|
|
|
|
}
|
2012-11-29 15:17:04 +08:00
|
|
|
}
|
|
|
|
|
2012-04-30 22:33:52 +08:00
|
|
|
INSTANTIATE_TEST_CASE_P(GPU_Video, GoodFeaturesToTrack, testing::Combine(
|
|
|
|
ALL_DEVICES,
|
|
|
|
testing::Values(MinDistance(0.0), MinDistance(3.0))));
|
|
|
|
|
2012-06-05 21:32:04 +08:00
|
|
|
//////////////////////////////////////////////////////
|
2012-04-30 22:33:52 +08:00
|
|
|
// PyrLKOpticalFlow
|
|
|
|
|
|
|
|
IMPLEMENT_PARAM_CLASS(UseGray, bool)
|
|
|
|
|
|
|
|
PARAM_TEST_CASE(PyrLKOpticalFlow, cv::gpu::DeviceInfo, UseGray)
|
|
|
|
{
|
|
|
|
cv::gpu::DeviceInfo devInfo;
|
|
|
|
bool useGray;
|
|
|
|
|
|
|
|
virtual void SetUp()
|
|
|
|
{
|
|
|
|
devInfo = GET_PARAM(0);
|
|
|
|
useGray = GET_PARAM(1);
|
|
|
|
|
|
|
|
cv::gpu::setDevice(devInfo.deviceID());
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
TEST_P(PyrLKOpticalFlow, Sparse)
|
|
|
|
{
|
2012-12-18 20:59:00 +08:00
|
|
|
try
|
|
|
|
{
|
|
|
|
cv::Mat frame0 = readImage("opticalflow/frame0.png", useGray ? cv::IMREAD_GRAYSCALE : cv::IMREAD_COLOR);
|
|
|
|
ASSERT_FALSE(frame0.empty());
|
2012-04-30 22:33:52 +08:00
|
|
|
|
2012-12-18 20:59:00 +08:00
|
|
|
cv::Mat frame1 = readImage("opticalflow/frame1.png", useGray ? cv::IMREAD_GRAYSCALE : cv::IMREAD_COLOR);
|
|
|
|
ASSERT_FALSE(frame1.empty());
|
2012-04-30 22:33:52 +08:00
|
|
|
|
2012-12-18 20:59:00 +08:00
|
|
|
cv::Mat gray_frame;
|
|
|
|
if (useGray)
|
|
|
|
gray_frame = frame0;
|
|
|
|
else
|
|
|
|
cv::cvtColor(frame0, gray_frame, cv::COLOR_BGR2GRAY);
|
2012-04-30 22:33:52 +08:00
|
|
|
|
2012-12-18 20:59:00 +08:00
|
|
|
std::vector<cv::Point2f> pts;
|
|
|
|
cv::goodFeaturesToTrack(gray_frame, pts, 1000, 0.01, 0.0);
|
2012-04-30 22:33:52 +08:00
|
|
|
|
2012-12-18 20:59:00 +08:00
|
|
|
cv::gpu::GpuMat d_pts;
|
|
|
|
cv::Mat pts_mat(1, (int)pts.size(), CV_32FC2, (void*)&pts[0]);
|
|
|
|
d_pts.upload(pts_mat);
|
2012-04-30 22:33:52 +08:00
|
|
|
|
2012-12-18 20:59:00 +08:00
|
|
|
cv::gpu::PyrLKOpticalFlow pyrLK;
|
2012-04-30 22:33:52 +08:00
|
|
|
|
2012-12-18 20:59:00 +08:00
|
|
|
cv::gpu::GpuMat d_nextPts;
|
|
|
|
cv::gpu::GpuMat d_status;
|
|
|
|
pyrLK.sparse(loadMat(frame0), loadMat(frame1), d_pts, d_nextPts, d_status);
|
2012-04-30 22:33:52 +08:00
|
|
|
|
2012-12-18 20:59:00 +08:00
|
|
|
std::vector<cv::Point2f> nextPts(d_nextPts.cols);
|
|
|
|
cv::Mat nextPts_mat(1, d_nextPts.cols, CV_32FC2, (void*)&nextPts[0]);
|
|
|
|
d_nextPts.download(nextPts_mat);
|
2012-04-30 22:33:52 +08:00
|
|
|
|
2012-12-18 20:59:00 +08:00
|
|
|
std::vector<unsigned char> status(d_status.cols);
|
|
|
|
cv::Mat status_mat(1, d_status.cols, CV_8UC1, (void*)&status[0]);
|
|
|
|
d_status.download(status_mat);
|
2012-04-30 22:33:52 +08:00
|
|
|
|
2012-12-18 20:59:00 +08:00
|
|
|
std::vector<cv::Point2f> nextPts_gold;
|
|
|
|
std::vector<unsigned char> status_gold;
|
|
|
|
cv::calcOpticalFlowPyrLK(frame0, frame1, pts, nextPts_gold, status_gold, cv::noArray());
|
2012-06-18 14:49:10 +08:00
|
|
|
|
2012-12-18 20:59:00 +08:00
|
|
|
ASSERT_EQ(nextPts_gold.size(), nextPts.size());
|
|
|
|
ASSERT_EQ(status_gold.size(), status.size());
|
2012-04-30 22:33:52 +08:00
|
|
|
|
2012-12-18 20:59:00 +08:00
|
|
|
size_t mistmatch = 0;
|
|
|
|
for (size_t i = 0; i < nextPts.size(); ++i)
|
2012-04-30 22:33:52 +08:00
|
|
|
{
|
2012-12-18 20:59:00 +08:00
|
|
|
cv::Point2i a = nextPts[i];
|
|
|
|
cv::Point2i b = nextPts_gold[i];
|
2012-04-30 22:33:52 +08:00
|
|
|
|
2012-12-18 20:59:00 +08:00
|
|
|
if (status[i] != status_gold[i])
|
|
|
|
{
|
2012-04-30 22:33:52 +08:00
|
|
|
++mistmatch;
|
2012-12-18 20:59:00 +08:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (status[i])
|
|
|
|
{
|
|
|
|
bool eq = std::abs(a.x - b.x) <= 1 && std::abs(a.y - b.y) <= 1;
|
|
|
|
|
|
|
|
if (!eq)
|
|
|
|
++mistmatch;
|
|
|
|
}
|
2012-04-30 22:33:52 +08:00
|
|
|
}
|
|
|
|
|
2012-12-18 20:59:00 +08:00
|
|
|
double bad_ratio = static_cast<double>(mistmatch) / nextPts.size();
|
2012-04-30 22:33:52 +08:00
|
|
|
|
2012-12-18 20:59:00 +08:00
|
|
|
ASSERT_LE(bad_ratio, 0.01);
|
|
|
|
}
|
|
|
|
catch (...)
|
|
|
|
{
|
|
|
|
cv::gpu::resetDevice();
|
|
|
|
throw;
|
|
|
|
}
|
2012-04-30 22:33:52 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
INSTANTIATE_TEST_CASE_P(GPU_Video, PyrLKOpticalFlow, testing::Combine(
|
|
|
|
ALL_DEVICES,
|
|
|
|
testing::Values(UseGray(true), UseGray(false))));
|
|
|
|
|
2012-06-05 21:32:04 +08:00
|
|
|
//////////////////////////////////////////////////////
|
2012-04-30 22:33:52 +08:00
|
|
|
// FarnebackOpticalFlow
|
|
|
|
|
|
|
|
IMPLEMENT_PARAM_CLASS(PyrScale, double)
|
|
|
|
IMPLEMENT_PARAM_CLASS(PolyN, int)
|
|
|
|
CV_FLAGS(FarnebackOptFlowFlags, 0, cv::OPTFLOW_FARNEBACK_GAUSSIAN)
|
|
|
|
IMPLEMENT_PARAM_CLASS(UseInitFlow, bool)
|
|
|
|
|
|
|
|
PARAM_TEST_CASE(FarnebackOpticalFlow, cv::gpu::DeviceInfo, PyrScale, PolyN, FarnebackOptFlowFlags, UseInitFlow)
|
|
|
|
{
|
|
|
|
cv::gpu::DeviceInfo devInfo;
|
|
|
|
double pyrScale;
|
|
|
|
int polyN;
|
|
|
|
int flags;
|
|
|
|
bool useInitFlow;
|
|
|
|
|
|
|
|
virtual void SetUp()
|
|
|
|
{
|
|
|
|
devInfo = GET_PARAM(0);
|
|
|
|
pyrScale = GET_PARAM(1);
|
|
|
|
polyN = GET_PARAM(2);
|
|
|
|
flags = GET_PARAM(3);
|
|
|
|
useInitFlow = GET_PARAM(4);
|
|
|
|
|
|
|
|
cv::gpu::setDevice(devInfo.deviceID());
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
TEST_P(FarnebackOpticalFlow, Accuracy)
|
|
|
|
{
|
2012-12-18 20:59:00 +08:00
|
|
|
try
|
|
|
|
{
|
|
|
|
cv::Mat frame0 = readImage("opticalflow/rubberwhale1.png", cv::IMREAD_GRAYSCALE);
|
|
|
|
ASSERT_FALSE(frame0.empty());
|
2012-04-30 22:33:52 +08:00
|
|
|
|
2012-12-18 20:59:00 +08:00
|
|
|
cv::Mat frame1 = readImage("opticalflow/rubberwhale2.png", cv::IMREAD_GRAYSCALE);
|
|
|
|
ASSERT_FALSE(frame1.empty());
|
2012-04-30 22:33:52 +08:00
|
|
|
|
2012-12-18 20:59:00 +08:00
|
|
|
double polySigma = polyN <= 5 ? 1.1 : 1.5;
|
2012-04-30 22:33:52 +08:00
|
|
|
|
2012-12-18 20:59:00 +08:00
|
|
|
cv::gpu::FarnebackOpticalFlow calc;
|
|
|
|
calc.pyrScale = pyrScale;
|
|
|
|
calc.polyN = polyN;
|
|
|
|
calc.polySigma = polySigma;
|
|
|
|
calc.flags = flags;
|
2012-04-30 22:33:52 +08:00
|
|
|
|
2012-12-18 20:59:00 +08:00
|
|
|
cv::gpu::GpuMat d_flowx, d_flowy;
|
|
|
|
calc(loadMat(frame0), loadMat(frame1), d_flowx, d_flowy);
|
2012-04-30 22:33:52 +08:00
|
|
|
|
2012-12-18 20:59:00 +08:00
|
|
|
cv::Mat flow;
|
|
|
|
if (useInitFlow)
|
|
|
|
{
|
|
|
|
cv::Mat flowxy[] = {cv::Mat(d_flowx), cv::Mat(d_flowy)};
|
|
|
|
cv::merge(flowxy, 2, flow);
|
|
|
|
}
|
2012-04-30 22:33:52 +08:00
|
|
|
|
2012-12-18 20:59:00 +08:00
|
|
|
if (useInitFlow)
|
|
|
|
{
|
|
|
|
calc.flags |= cv::OPTFLOW_USE_INITIAL_FLOW;
|
|
|
|
calc(loadMat(frame0), loadMat(frame1), d_flowx, d_flowy);
|
|
|
|
}
|
2012-04-30 22:33:52 +08:00
|
|
|
|
2012-12-18 20:59:00 +08:00
|
|
|
cv::calcOpticalFlowFarneback(
|
|
|
|
frame0, frame1, flow, calc.pyrScale, calc.numLevels, calc.winSize,
|
|
|
|
calc.numIters, calc.polyN, calc.polySigma, calc.flags);
|
2012-04-30 22:33:52 +08:00
|
|
|
|
2012-12-18 20:59:00 +08:00
|
|
|
std::vector<cv::Mat> flowxy;
|
|
|
|
cv::split(flow, flowxy);
|
2012-04-30 22:33:52 +08:00
|
|
|
|
2012-12-18 20:59:00 +08:00
|
|
|
EXPECT_MAT_SIMILAR(flowxy[0], d_flowx, 0.1);
|
|
|
|
EXPECT_MAT_SIMILAR(flowxy[1], d_flowy, 0.1);
|
|
|
|
}
|
|
|
|
catch (...)
|
|
|
|
{
|
|
|
|
cv::gpu::resetDevice();
|
|
|
|
throw;
|
|
|
|
}
|
2012-05-02 21:07:30 +08:00
|
|
|
}
|
2012-04-30 22:33:52 +08:00
|
|
|
|
|
|
|
INSTANTIATE_TEST_CASE_P(GPU_Video, FarnebackOpticalFlow, testing::Combine(
|
|
|
|
ALL_DEVICES,
|
|
|
|
testing::Values(PyrScale(0.3), PyrScale(0.5), PyrScale(0.8)),
|
|
|
|
testing::Values(PolyN(5), PolyN(7)),
|
|
|
|
testing::Values(FarnebackOptFlowFlags(0), FarnebackOptFlowFlags(cv::OPTFLOW_FARNEBACK_GAUSSIAN)),
|
|
|
|
testing::Values(UseInitFlow(false), UseInitFlow(true))));
|
|
|
|
|
|
|
|
struct OpticalFlowNan : public BroxOpticalFlow {};
|
|
|
|
|
|
|
|
TEST_P(OpticalFlowNan, Regression)
|
|
|
|
{
|
2012-12-18 20:59:00 +08:00
|
|
|
try
|
|
|
|
{
|
|
|
|
cv::Mat frame0 = readImageType("opticalflow/frame0.png", CV_32FC1);
|
|
|
|
ASSERT_FALSE(frame0.empty());
|
|
|
|
cv::Mat r_frame0, r_frame1;
|
|
|
|
cv::resize(frame0, r_frame0, cv::Size(1380,1000));
|
|
|
|
|
|
|
|
cv::Mat frame1 = readImageType("opticalflow/frame1.png", CV_32FC1);
|
|
|
|
ASSERT_FALSE(frame1.empty());
|
|
|
|
cv::resize(frame1, r_frame1, cv::Size(1380,1000));
|
|
|
|
|
|
|
|
cv::gpu::BroxOpticalFlow brox(0.197f /*alpha*/, 50.0f /*gamma*/, 0.8f /*scale_factor*/,
|
|
|
|
5 /*inner_iterations*/, 150 /*outer_iterations*/, 10 /*solver_iterations*/);
|
|
|
|
|
|
|
|
cv::gpu::GpuMat u;
|
|
|
|
cv::gpu::GpuMat v;
|
|
|
|
brox(loadMat(r_frame0), loadMat(r_frame1), u, v);
|
|
|
|
|
|
|
|
cv::Mat h_u, h_v;
|
|
|
|
u.download(h_u);
|
|
|
|
v.download(h_v);
|
|
|
|
EXPECT_TRUE(cv::checkRange(h_u));
|
|
|
|
EXPECT_TRUE(cv::checkRange(h_v));
|
|
|
|
}
|
|
|
|
catch (...)
|
|
|
|
{
|
|
|
|
cv::gpu::resetDevice();
|
|
|
|
throw;
|
|
|
|
}
|
2012-04-30 22:33:52 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
INSTANTIATE_TEST_CASE_P(GPU_Video, OpticalFlowNan, ALL_DEVICES);
|
|
|
|
|
2012-06-05 21:32:04 +08:00
|
|
|
//////////////////////////////////////////////////////
|
2012-10-25 17:27:14 +08:00
|
|
|
// OpticalFlowDual_TVL1
|
|
|
|
|
|
|
|
PARAM_TEST_CASE(OpticalFlowDual_TVL1, cv::gpu::DeviceInfo, UseRoi)
|
|
|
|
{
|
|
|
|
};
|
|
|
|
|
|
|
|
TEST_P(OpticalFlowDual_TVL1, Accuracy)
|
|
|
|
{
|
2012-12-18 20:59:00 +08:00
|
|
|
try
|
|
|
|
{
|
|
|
|
cv::gpu::DeviceInfo devInfo = GET_PARAM(0);
|
|
|
|
cv::gpu::setDevice(devInfo.deviceID());
|
2012-10-25 17:27:14 +08:00
|
|
|
|
2012-12-18 20:59:00 +08:00
|
|
|
const bool useRoi = GET_PARAM(1);
|
2012-10-25 17:27:14 +08:00
|
|
|
|
2012-12-18 20:59:00 +08:00
|
|
|
cv::Mat frame0 = readImage("opticalflow/rubberwhale1.png", cv::IMREAD_GRAYSCALE);
|
|
|
|
ASSERT_FALSE(frame0.empty());
|
2012-10-25 17:27:14 +08:00
|
|
|
|
2012-12-18 20:59:00 +08:00
|
|
|
cv::Mat frame1 = readImage("opticalflow/rubberwhale2.png", cv::IMREAD_GRAYSCALE);
|
|
|
|
ASSERT_FALSE(frame1.empty());
|
2012-10-25 17:27:14 +08:00
|
|
|
|
2012-12-18 20:59:00 +08:00
|
|
|
cv::gpu::OpticalFlowDual_TVL1_GPU d_alg;
|
|
|
|
cv::gpu::GpuMat d_flowx = createMat(frame0.size(), CV_32FC1, useRoi);
|
|
|
|
cv::gpu::GpuMat d_flowy = createMat(frame0.size(), CV_32FC1, useRoi);
|
|
|
|
d_alg(loadMat(frame0, useRoi), loadMat(frame1, useRoi), d_flowx, d_flowy);
|
2012-10-25 17:27:14 +08:00
|
|
|
|
2012-12-18 20:59:00 +08:00
|
|
|
cv::OpticalFlowDual_TVL1 alg;
|
|
|
|
cv::Mat flow;
|
|
|
|
alg(frame0, frame1, flow);
|
|
|
|
cv::Mat gold[2];
|
|
|
|
cv::split(flow, gold);
|
2012-10-25 17:27:14 +08:00
|
|
|
|
2012-12-18 20:59:00 +08:00
|
|
|
EXPECT_MAT_SIMILAR(gold[0], d_flowx, 3e-3);
|
|
|
|
EXPECT_MAT_SIMILAR(gold[1], d_flowy, 3e-3);
|
|
|
|
}
|
|
|
|
catch (...)
|
|
|
|
{
|
|
|
|
cv::gpu::resetDevice();
|
|
|
|
throw;
|
|
|
|
}
|
2012-10-25 17:27:14 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
INSTANTIATE_TEST_CASE_P(GPU_Video, OpticalFlowDual_TVL1, testing::Combine(
|
|
|
|
ALL_DEVICES,
|
|
|
|
WHOLE_SUBMAT));
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////
|
2012-12-06 19:11:13 +08:00
|
|
|
// OpticalFlowBM
|
|
|
|
|
|
|
|
void calcOpticalFlowBM(const cv::Mat& prev, const cv::Mat& curr,
|
|
|
|
cv::Size bSize, cv::Size shiftSize, cv::Size maxRange, int usePrevious,
|
|
|
|
cv::Mat& velx, cv::Mat& vely)
|
|
|
|
{
|
|
|
|
cv::Size sz((curr.cols - bSize.width + shiftSize.width)/shiftSize.width, (curr.rows - bSize.height + shiftSize.height)/shiftSize.height);
|
|
|
|
|
|
|
|
velx.create(sz, CV_32FC1);
|
|
|
|
vely.create(sz, CV_32FC1);
|
|
|
|
|
|
|
|
CvMat cvprev = prev;
|
|
|
|
CvMat cvcurr = curr;
|
|
|
|
|
|
|
|
CvMat cvvelx = velx;
|
|
|
|
CvMat cvvely = vely;
|
|
|
|
|
|
|
|
cvCalcOpticalFlowBM(&cvprev, &cvcurr, bSize, shiftSize, maxRange, usePrevious, &cvvelx, &cvvely);
|
|
|
|
}
|
|
|
|
|
|
|
|
struct OpticalFlowBM : testing::TestWithParam<cv::gpu::DeviceInfo>
|
|
|
|
{
|
|
|
|
};
|
|
|
|
|
|
|
|
TEST_P(OpticalFlowBM, Accuracy)
|
|
|
|
{
|
2012-12-18 20:59:00 +08:00
|
|
|
try
|
|
|
|
{
|
|
|
|
cv::gpu::DeviceInfo devInfo = GetParam();
|
|
|
|
cv::gpu::setDevice(devInfo.deviceID());
|
2012-12-06 19:11:13 +08:00
|
|
|
|
2012-12-18 20:59:00 +08:00
|
|
|
cv::Mat frame0 = readImage("opticalflow/rubberwhale1.png", cv::IMREAD_GRAYSCALE);
|
|
|
|
ASSERT_FALSE(frame0.empty());
|
2012-12-06 19:11:13 +08:00
|
|
|
|
2012-12-18 20:59:00 +08:00
|
|
|
cv::Mat frame1 = readImage("opticalflow/rubberwhale2.png", cv::IMREAD_GRAYSCALE);
|
|
|
|
ASSERT_FALSE(frame1.empty());
|
2012-12-06 19:11:13 +08:00
|
|
|
|
2012-12-18 20:59:00 +08:00
|
|
|
cv::Size block_size(16, 16);
|
|
|
|
cv::Size shift_size(1, 1);
|
|
|
|
cv::Size max_range(16, 16);
|
2012-12-06 19:11:13 +08:00
|
|
|
|
2012-12-18 20:59:00 +08:00
|
|
|
cv::gpu::GpuMat d_velx, d_vely, buf;
|
|
|
|
cv::gpu::calcOpticalFlowBM(loadMat(frame0), loadMat(frame1),
|
|
|
|
block_size, shift_size, max_range, false,
|
|
|
|
d_velx, d_vely, buf);
|
2012-12-06 19:11:13 +08:00
|
|
|
|
2012-12-18 20:59:00 +08:00
|
|
|
cv::Mat velx, vely;
|
|
|
|
calcOpticalFlowBM(frame0, frame1, block_size, shift_size, max_range, false, velx, vely);
|
2012-12-06 19:11:13 +08:00
|
|
|
|
2012-12-18 20:59:00 +08:00
|
|
|
EXPECT_MAT_NEAR(velx, d_velx, 0);
|
|
|
|
EXPECT_MAT_NEAR(vely, d_vely, 0);
|
|
|
|
}
|
|
|
|
catch (...)
|
|
|
|
{
|
|
|
|
cv::gpu::resetDevice();
|
|
|
|
throw;
|
|
|
|
}
|
2012-12-06 19:11:13 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
INSTANTIATE_TEST_CASE_P(GPU_Video, OpticalFlowBM, ALL_DEVICES);
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////
|
2012-12-17 14:39:19 +08:00
|
|
|
// FastOpticalFlowBM
|
|
|
|
|
|
|
|
static void FastOpticalFlowBM_gold(const cv::Mat_<uchar>& I0, const cv::Mat_<uchar>& I1, cv::Mat_<float>& velx, cv::Mat_<float>& vely, int search_window, int block_window)
|
|
|
|
{
|
|
|
|
velx.create(I0.size());
|
|
|
|
vely.create(I0.size());
|
|
|
|
|
|
|
|
int search_radius = search_window / 2;
|
|
|
|
int block_radius = block_window / 2;
|
|
|
|
|
|
|
|
for (int y = 0; y < I0.rows; ++y)
|
|
|
|
{
|
|
|
|
for (int x = 0; x < I0.cols; ++x)
|
|
|
|
{
|
|
|
|
int bestDist = std::numeric_limits<int>::max();
|
|
|
|
int bestDx = 0;
|
|
|
|
int bestDy = 0;
|
|
|
|
|
|
|
|
for (int dy = -search_radius; dy <= search_radius; ++dy)
|
|
|
|
{
|
|
|
|
for (int dx = -search_radius; dx <= search_radius; ++dx)
|
|
|
|
{
|
|
|
|
int dist = 0;
|
|
|
|
|
|
|
|
for (int by = -block_radius; by <= block_radius; ++by)
|
|
|
|
{
|
|
|
|
for (int bx = -block_radius; bx <= block_radius; ++bx)
|
|
|
|
{
|
|
|
|
int I0_val = I0(cv::borderInterpolate(y + by, I0.rows, cv::BORDER_DEFAULT), cv::borderInterpolate(x + bx, I0.cols, cv::BORDER_DEFAULT));
|
|
|
|
int I1_val = I1(cv::borderInterpolate(y + dy + by, I0.rows, cv::BORDER_DEFAULT), cv::borderInterpolate(x + dx + bx, I0.cols, cv::BORDER_DEFAULT));
|
|
|
|
|
|
|
|
dist += std::abs(I0_val - I1_val);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (dist < bestDist)
|
|
|
|
{
|
|
|
|
bestDist = dist;
|
|
|
|
bestDx = dx;
|
|
|
|
bestDy = dy;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-12-18 22:03:54 +08:00
|
|
|
velx(y, x) = (float) bestDx;
|
|
|
|
vely(y, x) = (float) bestDy;
|
2012-12-17 14:39:19 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static double calc_rmse(const cv::Mat_<float>& flow1, const cv::Mat_<float>& flow2)
|
|
|
|
{
|
|
|
|
double sum = 0.0;
|
|
|
|
|
|
|
|
for (int y = 0; y < flow1.rows; ++y)
|
|
|
|
{
|
|
|
|
for (int x = 0; x < flow1.cols; ++x)
|
|
|
|
{
|
|
|
|
double diff = flow1(y, x) - flow2(y, x);
|
|
|
|
sum += diff * diff;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return std::sqrt(sum / flow1.size().area());
|
|
|
|
}
|
|
|
|
|
|
|
|
struct FastOpticalFlowBM : testing::TestWithParam<cv::gpu::DeviceInfo>
|
|
|
|
{
|
|
|
|
};
|
|
|
|
|
|
|
|
TEST_P(FastOpticalFlowBM, Accuracy)
|
|
|
|
{
|
2012-12-18 20:59:00 +08:00
|
|
|
try
|
|
|
|
{
|
|
|
|
const double MAX_RMSE = 0.6;
|
2012-12-17 14:39:19 +08:00
|
|
|
|
2012-12-18 20:59:00 +08:00
|
|
|
int search_window = 15;
|
|
|
|
int block_window = 5;
|
2012-12-17 14:39:19 +08:00
|
|
|
|
2012-12-18 20:59:00 +08:00
|
|
|
cv::gpu::DeviceInfo devInfo = GetParam();
|
|
|
|
cv::gpu::setDevice(devInfo.deviceID());
|
2012-12-17 14:39:19 +08:00
|
|
|
|
2012-12-18 20:59:00 +08:00
|
|
|
cv::Mat frame0 = readImage("opticalflow/rubberwhale1.png", cv::IMREAD_GRAYSCALE);
|
|
|
|
ASSERT_FALSE(frame0.empty());
|
2012-12-17 14:39:19 +08:00
|
|
|
|
2012-12-18 20:59:00 +08:00
|
|
|
cv::Mat frame1 = readImage("opticalflow/rubberwhale2.png", cv::IMREAD_GRAYSCALE);
|
|
|
|
ASSERT_FALSE(frame1.empty());
|
2012-12-17 14:39:19 +08:00
|
|
|
|
2012-12-18 20:59:00 +08:00
|
|
|
cv::Size smallSize(320, 240);
|
|
|
|
cv::Mat frame0_small;
|
|
|
|
cv::Mat frame1_small;
|
2012-12-17 14:39:19 +08:00
|
|
|
|
2012-12-18 20:59:00 +08:00
|
|
|
cv::resize(frame0, frame0_small, smallSize);
|
|
|
|
cv::resize(frame1, frame1_small, smallSize);
|
2012-12-17 14:39:19 +08:00
|
|
|
|
2012-12-18 20:59:00 +08:00
|
|
|
cv::gpu::GpuMat d_flowx;
|
|
|
|
cv::gpu::GpuMat d_flowy;
|
|
|
|
cv::gpu::FastOpticalFlowBM fastBM;
|
2012-12-17 14:39:19 +08:00
|
|
|
|
2012-12-18 20:59:00 +08:00
|
|
|
fastBM(loadMat(frame0_small), loadMat(frame1_small), d_flowx, d_flowy, search_window, block_window);
|
2012-12-17 14:39:19 +08:00
|
|
|
|
2012-12-18 20:59:00 +08:00
|
|
|
cv::Mat_<float> flowx;
|
|
|
|
cv::Mat_<float> flowy;
|
|
|
|
FastOpticalFlowBM_gold(frame0_small, frame1_small, flowx, flowy, search_window, block_window);
|
2012-12-17 14:39:19 +08:00
|
|
|
|
2012-12-18 20:59:00 +08:00
|
|
|
double err;
|
2012-12-17 14:39:19 +08:00
|
|
|
|
2012-12-18 20:59:00 +08:00
|
|
|
err = calc_rmse(flowx, cv::Mat(d_flowx));
|
|
|
|
EXPECT_LE(err, MAX_RMSE);
|
2012-12-17 14:39:19 +08:00
|
|
|
|
2012-12-18 20:59:00 +08:00
|
|
|
err = calc_rmse(flowy, cv::Mat(d_flowy));
|
|
|
|
EXPECT_LE(err, MAX_RMSE);
|
|
|
|
}
|
|
|
|
catch (...)
|
|
|
|
{
|
|
|
|
cv::gpu::resetDevice();
|
|
|
|
throw;
|
|
|
|
}
|
2012-12-17 14:39:19 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
INSTANTIATE_TEST_CASE_P(GPU_Video, FastOpticalFlowBM, ALL_DEVICES);
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////
|
2012-06-05 21:32:04 +08:00
|
|
|
// FGDStatModel
|
|
|
|
|
|
|
|
namespace cv
|
|
|
|
{
|
|
|
|
template<> void Ptr<CvBGStatModel>::delete_obj()
|
|
|
|
{
|
|
|
|
cvReleaseBGStatModel(&obj);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
PARAM_TEST_CASE(FGDStatModel, cv::gpu::DeviceInfo, std::string, Channels)
|
|
|
|
{
|
2012-06-25 19:13:50 +08:00
|
|
|
cv::gpu::DeviceInfo devInfo;
|
|
|
|
std::string inputFile;
|
|
|
|
int out_cn;
|
2012-06-05 21:32:04 +08:00
|
|
|
|
2012-06-25 19:13:50 +08:00
|
|
|
virtual void SetUp()
|
|
|
|
{
|
|
|
|
devInfo = GET_PARAM(0);
|
|
|
|
cv::gpu::setDevice(devInfo.deviceID());
|
2012-06-05 21:32:04 +08:00
|
|
|
|
2012-06-25 19:13:50 +08:00
|
|
|
inputFile = std::string(cvtest::TS::ptr()->get_data_path()) + "video/" + GET_PARAM(1);
|
2012-06-05 21:32:04 +08:00
|
|
|
|
2012-06-25 19:13:50 +08:00
|
|
|
out_cn = GET_PARAM(2);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
TEST_P(FGDStatModel, Update)
|
|
|
|
{
|
2012-12-18 20:59:00 +08:00
|
|
|
try
|
|
|
|
{
|
|
|
|
cv::VideoCapture cap(inputFile);
|
|
|
|
ASSERT_TRUE(cap.isOpened());
|
2012-06-05 21:32:04 +08:00
|
|
|
|
2012-12-18 20:59:00 +08:00
|
|
|
cv::Mat frame;
|
|
|
|
cap >> frame;
|
|
|
|
ASSERT_FALSE(frame.empty());
|
2012-06-05 21:32:04 +08:00
|
|
|
|
2012-12-18 20:59:00 +08:00
|
|
|
IplImage ipl_frame = frame;
|
|
|
|
cv::Ptr<CvBGStatModel> model(cvCreateFGDStatModel(&ipl_frame));
|
2012-06-05 21:32:04 +08:00
|
|
|
|
2012-12-18 20:59:00 +08:00
|
|
|
cv::gpu::GpuMat d_frame(frame);
|
|
|
|
cv::gpu::FGDStatModel d_model(out_cn);
|
|
|
|
d_model.create(d_frame);
|
2012-06-05 21:32:04 +08:00
|
|
|
|
2012-12-18 20:59:00 +08:00
|
|
|
cv::Mat h_background;
|
|
|
|
cv::Mat h_foreground;
|
|
|
|
cv::Mat h_background3;
|
2012-06-05 21:32:04 +08:00
|
|
|
|
2012-12-18 20:59:00 +08:00
|
|
|
cv::Mat backgroundDiff;
|
|
|
|
cv::Mat foregroundDiff;
|
2012-06-05 21:32:04 +08:00
|
|
|
|
2012-12-18 20:59:00 +08:00
|
|
|
for (int i = 0; i < 5; ++i)
|
|
|
|
{
|
|
|
|
cap >> frame;
|
|
|
|
ASSERT_FALSE(frame.empty());
|
2012-06-05 21:32:04 +08:00
|
|
|
|
2012-12-18 20:59:00 +08:00
|
|
|
ipl_frame = frame;
|
|
|
|
int gold_count = cvUpdateBGStatModel(&ipl_frame, model);
|
2012-06-05 21:32:04 +08:00
|
|
|
|
2012-12-18 20:59:00 +08:00
|
|
|
d_frame.upload(frame);
|
2012-06-05 21:32:04 +08:00
|
|
|
|
2012-12-18 20:59:00 +08:00
|
|
|
int count = d_model.update(d_frame);
|
2012-06-05 21:32:04 +08:00
|
|
|
|
2012-12-18 20:59:00 +08:00
|
|
|
ASSERT_EQ(gold_count, count);
|
2012-06-05 21:32:04 +08:00
|
|
|
|
2012-12-18 20:59:00 +08:00
|
|
|
cv::Mat gold_background(model->background);
|
|
|
|
cv::Mat gold_foreground(model->foreground);
|
2012-06-05 21:32:04 +08:00
|
|
|
|
2012-12-18 20:59:00 +08:00
|
|
|
if (out_cn == 3)
|
|
|
|
d_model.background.download(h_background3);
|
|
|
|
else
|
|
|
|
{
|
|
|
|
d_model.background.download(h_background);
|
|
|
|
cv::cvtColor(h_background, h_background3, cv::COLOR_BGRA2BGR);
|
|
|
|
}
|
|
|
|
d_model.foreground.download(h_foreground);
|
2012-06-05 21:32:04 +08:00
|
|
|
|
2012-12-18 20:59:00 +08:00
|
|
|
ASSERT_MAT_NEAR(gold_background, h_background3, 1.0);
|
|
|
|
ASSERT_MAT_NEAR(gold_foreground, h_foreground, 0.0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
catch (...)
|
|
|
|
{
|
|
|
|
cv::gpu::resetDevice();
|
|
|
|
throw;
|
2012-06-05 21:32:04 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
INSTANTIATE_TEST_CASE_P(GPU_Video, FGDStatModel, testing::Combine(
|
|
|
|
ALL_DEVICES,
|
|
|
|
testing::Values(std::string("768x576.avi")),
|
|
|
|
testing::Values(Channels(3), Channels(4))));
|
|
|
|
|
2012-06-25 19:13:50 +08:00
|
|
|
//////////////////////////////////////////////////////
|
|
|
|
// MOG
|
|
|
|
|
|
|
|
IMPLEMENT_PARAM_CLASS(LearningRate, double)
|
|
|
|
|
|
|
|
PARAM_TEST_CASE(MOG, cv::gpu::DeviceInfo, std::string, UseGray, LearningRate, UseRoi)
|
|
|
|
{
|
|
|
|
cv::gpu::DeviceInfo devInfo;
|
|
|
|
std::string inputFile;
|
|
|
|
bool useGray;
|
|
|
|
double learningRate;
|
|
|
|
bool useRoi;
|
|
|
|
|
|
|
|
virtual void SetUp()
|
|
|
|
{
|
|
|
|
devInfo = GET_PARAM(0);
|
|
|
|
cv::gpu::setDevice(devInfo.deviceID());
|
|
|
|
|
|
|
|
inputFile = std::string(cvtest::TS::ptr()->get_data_path()) + "video/" + GET_PARAM(1);
|
|
|
|
|
|
|
|
useGray = GET_PARAM(2);
|
|
|
|
|
|
|
|
learningRate = GET_PARAM(3);
|
|
|
|
|
|
|
|
useRoi = GET_PARAM(4);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
TEST_P(MOG, Update)
|
|
|
|
{
|
2012-12-18 20:59:00 +08:00
|
|
|
try
|
2012-06-25 19:13:50 +08:00
|
|
|
{
|
2012-12-18 20:59:00 +08:00
|
|
|
cv::VideoCapture cap(inputFile);
|
|
|
|
ASSERT_TRUE(cap.isOpened());
|
|
|
|
|
|
|
|
cv::Mat frame;
|
2012-06-25 19:13:50 +08:00
|
|
|
cap >> frame;
|
|
|
|
ASSERT_FALSE(frame.empty());
|
|
|
|
|
2012-12-18 20:59:00 +08:00
|
|
|
cv::gpu::MOG_GPU mog;
|
|
|
|
cv::gpu::GpuMat foreground = createMat(frame.size(), CV_8UC1, useRoi);
|
|
|
|
|
|
|
|
cv::BackgroundSubtractorMOG mog_gold;
|
|
|
|
cv::Mat foreground_gold;
|
|
|
|
|
|
|
|
for (int i = 0; i < 10; ++i)
|
2012-06-25 19:13:50 +08:00
|
|
|
{
|
2012-12-18 20:59:00 +08:00
|
|
|
cap >> frame;
|
|
|
|
ASSERT_FALSE(frame.empty());
|
|
|
|
|
|
|
|
if (useGray)
|
|
|
|
{
|
|
|
|
cv::Mat temp;
|
|
|
|
cv::cvtColor(frame, temp, cv::COLOR_BGR2GRAY);
|
|
|
|
cv::swap(temp, frame);
|
|
|
|
}
|
2012-06-25 19:13:50 +08:00
|
|
|
|
2012-12-18 20:59:00 +08:00
|
|
|
mog(loadMat(frame, useRoi), foreground, (float)learningRate);
|
2012-06-25 19:13:50 +08:00
|
|
|
|
2012-12-18 20:59:00 +08:00
|
|
|
mog_gold(frame, foreground_gold, learningRate);
|
2012-06-25 19:13:50 +08:00
|
|
|
|
2012-12-18 20:59:00 +08:00
|
|
|
ASSERT_MAT_NEAR(foreground_gold, foreground, 0.0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
catch (...)
|
|
|
|
{
|
|
|
|
cv::gpu::resetDevice();
|
|
|
|
throw;
|
2012-06-25 19:13:50 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
INSTANTIATE_TEST_CASE_P(GPU_Video, MOG, testing::Combine(
|
|
|
|
ALL_DEVICES,
|
|
|
|
testing::Values(std::string("768x576.avi")),
|
|
|
|
testing::Values(UseGray(true), UseGray(false)),
|
|
|
|
testing::Values(LearningRate(0.0), LearningRate(0.01)),
|
|
|
|
WHOLE_SUBMAT));
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////
|
|
|
|
// MOG2
|
|
|
|
|
|
|
|
PARAM_TEST_CASE(MOG2, cv::gpu::DeviceInfo, std::string, UseGray, UseRoi)
|
|
|
|
{
|
|
|
|
cv::gpu::DeviceInfo devInfo;
|
|
|
|
std::string inputFile;
|
|
|
|
bool useGray;
|
|
|
|
bool useRoi;
|
|
|
|
|
|
|
|
virtual void SetUp()
|
|
|
|
{
|
|
|
|
devInfo = GET_PARAM(0);
|
|
|
|
cv::gpu::setDevice(devInfo.deviceID());
|
|
|
|
|
|
|
|
inputFile = std::string(cvtest::TS::ptr()->get_data_path()) + "video/" + GET_PARAM(1);
|
|
|
|
|
|
|
|
useGray = GET_PARAM(2);
|
|
|
|
|
|
|
|
useRoi = GET_PARAM(3);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
TEST_P(MOG2, Update)
|
|
|
|
{
|
2012-12-18 20:59:00 +08:00
|
|
|
try
|
2012-06-25 19:13:50 +08:00
|
|
|
{
|
2012-12-18 20:59:00 +08:00
|
|
|
cv::VideoCapture cap(inputFile);
|
|
|
|
ASSERT_TRUE(cap.isOpened());
|
|
|
|
|
|
|
|
cv::Mat frame;
|
2012-06-25 19:13:50 +08:00
|
|
|
cap >> frame;
|
|
|
|
ASSERT_FALSE(frame.empty());
|
|
|
|
|
2012-12-18 20:59:00 +08:00
|
|
|
cv::gpu::MOG2_GPU mog2;
|
|
|
|
cv::gpu::GpuMat foreground = createMat(frame.size(), CV_8UC1, useRoi);
|
|
|
|
|
|
|
|
cv::BackgroundSubtractorMOG2 mog2_gold;
|
|
|
|
cv::Mat foreground_gold;
|
|
|
|
|
|
|
|
for (int i = 0; i < 10; ++i)
|
2012-06-25 19:13:50 +08:00
|
|
|
{
|
2012-12-18 20:59:00 +08:00
|
|
|
cap >> frame;
|
|
|
|
ASSERT_FALSE(frame.empty());
|
|
|
|
|
|
|
|
if (useGray)
|
|
|
|
{
|
|
|
|
cv::Mat temp;
|
|
|
|
cv::cvtColor(frame, temp, cv::COLOR_BGR2GRAY);
|
|
|
|
cv::swap(temp, frame);
|
|
|
|
}
|
2012-06-25 19:13:50 +08:00
|
|
|
|
2012-12-18 20:59:00 +08:00
|
|
|
mog2(loadMat(frame, useRoi), foreground);
|
2012-06-25 19:13:50 +08:00
|
|
|
|
2012-12-18 20:59:00 +08:00
|
|
|
mog2_gold(frame, foreground_gold);
|
2012-06-25 19:13:50 +08:00
|
|
|
|
2012-12-18 20:59:00 +08:00
|
|
|
double norm = cv::norm(foreground_gold, cv::Mat(foreground), cv::NORM_L1);
|
2012-06-25 19:13:50 +08:00
|
|
|
|
2012-12-18 20:59:00 +08:00
|
|
|
norm /= foreground_gold.size().area();
|
2012-06-25 19:13:50 +08:00
|
|
|
|
2012-12-18 20:59:00 +08:00
|
|
|
ASSERT_LE(norm, 0.09);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
catch (...)
|
|
|
|
{
|
|
|
|
cv::gpu::resetDevice();
|
|
|
|
throw;
|
2012-06-25 19:13:50 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_P(MOG2, getBackgroundImage)
|
|
|
|
{
|
2012-08-09 16:30:55 +08:00
|
|
|
if (useGray)
|
|
|
|
return;
|
|
|
|
|
2012-12-18 20:59:00 +08:00
|
|
|
try
|
|
|
|
{
|
|
|
|
cv::VideoCapture cap(inputFile);
|
|
|
|
ASSERT_TRUE(cap.isOpened());
|
2012-06-25 19:13:50 +08:00
|
|
|
|
2012-12-18 20:59:00 +08:00
|
|
|
cv::Mat frame;
|
2012-06-25 19:13:50 +08:00
|
|
|
|
2012-12-18 20:59:00 +08:00
|
|
|
cv::gpu::MOG2_GPU mog2;
|
|
|
|
cv::gpu::GpuMat foreground;
|
2012-06-25 19:13:50 +08:00
|
|
|
|
2012-12-18 20:59:00 +08:00
|
|
|
cv::BackgroundSubtractorMOG2 mog2_gold;
|
|
|
|
cv::Mat foreground_gold;
|
2012-06-25 19:13:50 +08:00
|
|
|
|
2012-12-18 20:59:00 +08:00
|
|
|
for (int i = 0; i < 10; ++i)
|
|
|
|
{
|
|
|
|
cap >> frame;
|
|
|
|
ASSERT_FALSE(frame.empty());
|
2012-06-25 19:13:50 +08:00
|
|
|
|
2012-12-18 20:59:00 +08:00
|
|
|
mog2(loadMat(frame, useRoi), foreground);
|
2012-06-25 19:13:50 +08:00
|
|
|
|
2012-12-18 20:59:00 +08:00
|
|
|
mog2_gold(frame, foreground_gold);
|
|
|
|
}
|
2012-06-25 19:13:50 +08:00
|
|
|
|
2012-12-18 20:59:00 +08:00
|
|
|
cv::gpu::GpuMat background = createMat(frame.size(), frame.type(), useRoi);
|
|
|
|
mog2.getBackgroundImage(background);
|
2012-06-25 19:13:50 +08:00
|
|
|
|
2012-12-18 20:59:00 +08:00
|
|
|
cv::Mat background_gold;
|
|
|
|
mog2_gold.getBackgroundImage(background_gold);
|
2012-06-25 19:13:50 +08:00
|
|
|
|
2012-12-18 20:59:00 +08:00
|
|
|
ASSERT_MAT_NEAR(background_gold, background, 0);
|
|
|
|
}
|
|
|
|
catch (...)
|
|
|
|
{
|
|
|
|
cv::gpu::resetDevice();
|
|
|
|
throw;
|
|
|
|
}
|
2012-06-25 19:13:50 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
INSTANTIATE_TEST_CASE_P(GPU_Video, MOG2, testing::Combine(
|
|
|
|
ALL_DEVICES,
|
|
|
|
testing::Values(std::string("768x576.avi")),
|
|
|
|
testing::Values(UseGray(true), UseGray(false)),
|
|
|
|
WHOLE_SUBMAT));
|
|
|
|
|
2012-08-09 16:30:55 +08:00
|
|
|
//////////////////////////////////////////////////////
|
|
|
|
// VIBE
|
|
|
|
|
|
|
|
PARAM_TEST_CASE(VIBE, cv::gpu::DeviceInfo, cv::Size, MatType, UseRoi)
|
|
|
|
{
|
|
|
|
};
|
|
|
|
|
|
|
|
TEST_P(VIBE, Accuracy)
|
|
|
|
{
|
2012-12-18 20:59:00 +08:00
|
|
|
try
|
|
|
|
{
|
|
|
|
const cv::gpu::DeviceInfo devInfo = GET_PARAM(0);
|
|
|
|
cv::gpu::setDevice(devInfo.deviceID());
|
|
|
|
const cv::Size size = GET_PARAM(1);
|
|
|
|
const int type = GET_PARAM(2);
|
|
|
|
const bool useRoi = GET_PARAM(3);
|
2012-08-09 16:30:55 +08:00
|
|
|
|
2012-12-18 20:59:00 +08:00
|
|
|
const cv::Mat fullfg(size, CV_8UC1, cv::Scalar::all(255));
|
2012-08-09 16:30:55 +08:00
|
|
|
|
2012-12-18 20:59:00 +08:00
|
|
|
cv::Mat frame = randomMat(size, type, 0.0, 100);
|
|
|
|
cv::gpu::GpuMat d_frame = loadMat(frame, useRoi);
|
2012-08-09 16:30:55 +08:00
|
|
|
|
2012-12-18 20:59:00 +08:00
|
|
|
cv::gpu::VIBE_GPU vibe;
|
|
|
|
cv::gpu::GpuMat d_fgmask = createMat(size, CV_8UC1, useRoi);
|
|
|
|
vibe.initialize(d_frame);
|
2012-08-09 16:30:55 +08:00
|
|
|
|
2012-12-18 20:59:00 +08:00
|
|
|
for (int i = 0; i < 20; ++i)
|
|
|
|
vibe(d_frame, d_fgmask);
|
2012-08-09 16:30:55 +08:00
|
|
|
|
2012-12-18 20:59:00 +08:00
|
|
|
frame = randomMat(size, type, 160, 255);
|
|
|
|
d_frame = loadMat(frame, useRoi);
|
|
|
|
vibe(d_frame, d_fgmask);
|
2012-08-09 16:30:55 +08:00
|
|
|
|
2012-12-18 20:59:00 +08:00
|
|
|
// now fgmask should be entirely foreground
|
|
|
|
ASSERT_MAT_NEAR(fullfg, d_fgmask, 0);
|
|
|
|
}
|
|
|
|
catch (...)
|
|
|
|
{
|
|
|
|
cv::gpu::resetDevice();
|
|
|
|
throw;
|
|
|
|
}
|
2012-08-09 16:30:55 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
INSTANTIATE_TEST_CASE_P(GPU_Video, VIBE, testing::Combine(
|
|
|
|
ALL_DEVICES,
|
|
|
|
DIFFERENT_SIZES,
|
|
|
|
testing::Values(MatType(CV_8UC1), MatType(CV_8UC3), MatType(CV_8UC4)),
|
|
|
|
WHOLE_SUBMAT));
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////
|
|
|
|
// GMG
|
|
|
|
|
|
|
|
PARAM_TEST_CASE(GMG, cv::gpu::DeviceInfo, cv::Size, MatDepth, Channels, UseRoi)
|
|
|
|
{
|
|
|
|
};
|
|
|
|
|
|
|
|
TEST_P(GMG, Accuracy)
|
|
|
|
{
|
2012-12-18 20:59:00 +08:00
|
|
|
try
|
|
|
|
{
|
|
|
|
const cv::gpu::DeviceInfo devInfo = GET_PARAM(0);
|
|
|
|
cv::gpu::setDevice(devInfo.deviceID());
|
|
|
|
const cv::Size size = GET_PARAM(1);
|
|
|
|
const int depth = GET_PARAM(2);
|
|
|
|
const int channels = GET_PARAM(3);
|
|
|
|
const bool useRoi = GET_PARAM(4);
|
2012-08-09 16:30:55 +08:00
|
|
|
|
2012-12-18 20:59:00 +08:00
|
|
|
const int type = CV_MAKE_TYPE(depth, channels);
|
2012-08-09 16:30:55 +08:00
|
|
|
|
2012-12-18 20:59:00 +08:00
|
|
|
const cv::Mat zeros(size, CV_8UC1, cv::Scalar::all(0));
|
|
|
|
const cv::Mat fullfg(size, CV_8UC1, cv::Scalar::all(255));
|
2012-08-09 16:30:55 +08:00
|
|
|
|
2012-12-18 20:59:00 +08:00
|
|
|
cv::Mat frame = randomMat(size, type, 0, 100);
|
|
|
|
cv::gpu::GpuMat d_frame = loadMat(frame, useRoi);
|
2012-08-09 16:30:55 +08:00
|
|
|
|
2012-12-18 20:59:00 +08:00
|
|
|
cv::gpu::GMG_GPU gmg;
|
|
|
|
gmg.numInitializationFrames = 5;
|
|
|
|
gmg.smoothingRadius = 0;
|
|
|
|
gmg.initialize(d_frame.size(), 0, 255);
|
2012-08-09 16:30:55 +08:00
|
|
|
|
2012-12-18 20:59:00 +08:00
|
|
|
cv::gpu::GpuMat d_fgmask = createMat(size, CV_8UC1, useRoi);
|
2012-08-09 16:30:55 +08:00
|
|
|
|
2012-12-18 20:59:00 +08:00
|
|
|
for (int i = 0; i < gmg.numInitializationFrames; ++i)
|
|
|
|
{
|
|
|
|
gmg(d_frame, d_fgmask);
|
2012-08-09 16:30:55 +08:00
|
|
|
|
2012-12-18 20:59:00 +08:00
|
|
|
// fgmask should be entirely background during training
|
|
|
|
ASSERT_MAT_NEAR(zeros, d_fgmask, 0);
|
|
|
|
}
|
2012-08-09 16:30:55 +08:00
|
|
|
|
2012-12-18 20:59:00 +08:00
|
|
|
frame = randomMat(size, type, 160, 255);
|
|
|
|
d_frame = loadMat(frame, useRoi);
|
|
|
|
gmg(d_frame, d_fgmask);
|
2012-08-09 16:30:55 +08:00
|
|
|
|
2012-12-18 20:59:00 +08:00
|
|
|
// now fgmask should be entirely foreground
|
|
|
|
ASSERT_MAT_NEAR(fullfg, d_fgmask, 0);
|
|
|
|
}
|
|
|
|
catch (...)
|
|
|
|
{
|
|
|
|
cv::gpu::resetDevice();
|
|
|
|
throw;
|
|
|
|
}
|
2012-08-09 16:30:55 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
INSTANTIATE_TEST_CASE_P(GPU_Video, GMG, testing::Combine(
|
|
|
|
ALL_DEVICES,
|
|
|
|
DIFFERENT_SIZES,
|
|
|
|
testing::Values(MatType(CV_8U), MatType(CV_16U), MatType(CV_32F)),
|
|
|
|
testing::Values(Channels(1), Channels(3), Channels(4)),
|
|
|
|
WHOLE_SUBMAT));
|
|
|
|
|
2012-12-13 17:48:24 +08:00
|
|
|
#ifdef WIN32
|
|
|
|
|
2012-06-05 21:32:04 +08:00
|
|
|
//////////////////////////////////////////////////////
|
2012-05-02 21:07:30 +08:00
|
|
|
// VideoWriter
|
|
|
|
|
|
|
|
PARAM_TEST_CASE(VideoWriter, cv::gpu::DeviceInfo, std::string)
|
|
|
|
{
|
|
|
|
cv::gpu::DeviceInfo devInfo;
|
|
|
|
std::string inputFile;
|
|
|
|
|
|
|
|
std::string outputFile;
|
|
|
|
|
|
|
|
virtual void SetUp()
|
|
|
|
{
|
|
|
|
devInfo = GET_PARAM(0);
|
|
|
|
inputFile = GET_PARAM(1);
|
|
|
|
|
|
|
|
cv::gpu::setDevice(devInfo.deviceID());
|
|
|
|
|
|
|
|
inputFile = std::string(cvtest::TS::ptr()->get_data_path()) + "video/" + inputFile;
|
2012-06-25 19:24:06 +08:00
|
|
|
outputFile = cv::tempfile(".avi");
|
2012-05-02 21:07:30 +08:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
TEST_P(VideoWriter, Regression)
|
|
|
|
{
|
2012-12-18 20:59:00 +08:00
|
|
|
try
|
|
|
|
{
|
|
|
|
const double FPS = 25.0;
|
2012-05-02 21:07:30 +08:00
|
|
|
|
2012-12-18 20:59:00 +08:00
|
|
|
cv::VideoCapture reader(inputFile);
|
|
|
|
ASSERT_TRUE( reader.isOpened() );
|
2012-05-02 21:07:30 +08:00
|
|
|
|
2012-12-18 20:59:00 +08:00
|
|
|
cv::gpu::VideoWriter_GPU d_writer;
|
2012-05-02 21:07:30 +08:00
|
|
|
|
2012-12-18 20:59:00 +08:00
|
|
|
cv::Mat frame;
|
|
|
|
cv::gpu::GpuMat d_frame;
|
2012-05-02 21:07:30 +08:00
|
|
|
|
2012-12-18 20:59:00 +08:00
|
|
|
for (int i = 0; i < 10; ++i)
|
|
|
|
{
|
|
|
|
reader >> frame;
|
|
|
|
ASSERT_FALSE(frame.empty());
|
2012-05-02 21:07:30 +08:00
|
|
|
|
2012-12-18 20:59:00 +08:00
|
|
|
d_frame.upload(frame);
|
2012-05-02 21:07:30 +08:00
|
|
|
|
2012-12-18 20:59:00 +08:00
|
|
|
if (!d_writer.isOpened())
|
|
|
|
d_writer.open(outputFile, frame.size(), FPS);
|
2012-05-02 21:07:30 +08:00
|
|
|
|
2012-12-18 20:59:00 +08:00
|
|
|
d_writer.write(d_frame);
|
|
|
|
}
|
2012-05-02 21:07:30 +08:00
|
|
|
|
2012-12-18 20:59:00 +08:00
|
|
|
reader.release();
|
|
|
|
d_writer.close();
|
2012-05-02 21:07:30 +08:00
|
|
|
|
2012-12-18 20:59:00 +08:00
|
|
|
reader.open(outputFile);
|
|
|
|
ASSERT_TRUE( reader.isOpened() );
|
2012-05-02 21:07:30 +08:00
|
|
|
|
2012-12-18 20:59:00 +08:00
|
|
|
for (int i = 0; i < 5; ++i)
|
|
|
|
{
|
|
|
|
reader >> frame;
|
|
|
|
ASSERT_FALSE( frame.empty() );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
catch (...)
|
2012-05-02 21:07:30 +08:00
|
|
|
{
|
2012-12-18 20:59:00 +08:00
|
|
|
cv::gpu::resetDevice();
|
|
|
|
throw;
|
2012-05-02 21:07:30 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
INSTANTIATE_TEST_CASE_P(GPU_Video, VideoWriter, testing::Combine(
|
|
|
|
ALL_DEVICES,
|
2012-06-05 21:32:04 +08:00
|
|
|
testing::Values(std::string("768x576.avi"), std::string("1920x1080.avi"))));
|
2012-05-02 21:07:30 +08:00
|
|
|
|
2012-06-05 21:32:04 +08:00
|
|
|
//////////////////////////////////////////////////////
|
2012-05-02 21:07:30 +08:00
|
|
|
// VideoReader
|
|
|
|
|
|
|
|
PARAM_TEST_CASE(VideoReader, cv::gpu::DeviceInfo, std::string)
|
|
|
|
{
|
|
|
|
cv::gpu::DeviceInfo devInfo;
|
|
|
|
std::string inputFile;
|
|
|
|
|
|
|
|
virtual void SetUp()
|
|
|
|
{
|
|
|
|
devInfo = GET_PARAM(0);
|
|
|
|
inputFile = GET_PARAM(1);
|
|
|
|
|
|
|
|
cv::gpu::setDevice(devInfo.deviceID());
|
|
|
|
|
|
|
|
inputFile = std::string(cvtest::TS::ptr()->get_data_path()) + "video/" + inputFile;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
TEST_P(VideoReader, Regression)
|
|
|
|
{
|
2012-12-18 20:59:00 +08:00
|
|
|
try
|
|
|
|
{
|
|
|
|
cv::gpu::VideoReader_GPU reader(inputFile);
|
|
|
|
ASSERT_TRUE( reader.isOpened() );
|
2012-05-02 21:07:30 +08:00
|
|
|
|
2012-12-18 20:59:00 +08:00
|
|
|
cv::gpu::GpuMat frame;
|
2012-05-02 21:07:30 +08:00
|
|
|
|
2012-12-18 20:59:00 +08:00
|
|
|
for (int i = 0; i < 10; ++i)
|
|
|
|
{
|
|
|
|
ASSERT_TRUE( reader.read(frame) );
|
|
|
|
ASSERT_FALSE( frame.empty() );
|
|
|
|
}
|
|
|
|
|
|
|
|
reader.close();
|
|
|
|
ASSERT_FALSE( reader.isOpened() );
|
|
|
|
}
|
|
|
|
catch (...)
|
2012-05-02 21:07:30 +08:00
|
|
|
{
|
2012-12-18 20:59:00 +08:00
|
|
|
cv::gpu::resetDevice();
|
|
|
|
throw;
|
2012-05-02 21:07:30 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
INSTANTIATE_TEST_CASE_P(GPU_Video, VideoReader, testing::Combine(
|
|
|
|
ALL_DEVICES,
|
2012-06-05 21:32:04 +08:00
|
|
|
testing::Values(std::string("768x576.avi"), std::string("1920x1080.avi"))));
|
2012-08-20 14:15:36 +08:00
|
|
|
|
2012-12-13 17:48:24 +08:00
|
|
|
#endif // WIN32
|
|
|
|
|
2012-08-20 14:15:36 +08:00
|
|
|
#endif // HAVE_CUDA
|