视频分析模块主要包含两个函数,一个是VideoAnalysis::setup(....),其主要功能就是确定测试的视频是视频文件或摄像头输入亦或是采用命令行参数;第二个函数是VideoAnalysis::start(),其主要功能初始化视频处理、设置视频获取方式以及开始视频捕获功能等。
1、VideoAnalysis::setup(....)
该函数的代码如下:
1. bool VideoAnalysis::setup(int argc, const char **argv)
2. {
3. bool flag = false;
4.
5. const char* keys =
6. "{hp|help|false|Print help message}"
7. "{uf|use_file|false|Use video file}"
8. "{fn|filename||Specify video file}"
9. "{uc|use_cam|false|Use camera}"
10. "{ca|camera|0|Specify camera index}"
11. "{co|use_comp|false|Use mask comparator}"
12. "{st|stopAt|0|Frame number to stop}"
13. "{im|imgref||Specify image file}" ;
14.
15. cv::CommandLineParser cmd(argc, argv, keys);
16.
17. ////////////use_command
18. if (argc <= 1 || cmd.get<bool>("help") == true)
19. {
20. "Usage: " << argv[0] << " [options]" << endl;
21. "Avaible options:" << endl;
22. cmd.printParams();
23. return false;
24. }
25.
26. ////////////use_file
27. bool>("use_file");
28. if (use_file)
29. {
30. "filename");
31.
32. if (filename.empty())
33. {
34. "Specify filename" << endl;
35. return false;
36. }
37.
38. true;
39. }
40.
41. ////////////use_camera
42. bool>("use_cam");
43. if (use_camera)
44. {
45. int>("camera");
46. true;
47. }
48.
49. ////////////use_comp
50. if (flag == true)
51. {
52. bool>("use_comp");
53. if (use_comp)
54. {
55. int>("stopAt");
56. "imgref");
57.
58. if (imgref.empty())
59. {
60. "Specify image reference" << endl;
61. return false;
62. }
63. }
64. }
65.
66. return flag;
67. }
它的主要流程如下图所示:
2、VideoAnalysis::start()
该函数的代码如下:
2. {
3. //cout << "Press 'ESC' to stop..." << endl;
4.
5. do
6. {
7. new VideoCapture;
8. new FrameProcessor;
9.
10. frameProcessor->init();
11. frameProcessor->frameToStop = frameToStop;
12. frameProcessor->imgref = imgref;
13.
14. ///setFrameProcessor
15.
16. if (use_file)
17. ///setVideo
18.
19. if (use_camera)
20. ///setCamera
21.
22. ///start
23.
24. if (use_file || use_camera)
25. break;
26.
27. frameProcessor->finish();
28.
29. int key = cvWaitKey(500);
30. if (key == KEY_ESC)
31. break;
32.
33. delete frameProcessor;
34. delete videoCapture;
35.
36. }
37. while (1);
38.
39. delete frameProcessor;
40. delete videoCapture;
41. }
它的主要流程如下图所示: