-
Notifications
You must be signed in to change notification settings - Fork 0
/
get_image.cpp
45 lines (39 loc) · 994 Bytes
/
get_image.cpp
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
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
#include <thread>
#include <queue>
#include <chrono>
#include <iostream>
#include <fstream>
#include <cstdlib>
#include <filesystem>
#include <future>
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/imgproc/imgproc.hpp"
#include "opencv2/core/core.hpp"
int main(int argc, char* argv[])
{
bool capture_successful = false;
cv::Mat cv_img(1920, 1080, CV_8UC3);
std::string filename = "/tmp/test.png";
cv::VideoCapture vid_cap(0);
sleep(1);
try
{
capture_successful = vid_cap.read(cv_img);
if (capture_successful) {
std::cout << "writing image " << filename << std::endl;
cv::imwrite(filename, cv_img);
}
else
{
std::cout << "capture unsuccesful" << std::endl;
}
}
catch (const std::exception& e) // reference to the base of a polymorphic object
{
throw e;
}
vid_cap.release();
}