当前位置:网站首页>Save video opencv:: videowriter
Save video opencv:: videowriter
2022-07-02 09:39:00 【Ignorant dream fireworks】
// Video parameters
m_videoInfo.fps = m_capture.get(cv::CAP_PROP_FPS);
m_videoInfo.width = m_capture.get(cv::CAP_PROP_FRAME_WIDTH);
m_videoInfo.height = m_capture.get(cv::CAP_PROP_FRAME_HEIGHT);
// initialization VideoWriter
m_mapVideoWriter[_strVideoName] = cv::VideoWriter(_strVideoName,
cv::VideoWriter::fourcc('X', 'V', 'I', 'D'),
m_videoInfo.fps,
cv::Size(m_videoInfo.width, m_videoInfo.height)
);
// Writing data
for (auto videoWriter : m_mapVideoWriter)
{
videoWriter.second << _mat;
}
Video save results 
while(true)
{
for (auto videoWriter : m_mapVideoWriter)
{
videoWriter.second << _mat;
funtion();
}
}
The operation of writing data , Run the following , The premise of saving data is normal ,funtion() The execution time cannot be too long ( The frequency of saving pictures should meet certain requirements ,120ms There will be errors in saving , No other tests ). Upper figure video.mp4 Videos saved for normal ,15_9_36_model_zhiyin.mp4 Results saved for errors , There will be an error in the following figure when opening .
VideoSaveFunTool folders creating , File name splicing class
VideoSaveFunTool.h
#pragma once
/*
Save in video , File path processing class
*/
#ifndef VIDEOSAVEFUNTOOL_H
#define VIDEOSAVEFUNTOOL_H
#include <ctime>
#include <string>
namespace UsbCamera
{
class VideoSaveFunTool
{
public:
VideoSaveFunTool();
void GetSaveVidePath(std::string& _strVideoDir);
private:
std::string GetVideoDir();
bool CreateDir(std::string & _strDir);
void UpdateTime();
std::string m_fileDir;
struct tm* m_pTime; // Storage time , Used to save video files
};
}
#endif // !VIDEOSAVEFUNTOOL_H
VideoSaveFunTool.cpp
#include "VideoSaveFunTool.h"
#include "io.h"
#include <ctime>
#include <direct.h>
#include <iostream>
#include "tinyxml2.h"
namespace UsbCamera
{
#define PATH_DELIMITER '\\'
void VideoSaveFunTool::UpdateTime()
{
time_t nowtime;
time(&nowtime);
// Use this function to get the current system time , To use this function, you need to pass in time_t Type variable nowtime Address value of .
m_pTime = localtime(&nowtime);
m_pTime->tm_year += 1900;
}
bool VideoSaveFunTool::CreateDir(std::string & _strDir)
{
std::string folder_builder;
std::string sub;
sub.reserve(_strDir.size());
for (auto it = _strDir.begin(); it != _strDir.end(); ++it) {
const char c = *it;
sub.push_back(c);
if (c == PATH_DELIMITER || it == _strDir.end() - 1) {
folder_builder.append(sub);
if (0 != ::_access(folder_builder.c_str(), 0)) {
// this folder not exist
if (0 != ::_mkdir(folder_builder.c_str())) {
// create failed
return false;
}
}
sub.clear();
}
}
return true;
}
std::string VideoSaveFunTool::GetVideoDir()
{
// Create a new empty document
tinyxml2::XMLDocument xmlDoc;
// Read the specified xml File and judge whether the reading is successful
tinyxml2::XMLError eResult = xmlDoc.LoadFile("config/VideoFileConfig.cas");
if (eResult != tinyxml2::XML_SUCCESS)
{
printf("error code :%d\n", tinyxml2::XML_ERROR_FILE_NOT_FOUND);
return "";
}
// Get the first node of the file ( The root node )
tinyxml2::XMLNode * pRoot = xmlDoc.FirstChildElement("VideoFileConfig");
if (pRoot == nullptr)
{
printf("error code :%d\n", tinyxml2::XML_ERROR_FILE_READ_ERROR);
return "";
}
else
{
tinyxml2::XMLElement * pVideoDirElement = pRoot->FirstChildElement("VideoDir");
return pVideoDirElement->GetText();
}
}
VideoSaveFunTool::VideoSaveFunTool()
{
m_fileDir = GetVideoDir();
if (m_fileDir == "")
m_fileDir = "D:\\Video";
}
void VideoSaveFunTool::GetSaveVidePath(std::string& _strVideoDir)
{
struct tm time; // Time
std::string filePath; // Saved path
// Update time
UpdateTime();
// Build a storage directory
filePath = m_fileDir + "\\" + std::to_string(m_pTime->tm_year) + "\\" + std::to_string(m_pTime->tm_mon) + "\\"
+ std::to_string(m_pTime->tm_mday);
CreateDir(filePath);
filePath = filePath + "\\" + std::to_string(m_pTime->tm_hour) + "_" + std::to_string(m_pTime->tm_min)
+ "_" + std::to_string(m_pTime->tm_sec);
_strVideoDir = filePath;
}
}
边栏推荐
- Actual combat of microservices | discovery and invocation of original ecosystem implementation services
- 图像识别-数据采集
- MySQL error: unblock with mysqladmin flush hosts
- 在SQL注入中,为什么union联合查询,id必须等于0
- C语言之分草莓
- Redis 序列化 GenericJackson2JsonRedisSerializer和Jackson2JsonRedisSerializer的区别
- ClassFile - Attributes - Code
- VIM operation command Encyclopedia
- Mathematics in machine learning -- point estimation (I): basic knowledge
- Creation and jump of activity
猜你喜欢

企业级SaaS CRM实现

Failed to configure a DataSource: ‘url‘ attribute is not specified and no embedd

定时线程池实现请求合并

Inverter Simulink model -- processor in the loop test (PIL)

2837xd code generation - stateflow (4)

zk配置中心---Config Toolkit配置与使用

kinect dk 获取CV::Mat格式的彩色RGB图像(openpose中使用)

In depth analysis of how the JVM executes Hello World

Microservice practice | fuse hytrix initial experience

vs+qt 设置应用程序图标
随机推荐
Mysql默认事务隔离级别及行锁
图像识别-数据清洗
Timed thread pool implements request merging
Say goodbye to 996. What are the necessary plug-ins in idea?
Discussion on improving development quality and reducing test bug rate
2837xd code generation - Summary
Demand delineation executive summary
Idea view bytecode configuration
Watermelon book -- Chapter 6 Support vector machine (SVM)
PI control of grid connected inverter (grid connected mode)
Read Day5 30 minutes before going to bed every day_ All key values in the map, how to obtain all value values
JDBC review
Idempotent design of Internet API interface
记录下对游戏主机配置的个人理解与心得
Bold prediction: it will become the core player of 5g
Read 30 minutes before going to bed every day_ day3_ Files
hystrix 实现请求合并
自定义Redis连接池
Navicat 远程连接Mysql报错1045 - Access denied for user ‘root‘@‘222.173.220.236‘ (using password: YES)
C语言之二进制与十进制