@@ -25,47 +25,55 @@ constexpr uint64_t hashString(const char* str, size_t length) {
25
25
}
26
26
27
27
jsi::Object FOCV_Object::create (jsi::Runtime& runtime, const jsi::Value* arguments) {
28
- std::any object ;
28
+ std::string id = " " ;
29
29
std::string objectType = arguments[0 ].asString (runtime).utf8 (runtime);
30
30
31
31
switch (hashString (objectType.c_str (), objectType.size ())) {
32
32
case hashString (" mat" , 3 ): {
33
33
int rows = arguments[1 ].asNumber ();
34
34
int cols = arguments[2 ].asNumber ();
35
35
int type = arguments[3 ].asNumber ();
36
- object = cv::Mat (rows, cols, type);
36
+ cv::Mat object (rows, cols, type);
37
+ id = FOCV_Storage::save (object);
37
38
} break ;
38
39
case hashString (" mat_vector" , 10 ): {
39
- object = std::vector<cv::Mat>();
40
+ std::vector<cv::Mat> object;
41
+ id = FOCV_Storage::save (object);
40
42
} break ;
41
43
case hashString (" rect" , 4 ): {
42
44
int x = arguments[1 ].asNumber ();
43
45
int y = arguments[2 ].asNumber ();
44
46
int width = arguments[3 ].asNumber ();
45
47
int height = arguments[4 ].asNumber ();
46
- object = cv::Rect (x, y, width, height);
48
+ cv::Rect object (x, y, width, height);
49
+ id = FOCV_Storage::save (object);
47
50
} break ;
48
51
case hashString (" rect_vector" , 11 ): {
49
- object = std::vector<cv::Rect >();
52
+ std::vector<cv::Rect > object;
53
+ id = FOCV_Storage::save (object);
50
54
} break ;
51
55
case hashString (" point" , 5 ): {
52
56
int x = arguments[1 ].asNumber ();
53
57
int y = arguments[2 ].asNumber ();
54
- object = cv::Point (x, y);
58
+ cv::Point object (x, y);
59
+ id = FOCV_Storage::save (object);
55
60
} break ;
56
61
case hashString (" point_vector" , 12 ): {
57
- object = std::vector<cv::Point >();
62
+ std::vector<cv::Point > object;
63
+ id = FOCV_Storage::save (object);
58
64
} break ;
59
65
case hashString (" size" , 4 ): {
60
66
int width = arguments[1 ].asNumber ();
61
67
int height = arguments[2 ].asNumber ();
62
- object = cv::Size (width, height);
68
+ cv::Size object (width, height);
69
+ id = FOCV_Storage::save (object);
63
70
} break ;
64
71
case hashString (" vec3b" , 5 ): {
65
72
int a = arguments[1 ].asNumber ();
66
73
int b = arguments[2 ].asNumber ();
67
74
int c = arguments[3 ].asNumber ();
68
- object = cv::Vec3b (a, b, c);
75
+ cv::Vec3b object (a, b, c);
76
+ id = FOCV_Storage::save (object);
69
77
} break ;
70
78
case hashString (" scalar" , 6 ): {
71
79
if (arguments[4 ].isNumber ()) {
@@ -74,16 +82,19 @@ jsi::Object FOCV_Object::create(jsi::Runtime& runtime, const jsi::Value* argumen
74
82
int c = arguments[3 ].asNumber ();
75
83
int d = arguments[3 ].asNumber ();
76
84
77
- object = cv::Scalar (a, b, c, d);
85
+ cv::Scalar object (a, b, c, d);
86
+ id = FOCV_Storage::save (object);
78
87
} else if (arguments[3 ].isNumber ()) {
79
88
int a = arguments[1 ].asNumber ();
80
89
int b = arguments[2 ].asNumber ();
81
90
int c = arguments[3 ].asNumber ();
82
91
83
- object = cv::Scalar (a, b, c);
92
+ cv::Scalar object (a, b, c);
93
+ id = FOCV_Storage::save (object);
84
94
} else {
85
95
int a = arguments[1 ].asNumber ();
86
- object = cv::Scalar (a);
96
+ cv::Scalar object (a);
97
+ id = FOCV_Storage::save (object);
87
98
}
88
99
} break ;
89
100
case hashString (" rotated_rect" , 12 ): {
@@ -93,11 +104,12 @@ jsi::Object FOCV_Object::create(jsi::Runtime& runtime, const jsi::Value* argumen
93
104
int height = arguments[4 ].asNumber ();
94
105
int angle = arguments[5 ].asNumber ();
95
106
96
- object = cv::RotatedRect (cv::Point (x,y), cv::Size (width, height), angle);
107
+ cv::RotatedRect object (cv::Point (x,y), cv::Size (width, height), angle);
108
+ id = FOCV_Storage::save (object);
97
109
} break ;
98
110
}
99
111
100
- std::string id = FOCV_Storage::save (object);
112
+
101
113
return FOCV_JsiObject::wrap (runtime, objectType, id);
102
114
}
103
115
@@ -108,15 +120,15 @@ jsi::Object FOCV_Object::convertToJSI(jsi::Runtime& runtime, const jsi::Value* a
108
120
109
121
switch (hashString (objectType.c_str (), objectType.size ())) {
110
122
case hashString (" mat" , 3 ): {
111
- cv::Mat mat = FOCV_Storage::get<cv::Mat>(id);
123
+ auto mat = * FOCV_Storage::get<cv::Mat>(id);
112
124
113
125
value.setProperty (runtime, " base64" , jsi::String::createFromUtf8 (runtime, ImageConverter::mat2str (mat)));
114
126
value.setProperty (runtime, " size" , jsi::Value (mat.size ));
115
127
value.setProperty (runtime, " cols" , jsi::Value (mat.cols ));
116
128
value.setProperty (runtime, " rows" , jsi::Value (mat.rows ));
117
129
} break ;
118
130
case hashString (" mat_vector" , 10 ): {
119
- std::vector<cv::Mat> mats = FOCV_Storage::get<std::vector<cv::Mat>>(id);
131
+ auto mats = * FOCV_Storage::get<std::vector<cv::Mat>>(id);
120
132
121
133
auto array = jsi::Array (runtime, mats.size ());
122
134
@@ -132,15 +144,15 @@ jsi::Object FOCV_Object::convertToJSI(jsi::Runtime& runtime, const jsi::Value* a
132
144
value.setProperty (runtime, " array" , array);
133
145
} break ;
134
146
case hashString (" rect" , 4 ): {
135
- cv:: Rect rect = FOCV_Storage::get<cv::Rect >(id);
147
+ auto rect = * FOCV_Storage::get<cv::Rect >(id);
136
148
137
149
value.setProperty (runtime, " x" , jsi::Value (rect.x ));
138
150
value.setProperty (runtime, " y" , jsi::Value (rect.y ));
139
151
value.setProperty (runtime, " width" , jsi::Value (rect.width ));
140
152
value.setProperty (runtime, " height" , jsi::Value (rect.height ));
141
153
} break ;
142
154
case hashString (" rect_vector" , 11 ): {
143
- std::vector<cv:: Rect > rects = FOCV_Storage::get<std::vector<cv::Rect >>(id);
155
+ auto rects = * FOCV_Storage::get<std::vector<cv::Rect >>(id);
144
156
145
157
auto array = jsi::Array (runtime, rects.size ());
146
158
@@ -157,13 +169,13 @@ jsi::Object FOCV_Object::convertToJSI(jsi::Runtime& runtime, const jsi::Value* a
157
169
value.setProperty (runtime, " array" , array);
158
170
} break ;
159
171
case hashString (" point" , 5 ): {
160
- cv:: Point point = FOCV_Storage::get<cv::Point >(id);
172
+ auto point = * FOCV_Storage::get<cv::Point >(id);
161
173
162
174
value.setProperty (runtime, " x" , jsi::Value (point.x ));
163
175
value.setProperty (runtime, " y" , jsi::Value (point.y ));
164
176
} break ;
165
177
case hashString (" point_vector" , 12 ): {
166
- std::vector<cv:: Point > points = FOCV_Storage::get<std::vector<cv::Point >>(id);
178
+ auto points = * FOCV_Storage::get<std::vector<cv::Point >>(id);
167
179
168
180
auto array = jsi::Array (runtime, points.size ());
169
181
@@ -178,28 +190,28 @@ jsi::Object FOCV_Object::convertToJSI(jsi::Runtime& runtime, const jsi::Value* a
178
190
value.setProperty (runtime, " array" , array);
179
191
} break ;
180
192
case hashString (" size" , 4 ): {
181
- cv:: Size size = FOCV_Storage::get<cv::Size >(id);
193
+ auto size = * FOCV_Storage::get<cv::Size >(id);
182
194
183
195
value.setProperty (runtime, " width" , jsi::Value (size.width ));
184
196
value.setProperty (runtime, " height" , jsi::Value (size.height ));
185
197
} break ;
186
198
case hashString (" vec3b" , 5 ): {
187
- cv::Vec3b vec = FOCV_Storage::get<cv::Vec3b>(id);
199
+ auto vec = * FOCV_Storage::get<cv::Vec3b>(id);
188
200
189
201
value.setProperty (runtime, " a" , jsi::Value (vec.val [0 ]));
190
202
value.setProperty (runtime, " b" , jsi::Value (vec.val [1 ]));
191
203
value.setProperty (runtime, " c" , jsi::Value (vec.val [2 ]));
192
204
} break ;
193
205
case hashString (" scalar" , 6 ): {
194
- cv::Scalar scalar = FOCV_Storage::get<cv::Scalar>(id);
206
+ auto scalar = * FOCV_Storage::get<cv::Scalar>(id);
195
207
196
208
value.setProperty (runtime, " a" , jsi::Value (scalar.val [0 ]));
197
209
value.setProperty (runtime, " b" , jsi::Value (scalar.val [1 ]));
198
210
value.setProperty (runtime, " c" , jsi::Value (scalar.val [2 ]));
199
211
value.setProperty (runtime, " d" , jsi::Value (scalar.val [3 ]));
200
212
} break ;
201
213
case hashString (" rotated_rect" , 12 ): {
202
- cv::RotatedRect rect = FOCV_Storage::get<cv::RotatedRect>(id);
214
+ auto rect = * FOCV_Storage::get<cv::RotatedRect>(id);
203
215
204
216
value.setProperty (runtime, " centerX" , jsi::Value (rect.center .x ));
205
217
value.setProperty (runtime, " centerY" , jsi::Value (rect.center .y ));
@@ -222,19 +234,19 @@ jsi::Object FOCV_Object::copyObjectFromVector(jsi::Runtime& runtime, const jsi::
222
234
223
235
switch (hashString (objectType.c_str (), objectType.size ())) {
224
236
case hashString (" mat_vector" , 10 ): {
225
- std::vector<cv::Mat> array = FOCV_Storage::get<std::vector<cv::Mat>>(vectorId);
237
+ auto array = * FOCV_Storage::get<std::vector<cv::Mat>>(vectorId);
226
238
cv::Mat mat = array.at (index );
227
239
createdId = FOCV_Storage::save (mat);
228
240
return FOCV_JsiObject::wrap (runtime, " mat" , createdId);
229
241
} break ;
230
242
case hashString (" rect_vector" , 11 ): {
231
- std::vector<cv:: Rect > array = FOCV_Storage::get<std::vector<cv::Rect >>(vectorId);
243
+ auto array = * FOCV_Storage::get<std::vector<cv::Rect >>(vectorId);
232
244
cv::Rect rect = array.at (index );
233
245
createdId = FOCV_Storage::save (rect);
234
246
return FOCV_JsiObject::wrap (runtime, " rect" , createdId);
235
247
} break ;
236
248
case hashString (" point_vector" , 12 ): {
237
- std::vector<cv:: Point > array = FOCV_Storage::get<std::vector<cv::Point >>(vectorId);
249
+ auto array = * FOCV_Storage::get<std::vector<cv::Point >>(vectorId);
238
250
cv::Point point = array.at (index );
239
251
createdId = FOCV_Storage::save (point);
240
252
return FOCV_JsiObject::wrap (runtime, " point" , createdId);
0 commit comments