forked from kcwongjoe/directshow_camera
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patheg5_disconnect_process.cpp
More file actions
48 lines (36 loc) · 1.17 KB
/
eg5_disconnect_process.cpp
File metadata and controls
48 lines (36 loc) · 1.17 KB
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
#include "eg5_disconnect_process.h"
#include <uvc_camera.h>
#include <iostream>
using namespace DirectShowCamera;
void eg5_disconnect_process()
{
// Get a empty camera
UVCCamera camera = UVCCamera();
// Print camera list
std::vector<CameraDevice> cameraDeivceList = camera.getCameras();
for (int i = 0; i < cameraDeivceList.size(); i++) {
std::cout << std::to_string(i) + ": " + cameraDeivceList[i].getFriendlyName() << std::endl;
}
std::cout << "Select your USB camera:" << std::endl;
int cameraIndex;
std::cin >> cameraIndex;
// Open the camera
std::cout << "Open the camera..." << std::endl;
camera.open(cameraDeivceList[cameraIndex]);
camera.setDisconnectionProcess(
[]()
{
std::cout << "Camera was disconnected." << std::endl;
}
);
// Start Capture
std::cout << "Start capture..." << std::endl;
camera.startCapture();
// Wait for 2 second
std::cout << "You can unplug the USB camera now." << std::endl;
std::this_thread::sleep_for(std::chrono::milliseconds(2000));
// Stop Capture
camera.stopCapture();
// Close the camera.
camera.close();
}