我是靠谱客的博主 隐形楼房,这篇文章主要介绍opencv播放器和摄像头视频播放,现在分享给大家,希望可以做个参考。

2019独角兽企业重金招聘Python工程师标准>>> hot3.png

在看《学习opencv》这本书,按着其中的例子和写了一个播放器和摄像头播放,代码如下

复制代码
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
#include <opencv/cv.h> #include <opencv/highgui.h> #include <iostream> #include <sstream> using namespace std; using namespace cv; #define ESC 27 CvCapture* g_cvFileCap = 0; CvCapture* g_cvCameraCap = 0; int g_pos = 0; int String2Int(const string& str_) { int _re = 0; stringstream _ss; _ss << str_; _ss >> _re; return _re; } void OnTrackbarSlide(int nPos_) { cvSetCaptureProperty(g_cvFileCap, CV_CAP_PROP_POS_FRAMES, nPos_); } int main(int argc, char* argv[]) { if (argc < 3) { return -1; } int _re = String2Int(argv[1]); if (_re == 0) { g_cvFileCap = cvCreateFileCapture(argv[2]); if (g_cvFileCap != NULL) { cvNamedWindow("AVWidget"); cvMoveWindow("AVWidget", 100, 100); int _nFrames = cvGetCaptureProperty(g_cvFileCap, CV_CAP_PROP_FRAME_COUNT); cvCreateTrackbar("Pos", "AVWidget", &g_pos, _nFrames, OnTrackbarSlide); while (1) { IplImage* _frame = cvQueryFrame(g_cvFileCap); if (_frame != NULL) { if (ESC == waitKey(1000 / 25)) { break; } cvSmooth(_frame, _frame); cvShowImage("AVWidget", _frame); cvSetTrackbarPos("Pos", "AVWidget", g_pos++); } } } cvReleaseCapture(&g_cvFileCap); } else { int _index = String2Int(argv[2]); g_cvCameraCap = cvCreateCameraCapture(_index); if (g_cvCameraCap != NULL) { cvNamedWindow("CamWidget"); cvMoveWindow("CamWidget", 100, 100); while (1) { IplImage* _frame = cvQueryFrame(g_cvCameraCap); if (_frame != NULL) { if (ESC == waitKey(1000 / 25)) { break; } cvSmooth(_frame, _frame); cvShowImage("CamWidget", _frame); } } } cvReleaseCapture(&g_cvCameraCap); } return 0; }
通过传入参数实现打开那个视频和摄像头,当参数为 0 xxxx时,打开视频,参数为1 x打开第几个摄像头。

效果行。打开摄像头就算了。

其实使用opencv很方便。通过cvCreateFileCapture和cvQueryFrame就完成了视频文件的读取。操作摄像头唯一的不同是cvCreateCameraCapture,很方便。


转载于:https://my.oschina.net/u/854744/blog/418534

最后

以上就是隐形楼房最近收集整理的关于opencv播放器和摄像头视频播放的全部内容,更多相关opencv播放器和摄像头视频播放内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(58)

评论列表共有 0 条评论

立即
投稿
返回
顶部