2017-11-05 21:48:40 +08:00
|
|
|
// This file is part of OpenCV project.
|
|
|
|
// It is subject to the license terms in the LICENSE file found in the top-level directory
|
|
|
|
// of this distribution and at http://opencv.org/license.html.
|
2014-07-10 22:27:32 +08:00
|
|
|
#ifndef __OPENCV_TEST_PRECOMP_HPP__
|
|
|
|
#define __OPENCV_TEST_PRECOMP_HPP__
|
|
|
|
|
2020-09-23 22:36:43 +08:00
|
|
|
#include <sstream>
|
2023-07-07 22:25:49 +08:00
|
|
|
#include <algorithm>
|
2020-09-23 22:36:43 +08:00
|
|
|
|
2014-07-10 22:27:32 +08:00
|
|
|
#include "opencv2/ts.hpp"
|
2023-06-22 20:48:54 +08:00
|
|
|
#include "opencv2/ts/ocl_test.hpp"
|
2014-07-10 22:27:32 +08:00
|
|
|
#include "opencv2/videoio.hpp"
|
2018-07-19 21:14:50 +08:00
|
|
|
#include "opencv2/videoio/registry.hpp"
|
2014-07-10 22:27:32 +08:00
|
|
|
#include "opencv2/core/private.hpp"
|
|
|
|
|
2018-07-19 21:14:50 +08:00
|
|
|
namespace cv {
|
|
|
|
|
2021-03-01 23:51:04 +08:00
|
|
|
static inline
|
|
|
|
std::ostream& operator<<(std::ostream& out, const VideoCaptureAPIs& api)
|
2018-07-19 21:14:50 +08:00
|
|
|
{
|
|
|
|
out << cv::videoio_registry::getBackendName(api); return out;
|
|
|
|
}
|
|
|
|
|
2021-03-01 23:51:04 +08:00
|
|
|
static inline
|
|
|
|
std::ostream& operator<<(std::ostream& out, const VideoAccelerationType& va_type)
|
|
|
|
{
|
|
|
|
struct {
|
|
|
|
VideoAccelerationType va_type;
|
|
|
|
const char* str;
|
|
|
|
} va_types[] = {
|
|
|
|
{VIDEO_ACCELERATION_ANY, "ANY"},
|
|
|
|
{VIDEO_ACCELERATION_NONE, "NONE"},
|
|
|
|
{VIDEO_ACCELERATION_D3D11, "D3D11"},
|
|
|
|
{VIDEO_ACCELERATION_VAAPI, "VAAPI"},
|
|
|
|
{VIDEO_ACCELERATION_MFX, "MFX"},
|
|
|
|
};
|
|
|
|
for (const auto& va : va_types) {
|
|
|
|
if (va_type == va.va_type) {
|
|
|
|
out << va.str;
|
|
|
|
return out;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
out << cv::format("UNKNOWN(0x%ux)", static_cast<unsigned int>(va_type));
|
|
|
|
return out;
|
|
|
|
}
|
|
|
|
|
2018-07-19 21:14:50 +08:00
|
|
|
static inline void PrintTo(const cv::VideoCaptureAPIs& api, std::ostream* os)
|
|
|
|
{
|
|
|
|
*os << cv::videoio_registry::getBackendName(api);
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace
|
|
|
|
|
|
|
|
|
2017-06-07 01:22:30 +08:00
|
|
|
inline std::string fourccToString(int fourcc)
|
2014-07-10 22:27:32 +08:00
|
|
|
{
|
2023-08-04 15:50:03 +08:00
|
|
|
return cv::format("%c%c%c%c",
|
|
|
|
(char)(fourcc & 255),
|
|
|
|
(char)((fourcc >> 8) & 255),
|
|
|
|
(char)((fourcc >> 16) & 255),
|
|
|
|
(char)((fourcc >> 24) & 255));
|
2017-06-07 01:22:30 +08:00
|
|
|
}
|
2014-07-10 22:27:32 +08:00
|
|
|
|
2023-07-07 22:25:49 +08:00
|
|
|
inline std::string fourccToStringSafe(int fourcc)
|
|
|
|
{
|
|
|
|
std::string res = fourccToString(fourcc);
|
2023-07-14 16:31:55 +08:00
|
|
|
// TODO: return hex values for invalid characters
|
2023-08-01 19:09:22 +08:00
|
|
|
std::transform(res.begin(), res.end(), res.begin(), [](char c) -> char { return (c >= '0' && c <= 'z') ? c : (c == ' ' ? '_' : 'x'); });
|
2023-07-07 22:25:49 +08:00
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2017-06-07 01:22:30 +08:00
|
|
|
inline int fourccFromString(const std::string &fourcc)
|
2014-07-10 22:27:32 +08:00
|
|
|
{
|
2017-06-07 01:22:30 +08:00
|
|
|
if (fourcc.size() != 4) return 0;
|
|
|
|
return cv::VideoWriter::fourcc(fourcc[0], fourcc[1], fourcc[2], fourcc[3]);
|
|
|
|
}
|
2014-07-10 22:27:32 +08:00
|
|
|
|
2023-08-04 15:50:03 +08:00
|
|
|
inline void generateFrame(int i, int frame_count, cv::Mat & frame)
|
2017-06-07 01:22:30 +08:00
|
|
|
{
|
|
|
|
using namespace cv;
|
|
|
|
using namespace std;
|
2023-08-04 15:50:03 +08:00
|
|
|
int offset = (((i * 5) % frame_count) - frame_count / 2) * (frame.cols / 2) / frame_count;
|
2017-07-05 18:45:08 +08:00
|
|
|
frame(cv::Rect(0, 0, frame.cols / 2 + offset, frame.rows)) = Scalar(255, 255, 255);
|
|
|
|
frame(cv::Rect(frame.cols / 2 + offset, 0, frame.cols - frame.cols / 2 - offset, frame.rows)) = Scalar(0, 0, 0);
|
2023-08-04 15:50:03 +08:00
|
|
|
std::string str = cv::format("%02d", i+1);
|
2017-06-07 01:22:30 +08:00
|
|
|
int baseLine = 0;
|
2023-08-04 15:50:03 +08:00
|
|
|
Size box = getTextSize(str, FONT_HERSHEY_COMPLEX, 2, 5, &baseLine);
|
|
|
|
putText(frame, str, Point((frame.cols - box.width) / 2, (frame.rows - box.height) / 2 + baseLine),
|
2017-07-05 18:45:08 +08:00
|
|
|
FONT_HERSHEY_COMPLEX, 2, Scalar(0, 0, 255), 5, LINE_AA);
|
2023-08-04 15:50:03 +08:00
|
|
|
Point p(i * frame.cols / (frame_count - 1), i * frame.rows / (frame_count - 1));
|
2017-07-05 18:45:08 +08:00
|
|
|
circle(frame, p, 50, Scalar(200, 25, 55), 8, LINE_AA);
|
|
|
|
#if 0
|
|
|
|
imshow("frame", frame);
|
|
|
|
waitKey();
|
|
|
|
#endif
|
2014-07-10 22:27:32 +08:00
|
|
|
}
|
|
|
|
|
2018-02-14 23:04:54 +08:00
|
|
|
class BunnyParameters
|
|
|
|
{
|
|
|
|
public:
|
2023-10-06 18:33:21 +08:00
|
|
|
inline static int getWidth() { return 672; }
|
|
|
|
inline static int getHeight() { return 384; }
|
|
|
|
inline static int getFps() { return 24; }
|
|
|
|
inline static double getTime() { return 5.21; }
|
|
|
|
inline static int getCount() { return cvRound(getFps() * getTime()); }
|
2018-02-14 23:04:54 +08:00
|
|
|
inline static std::string getFilename(const std::string &ext)
|
|
|
|
{
|
|
|
|
return cvtest::TS::ptr()->get_data_path() + "video/big_buck_bunny" + ext;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2018-07-19 21:14:50 +08:00
|
|
|
|
|
|
|
static inline bool isBackendAvailable(cv::VideoCaptureAPIs api, const std::vector<cv::VideoCaptureAPIs>& api_list)
|
|
|
|
{
|
|
|
|
for (size_t i = 0; i < api_list.size(); i++)
|
|
|
|
{
|
|
|
|
if (api_list[i] == api)
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2014-07-10 22:27:32 +08:00
|
|
|
#endif
|