Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Tetragramm
GitHub Repository: Tetragramm/opencv
Path: blob/master/modules/videoio/test/test_precomp.hpp
16354 views
1
// This file is part of OpenCV project.
2
// It is subject to the license terms in the LICENSE file found in the top-level directory
3
// of this distribution and at http://opencv.org/license.html.
4
#ifndef __OPENCV_TEST_PRECOMP_HPP__
5
#define __OPENCV_TEST_PRECOMP_HPP__
6
7
#include "opencv2/ts.hpp"
8
#include "opencv2/videoio.hpp"
9
#include "opencv2/videoio/registry.hpp"
10
#include "opencv2/imgproc/imgproc_c.h"
11
12
#include "opencv2/core/private.hpp"
13
14
namespace cv {
15
16
inline std::ostream &operator<<(std::ostream &out, const VideoCaptureAPIs& api)
17
{
18
out << cv::videoio_registry::getBackendName(api); return out;
19
}
20
21
static inline void PrintTo(const cv::VideoCaptureAPIs& api, std::ostream* os)
22
{
23
*os << cv::videoio_registry::getBackendName(api);
24
}
25
26
} // namespace
27
28
29
inline std::string fourccToString(int fourcc)
30
{
31
return cv::format("%c%c%c%c", fourcc & 255, (fourcc >> 8) & 255, (fourcc >> 16) & 255, (fourcc >> 24) & 255);
32
}
33
34
inline int fourccFromString(const std::string &fourcc)
35
{
36
if (fourcc.size() != 4) return 0;
37
return cv::VideoWriter::fourcc(fourcc[0], fourcc[1], fourcc[2], fourcc[3]);
38
}
39
40
inline void generateFrame(int i, int FRAME_COUNT, cv::Mat & frame)
41
{
42
using namespace cv;
43
using namespace std;
44
int offset = (((i * 5) % FRAME_COUNT) - FRAME_COUNT / 2) * (frame.cols / 2) / FRAME_COUNT;
45
frame(cv::Rect(0, 0, frame.cols / 2 + offset, frame.rows)) = Scalar(255, 255, 255);
46
frame(cv::Rect(frame.cols / 2 + offset, 0, frame.cols - frame.cols / 2 - offset, frame.rows)) = Scalar(0, 0, 0);
47
ostringstream buf; buf << "Frame " << setw(2) << setfill('0') << i + 1;
48
int baseLine = 0;
49
Size box = getTextSize(buf.str(), FONT_HERSHEY_COMPLEX, 2, 5, &baseLine);
50
putText(frame, buf.str(), Point((frame.cols - box.width) / 2, (frame.rows - box.height) / 2 + baseLine),
51
FONT_HERSHEY_COMPLEX, 2, Scalar(0, 0, 255), 5, LINE_AA);
52
Point p(i * frame.cols / (FRAME_COUNT - 1), i * frame.rows / (FRAME_COUNT - 1));
53
circle(frame, p, 50, Scalar(200, 25, 55), 8, LINE_AA);
54
#if 0
55
imshow("frame", frame);
56
waitKey();
57
#endif
58
}
59
60
class BunnyParameters
61
{
62
public:
63
inline static int getWidth() { return 672; };
64
inline static int getHeight() { return 384; };
65
inline static int getFps() { return 24; };
66
inline static double getTime() { return 5.21; };
67
inline static int getCount() { return cvRound(getFps() * getTime()); };
68
inline static std::string getFilename(const std::string &ext)
69
{
70
return cvtest::TS::ptr()->get_data_path() + "video/big_buck_bunny" + ext;
71
}
72
};
73
74
75
static inline bool isBackendAvailable(cv::VideoCaptureAPIs api, const std::vector<cv::VideoCaptureAPIs>& api_list)
76
{
77
for (size_t i = 0; i < api_list.size(); i++)
78
{
79
if (api_list[i] == api)
80
return true;
81
}
82
return false;
83
}
84
85
#endif
86
87