EntryPointNative.cpp
5.06 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
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
#include "EntryPointNative.h"
#include <opencv2/opencv.hpp>
#include "SkeletonCNN2D.hpp"
//
#include "Manomotion.h"
#include "AdapterIOSNative.hpp"
#include "Utils.hpp"
#include "opencv2/opencv.hpp"
#include "ManoTimer.h"
#include <sys/stat.h>
#include <memory>
#include "AdapterBase.h"
#include "IOSUtils.hpp"
std::unique_ptr<AdapterIOSNative> adapter_ios = nullptr;
LicenseStatus licenseStatus;
ManoSettings settings;
ManoTimer mtimer;
Mat mr_frame;
cv::Mat working_frame;
DeviceInformation deviceInfo;
bool save_images = false;
const char *tag_ = "EntryPointNative";
void mlog(string msg) {
Utils::Logv(tag_, "%s", msg.c_str());
}
void packageAnswer(HandInfo hand_info, Session session_obj, Session session) {
cout << "inside packageAnswer " << endl;
}
/*
* Used to intialise the license status
*/
void initLicenseStatus(LicenseStatus * lStatus,ManoSettings mano_settings,DeviceInformation deviceInformation) {
cout << "inside initLicenseStatus " << endl;
IOSUtils::setIsPowerSaveMode(deviceInformation.is_power_save_mode_on);
adapter_ios = std::make_unique<AdapterIOSNative>(); // new
adapter_ios->initialise(deviceInformation.path, deviceInformation.deviceId, deviceInformation.bundleId, deviceInformation.deviceModel, deviceInformation.deviceBrand,deviceInformation.filepath);
cout << "from initLicenseStatus " << deviceInformation.path << " " << deviceInformation.deviceId << " " << deviceInformation.bundleId << " " << deviceInformation.deviceModel << " " << deviceInformation.deviceBrand << endl;
settings = IOSUtils::getManoSettings(mano_settings);
LicenseStatus ls = adapter_ios->init(settings);
*lStatus = IOSUtils::createLicenseStatus(ls);
bool is_power_save_mode_on = IOSUtils::isPowerSaveMode();
#ifdef _DEBUG_ON_
Utils::Logv(tag_, "PowerSave Mode %d", is_power_save_mode_on);
#endif
}
int frame_count = 771;
/*
* Used to save frames into memory
*/
void saveImage(Mat mat, double timestamp,string uri1) {
#ifdef __ANDROID__
string uri = "/storage/emulated/0/ManoMotionDebug/Right_hand";
#endif
#ifdef __IOS__
string uri = uri1;
#endif
int nError = 0;
const char *str = uri.c_str();
cout << "saveImage str " << str << endl;
struct stat st = {0};
int res = stat(str, &st);
if (res == -1) {
nError = mkdir(str, 0777);
mlog("ManomotionDirectory for debugging in path " + uri + " created");
}
string png = ".png";
uri += "/";
//uri += to_string(timestamp);
uri += "image (" + to_string(frame_count)+ ")";
uri += png;
cout << endl << "saveImage final URL " << uri << endl;
imwrite(uri, mat);
}
/*
* Used to intialise save_images flag
*/
void saveImages(bool val) {
cout << "inside saveImages" << endl;
save_images = val;
}
/*
* Used to pass the MAT frame to the dynamic library and take output of the procesed frame
*/
void process(uchar * data, int width, int height,Session session_obj,HandInfo *hand_info0) {
//session_obj.orientation = session_obj.orientation == 1 ? 4 : session_obj.orientation ;
mr_frame = Mat(height,width, CV_8UC4, Scalar(255, 255, 0, 0));
setResFrameArray(data, width, height, (uchar *)mr_frame.data);
#ifdef _DEBUG_ON_
double end_pre_process = mtimer.getCurrentTimeStamp();
#endif
try {
Utils::setPath(adapter_ios->filepath);
adapter_ios->processFrame(hand_info0, &session_obj);
} catch (char const *error) {
#ifdef _DEBUG_ON_
Utils::Logv(tag_, "%s", error);
#endif
return;
}
#ifdef _DEBUG_ON_
double end_processFrame = mtimer.getCurrentTimeStamp();
int time_end_processFrame = int(end_processFrame - end_pre_process);
Utils::Logv(tag_, "***Time for frame %d", time_end_processFrame);
#endif
frame_count++;
//saveImage(adapter_ios->working_frame, end_processFrame, adapter_ios->filepath);
}
/*
* Used to set frame array & MR frame array
*/
void setResFrameArray(uchar * data, int width, int height, uchar * mr_frame_data) {
adapter_ios->setResolution(width, height);
adapter_ios->setFrameArray(data); //required to run
adapter_ios->setMRFrameArray(mr_frame_data);
}
/*
* Used to set resolution of the MAT frame
*/
void setResolution(int width, int height) {
adapter_ios->setResolution(width, height);
}
void cleanUp() {
cout << "inside cleanUp" << endl;
}
int get_license_status_days_left() {
return licenseStatus.days_left;
}
float get_license_status_version() {
return licenseStatus.version;
}
LicenseAnswer get_license_status_license_answer() {
return licenseStatus.license_answer;
}
int get_license_status_machines_left() {
return licenseStatus.machines_left;
}
/*
cout << "Debug handside hand_side " << hand_info0->gesture_info.hand_side << endl;
cout << "Debug handside is_right " << hand_info0->gesture_info.is_right << endl;
cout << "Debug handside mano_class " << hand_info0->gesture_info.mano_class << endl;
cout << "Debug handside mano_gesture_continuous " << hand_info0->gesture_info.mano_gesture_continuous << endl;
cout << "Debug handside mano_gesture_trigger " << hand_info0->gesture_info.mano_gesture_trigger << endl;
*/