当前位置:网站首页>[opencv introduction to mastery 9] opencv video capture, image and video conversion
[opencv introduction to mastery 9] opencv video capture, image and video conversion
2022-07-04 18:57:00 【Life is like a song, and code is like a poem】
One 、 The relationship between pictures and videos
The picture is still , Put many pictures with gradual changes , Organized by time , That is to say, video .
The video is linked , Pause every moment in the video , Then the picture is displayed .
Video frame
Every instant picture in the video pauses, and the picture is the video frameVideo frame rate
Frames per second (Frames per Second, Jane :FPS), This word is often used in film and television production and video games . Because of the special physiological structure of human eyes , If the frame rate of the picture is higher than 16 When , It would be considered coherent , This phenomenon is called visual staying . That's why film is shot one by one , Then quickly play .
For the game , First person shooters pay more attention to FPS High and low , If FPS<30 Words , The game will appear incoherent .30fps Is acceptable , But improve performance to 60fps It can obviously enhance the sense of interaction and realism , But generally speaking, more than 75fps Generally, it is not easy to notice that there is a significant increase in fluency . If the frame rate exceeds the screen refresh rate, it will only waste graphics processing power , Because the monitor can't update so fast , In this way, the frame rate exceeding the refresh rate is wasted .
Two 、 Video and picture conversion
1. Video capture
There are several steps for video capture :
Video on
Read video frames
choice
// Open the video
VideoCapture captrue = VideoCapture("test.mp4");
// Open the failure
if (!captrue.isOpened())
{
return 1;
}
int rate = captrue.get(cv::CAP_PROP_FPS);
int frameCount = captrue.get(cv::CAP_PROP_FRAME_COUNT);
int frameWidth = captrue.get(cv::CAP_PROP_FRAME_WIDTH);
int framehHeight = captrue.get(cv::CAP_PROP_FRAME_HEIGHT);
int format = captrue.get(cv::CAP_PROP_FORMAT);
int video_duration = frameCount / rate;
cout << "---------------------------------------------" << endl;
cout << " Pixel width of video frame :" << frameWidth << endl;
cout << " Pixel height of video frame :" << framehHeight << endl;
cout << " Frame rate of recorded video ( frame / second ):" << rate << endl;
cout << " Total frames of video files :" << frameCount << endl;
cout << " The format of the image :" << format << endl;
cout << " Video duration :" << video_duration << endl;
cout << "---------------------------------------------" << endl;
namedWindow("Video", WINDOW_NORMAL);
resizeWindow("Video", 480, 270);
// Video write object
cv::VideoWriter write;
// Write the video file name
std::string outFlie = "videoTest.mp4";
// Open video file , Prepare to write
//write.open(outFlie, -1, rate, Size(frameWidth, framehHeight), true);
write.open(outFlie, CV_FOURCC('D', 'I', 'V', 'X'), rate, Size(frameWidth, framehHeight), true);
/* from 6700 Frame start reading */
bool stop = false;
cv::Mat frame;
captrue.set(CV_CAP_PROP_POS_FRAMES, 6700); // Jump to the 6700 frame
// Loop read video frames
while (!stop)
{
// Read frame
if (!captrue.read(frame))
break;
cv::imshow("Video", frame);
// write file
write.write(frame);
if (cv::waitKey(10) > 0)
{
stop = true;
}
}
// Release object
captrue.release();
write.release();
2. Video read pictures
VideoCapture captrue = VideoCapture(filename);
if (!captrue.isOpened()) {
return 1;
}
int picNum = 0;
char picName[32] = "";
cv::Mat frame;
while (1)
{
if (!captrue.read(frame))
break;
picNum++;
cout << "picNum:" << picNum << endl;
memset(picName, 0, sizeof(picName));
sprintf(picName, "pic_%d.jpg", picNum);
imwrite(picName, frame);
}
3. Picture synthesis video
int idx = 0;
char picName[64];
for (idx = 1; idx < 100; idx++)
{
sprintf(picName, "pic%d_out.jpg", idx);
cout << "read picture:" << picName << endl;
Mat image = imread(string(picName));
if (image.empty())
{
cout << "read picture failed!" << endl;
continue;
}
static VideoWriter saveVideo("output2.avi", CV_FOURCC('M', 'J', 'P', 'G'), 25, Size(image.cols, image.rows));
saveVideo << image;
waitKey(50);
}
边栏推荐
- 基于C语言的菜鸟驿站管理系统
- ByteDance dev better technology salon was successfully held, and we joined hands with Huatai to share our experience in improving the efficiency of web research and development
- Numpy 的仿制 2
- android使用SQLiteOpenHelper闪退
- [go language question brushing chapter] go conclusion chapter | introduction to functions, structures, interfaces, and errors
- Li Kou brush question diary /day8/7.1
- Just today, four experts from HSBC gathered to discuss the problems of bank core system transformation, migration and reconstruction
- . Net ORM framework hisql practice - Chapter 2 - using hisql to realize menu management (add, delete, modify and check)
- Pb extended DLL development (super chapter) (VII)
- 怎么开户才是安全的,
猜你喜欢

提升复杂场景三维重建精度 | 基于PaddleSeg分割无人机遥感影像

激进技术派 vs 项目保守派的微服务架构之争

Mysql5.7 installation tutorial graphic explanation

Principle and application of ThreadLocal

My colleagues quietly told me that flying Book notification can still play like this

MySQL common add, delete, modify and query operations (crud)
![[HCIA continuous update] network management and operation and maintenance](/img/a4/406b145793b701b001f04c7538dab3.png)
[HCIA continuous update] network management and operation and maintenance

一直以为做报表只能用EXCEL和PPT,直到我看到了这套模板(附模板)

Blue bridge: sympodial plant

Reptile elementary learning
随机推荐
[cloud native] what is the "grid" of service grid?
李迟2022年6月工作生活总结
【Go语言刷题篇】Go完结篇|函数、结构体、接口、错误入门学习
如何使用 wget 和 curl 下载文件
How to open an account is safe,
[go language question brushing chapter] go conclusion chapter | introduction to functions, structures, interfaces, and errors
ByteDance dev better technology salon was successfully held, and we joined hands with Huatai to share our experience in improving the efficiency of web research and development
Caché WebSocket
I always thought that excel and PPT could only be used for making statements until I saw this set of templates (attached)
【云端心声 建议征集】云商店焕新升级:提有效建议,赢海量码豆、华为AI音箱2!
中国农科院基因组所汪鸿儒课题组诚邀加入
Nature Microbiology | 可感染阿斯加德古菌的六种深海沉积物中的病毒基因组
[HCIA continuous update] WAN technology
vbs或vbe如何修改图标
提升复杂场景三维重建精度 | 基于PaddleSeg分割无人机遥感影像
力扣刷题日记/day6/6.28
Lua emmylua annotation details
激进技术派 vs 项目保守派的微服务架构之争
Scala基础教程--16--泛型
ITSS运维能力成熟度分级详解|一文搞清ITSS证书