-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmain.cpp
220 lines (213 loc) · 7.4 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
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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
#include <opencv2/opencv.hpp>
#include <iostream>
#include "BAAS.h"
#include "httplib.h"
#pragma comment(lib, "ws2_32.lib")
#include <BAASExternalIPC.h>
using namespace cv;
using namespace std;
using json = nlohmann::json;
#include <device/BAASLdopengl.h>
#include <benchmark/benchmark.h>
int main(int argc, char **argv) {
system("chcp 65001");
string config_name = "default_config";
cv::Mat img;
try{
cout <<shared_memory_exists("test") << endl;
// img = cv::imread("game_update.png");
auto sm = (Shared_Memory*)get_shared_memory("test", 1280*720*3, img.data);
auto t1 = std::chrono::high_resolution_clock::now();
img = cv::Mat(720, 1280, CV_8UC3, sm->get_data());
// cv::imshow("img", img);
// cv::waitKey(0);
//// Shared_Memory* sm = new Shared_Memory("test", 1280*720*3);
// auto t1 = std::chrono::high_resolution_clock::now();
// img = cv::Mat(720, 1280, CV_8UC3, sm->get_data());
//
// cout << "time: " << std::chrono::duration_cast<std::chrono::microseconds>(std::chrono::high_resolution_clock::now() - t1).count() << "us" << endl;
// cv::imshow("img", img);
// cv::waitKey(0);
// system("pause");
// img = cv::Mat(720, 1280, CV_8UC3, get_shared_memory_data(sm));
// cout << "time: " << BAASUtil::getCurrentTimeMS() - t1 << endl;
// cv::imshow("img", img);
// cv::waitKey(0);
// return 0;
// system("pause");
init_globals();
BAAS baas(config_name);
BAASConfig config;
// img = cv::imread("1.png");
global_setting->show();
// BAASConnection* conn = baas.get_connection();
// baas.update_screenshot_array();
// baas.get_latest_screenshot(img);
// cv::imshow("img", img);
// cv::waitKey(0);
// cv::imwrite("1.png", img);
// cv::imshow("img", img);
// img = cv::imread("NUM.png");
// cv::waitKey(0);
// string name = "rank-down";
// BAASRectangle region = {100, 291, 650, 363};
// BAASDevelopUtils::extract_image_rgb_range(img, name, region, {200, 200, 200}, {255, 255, 255});
baas.solve("restart");
baas.solve("collect_activity_fee");
baas.solve("mail");
baas.solve("work");
baas.solve("competition");
baas.solve("collect_reward");
// cv::imshow("img", img);
// cv::waitKey(0);
baas_ocr->init("zh-cn");
// baas_ocr->init("zh-tw");
// baas_ocr->init("en-us");
// baas_ocr->init("ja-jp");
// baas_ocr->init("ko-kr");
// baas_ocr->init("ru-ru");
// baas_ocr->test_ocr();
OcrResult result;
TextLine result2;
std::string a = "1234567890/";
baas.update_screenshot_array();
BAASRectangle region_ap = {345, 32, 452, 53};
baas.ocr_for_single_line("zh-cn", result2, region_ap, "AP", a);
BAASRectangle region_diamond = {549, 30, 663, 63};
baas.ocr_for_single_line("zh-cn", result2, region_diamond, "Diamond", "1234567890,");
json j;
// BAASOCR::ocrResult2json(result, j);
// cout << j.dump(4) << endl;
// cv::imshow("img", result.boxImg);
cv::waitKey(0);
// BAASUtil::stringReplace("/", "_", result2.text);
// cv::imwrite(result2.text + ".png", img);
}
// for(int i = 1; i <= 10; ++i) {
// }
// for (int i = 1; i<=10; ++i) {
// baas_ocr->ocr("en-us", img, result);
// }
// baas_ocr->ocr("en-us", img, result);
// for (int i = 1; i<=10; ++i) {
// baas.update_screenshot_array();
// baas.get_latest_screenshot(img);
// cv::imwrite(to_string(i) + ".png", img);
// imgName = to_string(i) + ".png";
//
//
// }
catch (const std::exception& e){
BAASGlobalLogger->BAASInfo(e.what());
}
return 0;
}
//
//
//
//int main() {
// system("chcp 65001");
// using namespace httplib;
// httplib::Client cli("http://localhost:1234");
//
// httplib::Params para;
//// para.emplace("name", "value");
//// auto res = cli.Get("/path", para);
// auto res = cli.Post("/path", "text", "text/plain");
//
//
// return 0;
// try {
// init_globals();
// string config_name = "default_config";
// cv::Mat img;
//
//
// BAAS baas(config_name);
// BAASConfig config;
// BAASConnection* conn = baas.get_connection();
//
//// BAASLdopengl* ldopengl = BAASLdopengl::get_instance(conn);
//// auto t1 = std::chrono::high_resolution_clock::now();
//// ldopengl->screenshot(img);
//// cout << "time: " << std::chrono::duration_cast<std::chrono::microseconds>(std::chrono::high_resolution_clock::now() - t1).count() << "us" << endl;
////
//// cv::imshow("img", img);
//// cv::waitKey(0);
//
// baas.update_screenshot_array();
// baas.get_latest_screenshot(img);
// Shared_Memory* img_mem_buf = Shared_Memory::create_shared_memory("img", img.cols*img.rows*3, img.data);
//// auto t1 = std::chrono::high_resolution_clock::now();
//// for(int i = 1; i <= 10; ++i) {
//// img_mem_buf->put_data(img.data, img.cols*img.rows*3);
//// }
//// cout << "time: " << std::chrono::duration_cast<std::chrono::microseconds>(std::chrono::high_resolution_clock::now() - t1).count() << "us" << endl;
//// system("pause");
//// return 0;
//// cout<<&img.data<<endl;
//// auto ptr = img.data;
//// cv::Mat img2 = cv::Mat(img.rows, img.cols, CV_8UC3, ptr);
//// cv::imshow("img", img2);
//// cv::waitKey(0);
//// system("pause");
//// vector<int> round_type;
//// baas.get_each_round_type(round_type);
//// cout << round_type.size() << endl;
//// std::map<int, string> round_type_map = {
//// {1, "red"},
//// {2, "blue"},
//// {3, "yellow"}
//// };
//// for(int i = 0; i < round_type.size(); i++){
//// cout << round_type_map[round_type[i]] << endl;
//// }
//// return 0;
//// while(true){
//// try{
//// baas.solve_procedure("COMPETITION_SOLVE", true);
//// }
//// catch (const std::exception& e){
//// BAASGlobalLogger->BAASInfo(e.what());
//// }
//// }
//
////
//// BAASConnection* connection = baas.get_connection();
//// connection->start_self();
//// resource->show();
//
//
//// config_name = "resource\\module_usage\\main_page.json";
//// BAASConfig procedure(config_name, baas.get_logger());
//// BAASConfig c = BAASConfig(procedure.get<json>("UI-GO-TO_main_page_home"), baas.get_logger());
//
// baas.get_logger()->hr("ISA Exited");
// }
//// resource->get(connection.get_server(), connection.get_language(), "common", "back", img);
//// cv::Mat mast;
//// BAASRectangle region = {0, 0, img.cols, img.rows};
//// BAASImageUtil::gen_not_black_region_mask(img, mast, region);
//
//
//// return 0;
//
//// }
// catch (const std::exception& e){
// BAASGlobalLogger->BAASInfo(e.what());
// }
//
// return 0;
//}
/*
// y --> 601 , 662
// x --> 847 , 932
// 946, 1038
// 1048, 1130
//
// 883, 688
// 985, 621
// 1087, 622
//
//
//*/