forked from wysaid/CameraCapture
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path1-minimal_example.cpp
More file actions
45 lines (36 loc) · 1.28 KB
/
1-minimal_example.cpp
File metadata and controls
45 lines (36 loc) · 1.28 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
/**
* @file minimal_example.cpp
* @author wysaid (this@wysaid.org)
* @brief Example for ccap.
* @date 2025-05
*
*/
#include "utils/helper.h"
#include <ccap.h>
#include <iostream>
int main() {
// Set error callback to receive error notifications
ccap::setErrorCallback([](ccap::ErrorCode errorCode, std::string_view description) {
std::cerr << "Error occurred - Code: " << static_cast<int>(errorCode)
<< ", Description: " << description << std::endl;
});
ccap::Provider cameraProvider;
cameraProvider.open(selectCamera(cameraProvider), true);
cameraProvider.start();
if (!cameraProvider.isStarted()) {
std::cerr << "Failed to start camera!" << std::endl;
return -1;
}
for (int i = 0; i < 10; ++i) {
auto frame = cameraProvider.grab(3000);
if (frame) {
printf("VideoFrame %d grabbed: width = %d, height = %d, bytes: %d, format: %s\n", (int)frame->frameIndex, frame->width,
frame->height, (int)frame->sizeInBytes, ccap::pixelFormatToString(frame->pixelFormat).data());
} else {
std::cerr << "Failed to grab frame!" << std::endl;
exit(-1);
}
}
std::cout << "Captured 10 frames, stopping..." << std::endl;
return 0;
}