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 #include "opencv2/videoio.hpp"
     45 #include "opencv2/ts.hpp"
     46 #include <stdio.h>
     47 
     48 #if BUILD_WITH_VIDEO_INPUT_SUPPORT
     49 
     50 using namespace cv;
     51 using namespace std;
     52 using namespace cvtest;
     53 
     54 #ifdef HAVE_GSTREAMER
     55 const string ext[] = {"avi"};
     56 #else
     57 const string ext[] = {"avi", "mov", "mp4"};
     58 #endif
     59 
     60 TEST(Videoio_Video, prop_resolution)
     61 {
     62     const size_t n = sizeof(ext)/sizeof(ext[0]);
     63     const string src_dir = TS::ptr()->get_data_path();
     64 
     65     TS::ptr()->printf(cvtest::TS::LOG, "\n\nSource files directory: %s\n", (src_dir+"video/").c_str());
     66 
     67     for (size_t i = 0; i < n; ++i)
     68     {
     69         string file_path = src_dir+"video/big_buck_bunny."+ext[i];
     70         VideoCapture cap(file_path);
     71         if (!cap.isOpened())
     72         {
     73             TS::ptr()->printf(cvtest::TS::LOG, "\nFile information (video %d): \n\nName: big_buck_bunny.%s\nFAILED\n\n", i+1, ext[i].c_str());
     74             TS::ptr()->printf(cvtest::TS::LOG, "Error: cannot read source video file.\n");
     75             TS::ptr()->set_failed_test_info(cvtest::TS::FAIL_INVALID_TEST_DATA);
     76             return;
     77         }
     78 
     79         ASSERT_EQ(672, cap.get(CAP_PROP_FRAME_WIDTH));
     80         ASSERT_EQ(384, cap.get(CAP_PROP_FRAME_HEIGHT));
     81     }
     82 }
     83 
     84 TEST(Videoio_Video, actual_resolution)
     85 {
     86     const size_t n = sizeof(ext)/sizeof(ext[0]);
     87     const string src_dir = TS::ptr()->get_data_path();
     88 
     89     TS::ptr()->printf(cvtest::TS::LOG, "\n\nSource files directory: %s\n", (src_dir+"video/").c_str());
     90 
     91     for (size_t i = 0; i < n; ++i)
     92     {
     93         string file_path = src_dir+"video/big_buck_bunny."+ext[i];
     94         VideoCapture cap(file_path);
     95         if (!cap.isOpened())
     96         {
     97             TS::ptr()->printf(cvtest::TS::LOG, "\nFile information (video %d): \n\nName: big_buck_bunny.%s\nFAILED\n\n", i+1, ext[i].c_str());
     98             TS::ptr()->printf(cvtest::TS::LOG, "Error: cannot read source video file.\n");
     99             TS::ptr()->set_failed_test_info(cvtest::TS::FAIL_INVALID_TEST_DATA);
    100             return;
    101         }
    102 
    103         Mat frame;
    104         cap >> frame;
    105 
    106         ASSERT_EQ(672, frame.cols);
    107         ASSERT_EQ(384, frame.rows);
    108     }
    109 }
    110 
    111 TEST(Videoio_Video, DISABLED_prop_fps)
    112 {
    113     const size_t n = sizeof(ext)/sizeof(ext[0]);
    114     const string src_dir = TS::ptr()->get_data_path();
    115 
    116     TS::ptr()->printf(cvtest::TS::LOG, "\n\nSource files directory: %s\n", (src_dir+"video/").c_str());
    117 
    118     for (size_t i = 0; i < n; ++i)
    119     {
    120         string file_path = src_dir+"video/big_buck_bunny."+ext[i];
    121         VideoCapture cap(file_path);
    122         if (!cap.isOpened())
    123         {
    124             TS::ptr()->printf(cvtest::TS::LOG, "\nFile information (video %d): \n\nName: big_buck_bunny.%s\nFAILED\n\n", i+1, ext[i].c_str());
    125             TS::ptr()->printf(cvtest::TS::LOG, "Error: cannot read source video file.\n");
    126             TS::ptr()->set_failed_test_info(cvtest::TS::FAIL_INVALID_TEST_DATA);
    127             return;
    128         }
    129 
    130         ASSERT_EQ(24, cap.get(CAP_PROP_FPS));
    131     }
    132 }
    133 
    134 TEST(Videoio_Video, prop_framecount)
    135 {
    136     const size_t n = sizeof(ext)/sizeof(ext[0]);
    137     const string src_dir = TS::ptr()->get_data_path();
    138 
    139     TS::ptr()->printf(cvtest::TS::LOG, "\n\nSource files directory: %s\n", (src_dir+"video/").c_str());
    140 
    141     for (size_t i = 0; i < n; ++i)
    142     {
    143         string file_path = src_dir+"video/big_buck_bunny."+ext[i];
    144         VideoCapture cap(file_path);
    145         if (!cap.isOpened())
    146         {
    147             TS::ptr()->printf(cvtest::TS::LOG, "\nFile information (video %d): \n\nName: big_buck_bunny.%s\nFAILED\n\n", i+1, ext[i].c_str());
    148             TS::ptr()->printf(cvtest::TS::LOG, "Error: cannot read source video file.\n");
    149             TS::ptr()->set_failed_test_info(cvtest::TS::FAIL_INVALID_TEST_DATA);
    150             return;
    151         }
    152 
    153         ASSERT_EQ(125, cap.get(CAP_PROP_FRAME_COUNT));
    154     }
    155 }
    156 
    157 #endif
    158