我是靠谱客的博主 香蕉白开水,这篇文章主要介绍Qt基于Qml摄像头使用,现在分享给大家,希望可以做个参考。

演示效果

 完整QML源码

复制代码
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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
import QtQuick 2.12 import QtQuick.Window 2.12 import QtMultimedia 5.12 import QtQuick.Controls 2.12 Window { visible: true; width: 600; height: 400; color: "black"; title:"Qt基于Qml摄像头使用" //摄像机 Camera { id: camera; captureMode: Camera.CaptureStillImage;//捕获模式 //摄像机焦点模式 focus { focusMode: Camera.FocusAuto; focusPointMode: Camera.FocusPointCenter; } //图像处理模式 imageProcessing { whiteBalanceMode: CameraImageProcessing.WhiteBalanceAuto; } flash.mode: Camera.FlashAuto; //图像捕获 imageCapture { //分辩率 resolution: Qt.size(640, 480); //图像捕获成功信号 onImageCaptured: { camera.stop();//停止捕获 photoPreview.visible = true;//显示图像 actionBar.visible = false; viewfinder.visible = false; photoPreview.source = preview } //保存图像 onImageSaved: { console.log(path); } } //锁定状态信号 onLockStatusChanged: { switch(lockStatus){ case Camera.Locked: console.log("locked"); imageCapture.captureToLocation("capture.jpg"); unlock(); break; case Camera.Searching: console.log("searching"); break; case Camera.Unlocked: console.log("unlocked"); break; } } } //视频输出 VideoOutput { id: viewfinder; source: camera;//视频输出源 focus : visible; anchors.fill: parent; autoOrientation: true; } Image { id: photoPreview; anchors.fill: parent; visible: false; fillMode: Image.PreserveAspectFit; //拍照 FlatButton { iconSource: "res/ic_launcher_camera.png"; width: 76; height: 76; anchors.left: parent.left; anchors.bottom: parent.bottom; anchors.margins: 8; onClicked: { camera.start(); actionBar.visible = true; viewfinder.visible = true; photoPreview.visible = false; } } } Image { id: actionBar; source: "res/control_bar.png"; anchors.bottom: parent.bottom; anchors.bottomMargin: 8; anchors.horizontalCenter: parent.horizontalCenter; z: 1; FlatButton { id: shutter; anchors.centerIn: parent; iconSource: "res/ic_cam_shutter.png"; width: 88; height: 88; iconWidth: 84; iconHeight: 84; onClicked: { camera.searchAndLock(); } } FlatButton { id: zoomout; anchors.verticalCenter: shutter.verticalCenter; anchors.right: shutter.left; anchors.rightMargin: 4; width: 70; height: 70; iconWidth: 40; iconHeight: 40; text: "缩小"; font.pointSize: 12; iconSource: "res/ic_zoom_out.png"; onClicked: { console.log("maximumDigitalZoom-", camera.maximumDigitalZoom); console.log("maximumOpticalZoom-", camera.maximumOpticalZoom); if(camera.digitalZoom > 1){ camera.digitalZoom -= 1; } } } FlatButton { id: zoomin; anchors.verticalCenter: shutter.verticalCenter; anchors.right: zoomout.left; anchors.rightMargin: 4; width: 70; height: 70; iconWidth: 40; iconHeight: 40; text: "放大"; font.pointSize: 12; iconSource: "res/ic_zoom_in.png"; onClicked: { if(camera.digitalZoom < camera.maximumDigitalZoom){ camera.digitalZoom += 1; } } } FlatButton { id: currentFlash; anchors.verticalCenter: shutter.verticalCenter; anchors.left: shutter.right; anchors.leftMargin: 4; width: 70; height: 70; iconWidth: 40; iconHeight: 40; font.pointSize: 12; property var modeIcon: [ "res/ic_menu_stat_flash_auto.png", "res/ic_menu_stat_flash.png", "res/ic_menu_stat_flash_off.png" ] property var modeDesc: [ "自动", "打开", "关闭" ] property var flashMode: [ Camera.FlashAuto, Camera.FlashOn, Camera.FlashOff ] property int mode: 0; text: modeDesc[mode]; iconSource: modeIcon[mode]; onClicked: { mode = (mode + 1)%3; camera.flash.mode = flashMode[mode]; } } FlatButton { id: currentScene; anchors.verticalCenter: shutter.verticalCenter; anchors.left: currentFlash.right; anchors.leftMargin: 4; width: 70; height: 70; iconWidth: 40; iconHeight: 40; font.pointSize: 12; property var modeIcon: [ "res/ic_menu_stat_auto.png", "res/ic_menu_stat_portrait.png", "res/ic_menu_stat_landscape.png", "res/ic_menu_stat_night.png", "res/ic_menu_stat_action.png" ] property var modeDesc: [ "自动", "人物", "风景", "夜间", "运动" ] //摄像机模式 property var exposureMode: [ Camera.ExposureAuto, Camera.ExposurePortrait, Camera.ExposureBeach, Camera.ExposureNight, Camera.ExposureSports ] property int mode: 0; text: modeDesc[mode]; iconSource: modeIcon[mode]; onClicked: { mode = (mode + 1)%5; camera.exposure.exposureMode = exposureMode[mode]; } } } }

最后

以上就是香蕉白开水最近收集整理的关于Qt基于Qml摄像头使用的全部内容,更多相关Qt基于Qml摄像头使用内容请搜索靠谱客的其他文章。

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

评论列表共有 0 条评论

立即
投稿
返回
顶部