RLL Computer Vision Code: code/tool.cpp 源文件

RLL Computer Vision

RLL Computer Vision Code  1.0
江苏科技大学HLL战队机器视觉代码
tool.cpp
浏览该文件的文档.
1 #include "tool.h"
2 
3 namespace HCVC {
5 
6 void Tool::addTrackBar(const string& windowName, VideoCapture& file)
7 {
8  double count = file.get(CAP_PROP_FRAME_COUNT);
9  createTrackbar("trackBar", windowName, &g_trackBarLocation, static_cast<int>(count), onTrackBarCallback, &file);
10 }
11 
12 void Tool::onTrackBarCallback(int pos, void* file)
13 {
14  static_cast<VideoCapture*>(file)->set(CAP_PROP_POS_FRAMES, pos);
15 }
16 
17 void Tool::setTrackBarFollow(const string& windowName, const VideoCapture& file)
18 {
19  double cur = file.get(CAP_PROP_POS_FRAMES);
20  setTrackbarPos("trackBar", windowName, static_cast<int>(cur));
21 }
22 
23 void Tool::addKeyboardControl(VideoCapture& srcFile, const int& delay)
24 {
25  //记录当前暂停帧
26  static double recordFrame = -1;
27  //相当于设定播放帧率为每秒1000/33=30帧
28  switch(waitKey(delay))
29  {
30  //如果读取到esc键终止播放
31  case ESC:
32  srcFile.release();
33  break;
34 
35  //如果读取到空格键暂停播放,直到再次按下空格键,期间可以按下esc键退出
36  case PAUSE:
37  if(recordFrame < 0)
38  {
39  recordFrame = srcFile.get(CAP_PROP_POS_FRAMES);
40  }
41  else
42  {
43  recordFrame = -1;
44  }
45  break;
46 
47  //j键为视频回放
48  case MOVE_BACK:
49  if(recordFrame < 0)
50  {
51  double cur = srcFile.get(CAP_PROP_POS_FRAMES);
52  srcFile.set(CAP_PROP_POS_FRAMES, cur-1);
53  }
54  else
55  {
56  recordFrame--;
57  srcFile.set(CAP_PROP_POS_FRAMES, recordFrame);
58  }
59  break;
60 
61  //k键为视频快进
62  case MOVE_FORWARD:
63  if(recordFrame < 0)
64  {
65  double cur = srcFile.get(CAP_PROP_POS_FRAMES);
66  srcFile.set(CAP_PROP_POS_FRAMES, cur+1);
67  }
68  else
69  {
70  recordFrame++;
71  srcFile.set(CAP_PROP_POS_FRAMES, recordFrame);
72  }
73  break;
74 
75  default:
76  if(recordFrame >= 0)
77  {
78  srcFile.set(CAP_PROP_POS_FRAMES, recordFrame);
79  }
80  }
81 }
82 
83 void Tool::getTimeCount(const int& id)
84 {
85  static long long startTimes[100] = {0};
86 
87  if(startTimes[id] == 0)
88  {
89  startTimes[id] = getTickCount();
90  }
91  else
92  {
93  cout << "id - " << id << " Cost time: "
94  << (getTickCount()-startTimes[id]) / getTickFrequency()
95  << " s" << endl;
96 
97  startTimes[id] = getTickCount();
98  }
99 }
100 }
static void addTrackBar(const string &windowName, VideoCapture &file)
添加滑动控制条
Definition: tool.cpp:6
static void onTrackBarCallback(int pos, void *data)
滑动控制条回调函数
Definition: tool.cpp:12
static void addKeyboardControl(VideoCapture &srcFile, const int &delay=1)
添加键盘按键控制
Definition: tool.cpp:23
HLL Computer Vision Code namepace.
int g_trackBarLocation
Definition: tool.cpp:4
static void setTrackBarFollow(const string &windowName, const VideoCapture &file)
添加滑动控制条跟随视频进度功能
Definition: tool.cpp:17
static void getTimeCount(const int &id)
添加运行时间统计
Definition: tool.cpp:83
制作者   doxygen 1.8.13