Home | History | Annotate | Download | only in test
      1 /*M///////////////////////////////////////////////////////////////////////////////////////
      2 //
      3 //  IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
      4 //
      5 //  By downloading, copying, installing or using the software you agree to this license.
      6 //  If you do not agree to this license, do not download, install,
      7 //  copy or use the software.
      8 //
      9 //
     10 //                           License Agreement
     11 //                For Open Source Computer Vision Library
     12 //
     13 // Copyright (C) 2000-2008, Intel Corporation, all rights reserved.
     14 // Copyright (C) 2009, Willow Garage Inc., all rights reserved.
     15 // Third party copyrights are property of their respective owners.
     16 //
     17 // Redistribution and use in source and binary forms, with or without modification,
     18 // are permitted provided that the following conditions are met:
     19 //
     20 //   * Redistribution's of source code must retain the above copyright notice,
     21 //     this list of conditions and the following disclaimer.
     22 //
     23 //   * Redistribution's in binary form must reproduce the above copyright notice,
     24 //     this list of conditions and the following disclaimer in the documentation
     25 //     and/or other materials provided with the distribution.
     26 //
     27 //   * The name of the copyright holders may not be used to endorse or promote products
     28 //     derived from this software without specific prior written permission.
     29 //
     30 // This software is provided by the copyright holders and contributors "as is" and
     31 // any express or implied warranties, including, but not limited to, the implied
     32 // warranties of merchantability and fitness for a particular purpose are disclaimed.
     33 // In no event shall the Intel Corporation or contributors be liable for any direct,
     34 // indirect, incidental, special, exemplary, or consequential damages
     35 // (including, but not limited to, procurement of substitute goods or services;
     36 // loss of use, data, or profits; or business interruption) however caused
     37 // and on any theory of liability, whether in contract, strict liability,
     38 // or tort (including negligence or otherwise) arising in any way out of
     39 // the use of this software, even if advised of the possibility of such damage.
     40 //
     41 //M*/
     42 
     43 #include "test_precomp.hpp"
     44 
     45 #ifdef HAVE_NVCUVID
     46 
     47 PARAM_TEST_CASE(Video, cv::cuda::DeviceInfo, std::string)
     48 {
     49 };
     50 
     51 //////////////////////////////////////////////////////
     52 // VideoReader
     53 
     54 CUDA_TEST_P(Video, Reader)
     55 {
     56     cv::cuda::setDevice(GET_PARAM(0).deviceID());
     57 
     58     const std::string inputFile = std::string(cvtest::TS::ptr()->get_data_path()) + "video/" + GET_PARAM(1);
     59 
     60     cv::Ptr<cv::cudacodec::VideoReader> reader = cv::cudacodec::createVideoReader(inputFile);
     61 
     62     cv::cuda::GpuMat frame;
     63 
     64     for (int i = 0; i < 10; ++i)
     65     {
     66         ASSERT_TRUE(reader->nextFrame(frame));
     67         ASSERT_FALSE(frame.empty());
     68     }
     69 }
     70 
     71 //////////////////////////////////////////////////////
     72 // VideoWriter
     73 
     74 #ifdef WIN32
     75 
     76 CUDA_TEST_P(Video, Writer)
     77 {
     78     cv::cuda::setDevice(GET_PARAM(0).deviceID());
     79 
     80     const std::string inputFile = std::string(cvtest::TS::ptr()->get_data_path()) + "video/" + GET_PARAM(1);
     81 
     82     std::string outputFile = cv::tempfile(".avi");
     83     const double FPS = 25.0;
     84 
     85     cv::VideoCapture reader(inputFile);
     86     ASSERT_TRUE(reader.isOpened());
     87 
     88     cv::Ptr<cv::cudacodec::VideoWriter> d_writer;
     89 
     90     cv::Mat frame;
     91     cv::cuda::GpuMat d_frame;
     92 
     93     for (int i = 0; i < 10; ++i)
     94     {
     95         reader >> frame;
     96         ASSERT_FALSE(frame.empty());
     97 
     98         d_frame.upload(frame);
     99 
    100         if (d_writer.empty())
    101             d_writer = cv::cudacodec::createVideoWriter(outputFile, frame.size(), FPS);
    102 
    103         d_writer->write(d_frame);
    104     }
    105 
    106     reader.release();
    107     d_writer.release();
    108 
    109     reader.open(outputFile);
    110     ASSERT_TRUE(reader.isOpened());
    111 
    112     for (int i = 0; i < 5; ++i)
    113     {
    114         reader >> frame;
    115         ASSERT_FALSE(frame.empty());
    116     }
    117 }
    118 
    119 #endif // WIN32
    120 
    121 INSTANTIATE_TEST_CASE_P(CUDA_Codec, Video, testing::Combine(
    122     ALL_DEVICES,
    123     testing::Values(std::string("768x576.avi"), std::string("1920x1080.avi"))));
    124 
    125 #endif // HAVE_NVCUVID
    126