-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvideo_player.cpp
51 lines (45 loc) · 1.24 KB
/
video_player.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#include "video_player.hpp"
video_player::video_player() {}
video_player::~video_player() {}
void video_player::play_video(cv::Mat &image) {
int key = cv::waitKey(1);
respondKeyIfVideoContinuing(key);
if (stop_video) {
int key = cv::waitKey(0); // 无限制等待
respondKeyIfVideoStopped(key, image);
}
}
void video_player::respondKeyIfVideoContinuing(int key)
{
if (key == 27)// esc键退出
{
exit(0);
}
else if (key == ' ')// 空格键暂停视频
{
stop_video = true;
}
}
void video_player::respondKeyIfVideoStopped(int key, cv::Mat &img) {
static int cnt_img = 0;
if (key == 27)// esc键退出
{
exit(0);
} else if (key == 115)// s键保存视频
{
std::cout << "save image" << std::endl;
std::stringstream sstream;
sstream.str("");
sstream << "../save/gl_test/" << "gl_test_" <<cnt_img << ".jpg";
std::cout << "sstream" << sstream.str() << std::endl;
cv::imwrite(sstream.str(), img);
cnt_img++;
stop_video = true;
} else if (key == ' ')// 空格键暂停视频
{
stop_video = true;
} else if (key == 119)// w 取消暂停视频
{
stop_video = false;
}
}