blob: a02fa7fd4e04b3a0836547e9ce3c01ba5ff1c244 [file] [log] [blame]
Éanna Ó Catháin919c14e2020-09-14 17:36:49 +01001//
2// Copyright © 2020 Arm Ltd and Contributors. All rights reserved.
3// SPDX-License-Identifier: MIT
4//
5
6#define CATCH_CONFIG_MAIN
7
8#include <catch.hpp>
9#include <opencv2/opencv.hpp>
10
11#include "IFrameReader.hpp"
12#include "CvVideoFrameReader.hpp"
13
14SCENARIO("Read frames from video file using CV frame reader", "[framereader]") {
15
16 GIVEN("a valid video file") {
17
18 std::string testResources = TEST_RESOURCE_DIR;
19 REQUIRE(testResources != "");
20 std::string file = testResources + "/" + "Megamind.avi";
21 WHEN("Frame reader is initialised") {
22
Éanna Ó Catháinc6ab02a2021-04-07 14:35:25 +010023 common::CvVideoFrameReader reader;
Éanna Ó Catháin919c14e2020-09-14 17:36:49 +010024 THEN("no exception is thrown") {
25 reader.Init(file);
26
27 AND_WHEN("when source parameters are read") {
28
29 auto fps = reader.GetSourceFps();
30 auto height = reader.GetSourceHeight();
31 auto width = reader.GetSourceWidth();
32 auto encoding = reader.GetSourceEncoding();
33 auto framesCount = reader.GetFrameCount();
34
35 THEN("they are aligned with video file") {
36
37 REQUIRE(height == 528);
38 REQUIRE(width == 720);
39 REQUIRE(encoding == "XVID");
40 REQUIRE(fps == 23.976);
41 REQUIRE(framesCount == 270);
42 }
43
44 }
45
46 AND_WHEN("frame is read") {
47 auto framePtr = reader.ReadFrame();
48
49 THEN("it is not a NULL pointer") {
50 REQUIRE(framePtr != nullptr);
51 }
52
53 AND_THEN("it is not empty") {
54 REQUIRE(!framePtr->empty());
55 REQUIRE(!reader.IsExhausted(framePtr));
56 }
57 }
58
59 AND_WHEN("all frames were read from the file") {
60
61 for (int i = 0; i < 270; i++) {
62 auto framePtr = reader.ReadFrame();
63 }
64
65 THEN("last + 1 frame is empty") {
66 auto framePtr = reader.ReadFrame();
67
68 REQUIRE(framePtr->empty());
69 REQUIRE(reader.IsExhausted(framePtr));
70 }
71
72 }
73
74 AND_WHEN("frames are read from the file, pointers point to the different objects") {
75
76 auto framePtr = reader.ReadFrame();
77
78 cv::Mat *frame = framePtr.get();
79
80 for (int i = 0; i < 30; i++) {
81 REQUIRE(frame != reader.ReadFrame().get());
82 }
83
84 }
85 }
86 }
87 }
88
89 GIVEN("an invalid video file") {
90
91 std::string file = "nosuchfile.avi";
92
93 WHEN("Frame reader is initialised") {
94
Éanna Ó Catháinc6ab02a2021-04-07 14:35:25 +010095 common::CvVideoFrameReader reader;
Éanna Ó Catháin919c14e2020-09-14 17:36:49 +010096
97 THEN("exception is thrown") {
98 REQUIRE_THROWS(reader.Init(file));
99 }
100 }
101
102 }
103}