test_video.cpp 4.55 KB
Newer Older
wester committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44
/*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.
//
//
//                           License Agreement
//                For Open Source Computer Vision Library
//
// Copyright (C) 2000-2008, Intel Corporation, all rights reserved.
// Copyright (C) 2009, Willow Garage Inc., 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 the copyright holders 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*/

#include "test_precomp.hpp"

wester committed
45
#if defined(HAVE_CUDA) && defined(HAVE_NVCUVID)
wester committed
46 47 48 49

//////////////////////////////////////////////////////
// VideoReader

wester committed
50
PARAM_TEST_CASE(VideoReader, cv::gpu::DeviceInfo, std::string)
wester committed
51
{
wester committed
52 53 54 55 56 57 58 59 60
    cv::gpu::DeviceInfo devInfo;
    std::string inputFile;

    virtual void SetUp()
    {
        devInfo = GET_PARAM(0);
        inputFile = GET_PARAM(1);

        cv::gpu::setDevice(devInfo.deviceID());
wester committed
61

wester committed
62 63 64
        inputFile = std::string(cvtest::TS::ptr()->get_data_path()) + "video/" + inputFile;
    }
};
wester committed
65

wester committed
66 67 68 69
GPU_TEST_P(VideoReader, Regression)
{
    cv::gpu::VideoReader_GPU reader(inputFile);
    ASSERT_TRUE(reader.isOpened());
wester committed
70

wester committed
71
    cv::gpu::GpuMat frame;
wester committed
72 73 74

    for (int i = 0; i < 10; ++i)
    {
wester committed
75
        ASSERT_TRUE(reader.read(frame));
wester committed
76 77
        ASSERT_FALSE(frame.empty());
    }
wester committed
78 79 80

    reader.close();
    ASSERT_FALSE(reader.isOpened());
wester committed
81 82
}

wester committed
83 84 85 86
INSTANTIATE_TEST_CASE_P(GPU_Video, VideoReader, testing::Combine(
    ALL_DEVICES,
    testing::Values(std::string("768x576.avi"), std::string("1920x1080.avi"))));

wester committed
87 88 89
//////////////////////////////////////////////////////
// VideoWriter

a  
Kai Westerkamp committed
90
#ifdef WIN32
wester committed
91

wester committed
92
PARAM_TEST_CASE(VideoWriter, cv::gpu::DeviceInfo, std::string)
wester committed
93
{
wester committed
94 95 96 97 98 99 100 101 102
    cv::gpu::DeviceInfo devInfo;
    std::string inputFile;

    virtual void SetUp()
    {
        devInfo = GET_PARAM(0);
        inputFile = GET_PARAM(1);

        cv::gpu::setDevice(devInfo.deviceID());
wester committed
103

wester committed
104 105 106
        inputFile = std::string(cvtest::TS::ptr()->get_data_path()) + std::string("video/") + inputFile;
    }
};
wester committed
107

wester committed
108 109
GPU_TEST_P(VideoWriter, Regression)
{
wester committed
110 111 112 113 114 115
    std::string outputFile = cv::tempfile(".avi");
    const double FPS = 25.0;

    cv::VideoCapture reader(inputFile);
    ASSERT_TRUE(reader.isOpened());

wester committed
116
    cv::gpu::VideoWriter_GPU d_writer;
wester committed
117 118

    cv::Mat frame;
wester committed
119
    cv::gpu::GpuMat d_frame;
wester committed
120 121 122 123 124 125 126 127

    for (int i = 0; i < 10; ++i)
    {
        reader >> frame;
        ASSERT_FALSE(frame.empty());

        d_frame.upload(frame);

wester committed
128 129
        if (!d_writer.isOpened())
            d_writer.open(outputFile, frame.size(), FPS);
wester committed
130

wester committed
131
        d_writer.write(d_frame);
wester committed
132 133 134
    }

    reader.release();
wester committed
135
    d_writer.close();
wester committed
136 137 138 139 140 141 142 143 144 145 146

    reader.open(outputFile);
    ASSERT_TRUE(reader.isOpened());

    for (int i = 0; i < 5; ++i)
    {
        reader >> frame;
        ASSERT_FALSE(frame.empty());
    }
}

wester committed
147
INSTANTIATE_TEST_CASE_P(GPU_Video, VideoWriter, testing::Combine(
wester committed
148 149 150
    ALL_DEVICES,
    testing::Values(std::string("768x576.avi"), std::string("1920x1080.avi"))));

wester committed
151 152 153
#endif // WIN32

#endif //  defined(HAVE_CUDA) && defined(HAVE_NVCUVID)