Path: blob/master/modules/videoio/test/test_precomp.hpp
16354 views
// This file is part of OpenCV project.1// It is subject to the license terms in the LICENSE file found in the top-level directory2// of this distribution and at http://opencv.org/license.html.3#ifndef __OPENCV_TEST_PRECOMP_HPP__4#define __OPENCV_TEST_PRECOMP_HPP__56#include "opencv2/ts.hpp"7#include "opencv2/videoio.hpp"8#include "opencv2/videoio/registry.hpp"9#include "opencv2/imgproc/imgproc_c.h"1011#include "opencv2/core/private.hpp"1213namespace cv {1415inline std::ostream &operator<<(std::ostream &out, const VideoCaptureAPIs& api)16{17out << cv::videoio_registry::getBackendName(api); return out;18}1920static inline void PrintTo(const cv::VideoCaptureAPIs& api, std::ostream* os)21{22*os << cv::videoio_registry::getBackendName(api);23}2425} // namespace262728inline std::string fourccToString(int fourcc)29{30return cv::format("%c%c%c%c", fourcc & 255, (fourcc >> 8) & 255, (fourcc >> 16) & 255, (fourcc >> 24) & 255);31}3233inline int fourccFromString(const std::string &fourcc)34{35if (fourcc.size() != 4) return 0;36return cv::VideoWriter::fourcc(fourcc[0], fourcc[1], fourcc[2], fourcc[3]);37}3839inline void generateFrame(int i, int FRAME_COUNT, cv::Mat & frame)40{41using namespace cv;42using namespace std;43int offset = (((i * 5) % FRAME_COUNT) - FRAME_COUNT / 2) * (frame.cols / 2) / FRAME_COUNT;44frame(cv::Rect(0, 0, frame.cols / 2 + offset, frame.rows)) = Scalar(255, 255, 255);45frame(cv::Rect(frame.cols / 2 + offset, 0, frame.cols - frame.cols / 2 - offset, frame.rows)) = Scalar(0, 0, 0);46ostringstream buf; buf << "Frame " << setw(2) << setfill('0') << i + 1;47int baseLine = 0;48Size box = getTextSize(buf.str(), FONT_HERSHEY_COMPLEX, 2, 5, &baseLine);49putText(frame, buf.str(), Point((frame.cols - box.width) / 2, (frame.rows - box.height) / 2 + baseLine),50FONT_HERSHEY_COMPLEX, 2, Scalar(0, 0, 255), 5, LINE_AA);51Point p(i * frame.cols / (FRAME_COUNT - 1), i * frame.rows / (FRAME_COUNT - 1));52circle(frame, p, 50, Scalar(200, 25, 55), 8, LINE_AA);53#if 054imshow("frame", frame);55waitKey();56#endif57}5859class BunnyParameters60{61public:62inline static int getWidth() { return 672; };63inline static int getHeight() { return 384; };64inline static int getFps() { return 24; };65inline static double getTime() { return 5.21; };66inline static int getCount() { return cvRound(getFps() * getTime()); };67inline static std::string getFilename(const std::string &ext)68{69return cvtest::TS::ptr()->get_data_path() + "video/big_buck_bunny" + ext;70}71};727374static inline bool isBackendAvailable(cv::VideoCaptureAPIs api, const std::vector<cv::VideoCaptureAPIs>& api_list)75{76for (size_t i = 0; i < api_list.size(); i++)77{78if (api_list[i] == api)79return true;80}81return false;82}8384#endif858687