forked from kcwongjoe/directshow_camera
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patheg9_direct_arpara_camera.cpp
More file actions
96 lines (84 loc) · 3.12 KB
/
eg9_direct_arpara_camera.cpp
File metadata and controls
96 lines (84 loc) · 3.12 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
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
#include "eg9_direct_arpara_camera.h"
#include <arpara_camera.h>
#include <filesystem>
#include <iostream>
#include <fstream>
using namespace DirectShowCamera;
void draw_fps()
{
}
void eg9_arpara_camera()
{
// Get a empty camera
ArparaCamera camera = ArparaCamera();
// Get available camera list
std::cout << "Start to list the available cameras..." << std::endl;
std::vector<DirectShowCameraDevice> cameraDeivceList = camera.getDirectShowArparaCameras();
for (int i = 0; i < cameraDeivceList.size(); i++) {
std::cout << cameraDeivceList[i] << std::endl;
}
if (cameraDeivceList.size() == 0)
{
std::cout << "no arpara camera found, exiting" << std::endl;
} else
{
DirectShowCameraDevice &device = cameraDeivceList[cameraDeivceList.size() - 1];
// Get supported formats
std::cout << "DirectShowCameraDevice supported formats " << std::endl;
auto formats = device.getDirectShowVideoFormats();
for(auto& format: formats)
{
std::cout << format << std::endl;
}
// select a format
DirectShowVideoFormat format = formats[formats.size() - 1];
std::cout << "selected format " << format << std::endl;
// Open the first camera in the biggest resolution
std::cout << "Open the first camera..." << std::endl;
bool success = camera.open(device, &format, false);
if (!success)
{
std::cerr << "failed to open camera" << std::endl;
}
std::cout << "show DirectShow properties" << std::string(*camera.getDirectShowProperties()) << std::endl;
//camera.resetProperties();
// Get exposure in second
double exposureTime = camera.getExposure();
if (exposureTime > 0.0)
{
std::cout << "Exposure: " + std::to_string(exposureTime) + "s" << std::endl;
}
else
{
std::cout << "This device doesn't support exposure time" << std::endl;
}
// Reset all properties to default
//std::cout << "Reset properties to default..." << std::endl;
//camera.resetProperties();
{
camera.startCapture();
// Wait for 1 second
std::this_thread::sleep_for(std::chrono::milliseconds(1000));
cv::Mat frame;
while (true)
{
frame = cv::Mat(481, 1280, CV_8UC1, camera.getCameraGrayImage());
cv::imshow("frame", frame);
char key = cv::waitKey(1);
if (key == 'q')
{
break;
}else if (key == 's')
{
std::fstream ofile("481_1280_gray.bin", std::ios::out | std::ios::binary);
ofile.write(reinterpret_cast<char*>(frame.data), frame.total() * frame.elemSize());
ofile.close();
std::cout << "file saved to" << std::filesystem::current_path().string() + "\\481_1280_gray.bin" << std::endl;
}
}
}
}
camera.stopCapture();
// Close the camera.
camera.close();
}