-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmain.cpp
71 lines (55 loc) · 1.76 KB
/
main.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
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
#include <opencv2/opencv.hpp>
#include "threadsafe_queue.hpp"
#include "include/ScreenCaptureApi.h"
#include <thread>
#include <chrono>
#include <spdlog/spdlog.h>
static ScreenCaptureApi *api = nullptr;
threadsafe_queue<cv::Mat> imgQueue;
class MySpi : public ScreenCaptureSpi
{
void onStreamRtn(unsigned char *data, int length) override
{
auto mat = cv::imdecode(std::vector<unsigned char>(data, data+length), cv::IMREAD_COLOR);
imgQueue.push(mat);
}
void onImageRtn(unsigned char *data, int length) override
{
auto mat = cv::imdecode(std::vector<unsigned char>(data, data + length), cv::IMREAD_COLOR);
cv::imwrite("screen.jpg", mat);
}
void onConnectRspRtn(int imgWidth, int imgHeight) override
{
spdlog::info("[MySpi] onConnectRspRtn\n imgWidth: {}\n imgHeight: {}", imgWidth, imgHeight);
}
void onStartQueryScreenStreamRspRtn(const char *msg) override
{
spdlog::info("[MySpi] onStartQueryScreenStreamRspRtn\n msg: {}", msg);
}
void onStopQueryScreenStreamRspRtn(const char *msg) override
{
spdlog::info("[MySpi] onStopQueryScreenStreamRspRtn\n msg: {}", msg);
}
void onDisConnectRspRtn(const char *msg) override
{
spdlog::info("[MySpi] onDisConnectRspRtn\n msg: {}", msg);
}
} mySpi;
int main()
{
api = ScreenCaptureApi::create(mySpi);
api->connect("127.0.0.1", 8080);
api->queryScreenImage();
api->startQueryScreenStream();
while (true) {
auto img = imgQueue.wait_and_pop();
cv::imshow("Screen", *img);
if (cv::waitKey(1) == 'q') {
break;
}
}
api->stopQueryScreenStream();
std::this_thread::sleep_for(std::chrono::seconds(1));
api->disconnect();
return 0;
}