7
7
8
8
#include " FOCV_Function.hpp"
9
9
#include " FOCV_Storage.hpp"
10
+ #include " FOCV_Ids.hpp"
11
+ #include < FOCV_JsiObject.hpp>
10
12
#include < opencv2/opencv.hpp>
11
13
12
14
constexpr uint64_t hashString (const char * str, size_t length) {
@@ -21,47 +23,43 @@ constexpr uint64_t hashString(const char* str, size_t length) {
21
23
return hash;
22
24
}
23
25
24
- std::string getId (jsi::Object argument) {
25
- return argument.asString (runtime).utf8 (runtime)
26
+ std::string getId (jsi::Runtime& runtime, const jsi::Value& argument) {
27
+ return argument.asString (runtime).utf8 (runtime);
26
28
}
27
29
28
30
jsi::Object FOCV_Function::invoke (jsi::Runtime& runtime, const jsi::Value* arguments) {
29
31
jsi::Object value (runtime);
30
- std::string functionName = getId (arguments[0 ]);
31
32
32
- switch (hashString (objectType.c_str (), objectType.size ())) {
33
+ std::string functionName = getId (runtime, arguments[0 ]);
34
+
35
+ switch (hashString (functionName.c_str (), functionName.size ())) {
33
36
case hashString (" cvtColor" , 8 ): {
34
- cv::Mat src = FOCV_Storage::get<cv::Mat>(getId ( arguments[1 ]));
35
- cv::Mat dst = FOCV_Storage::get<cv::Mat>(getId ( arguments[2 ]));
37
+ cv::Mat src = FOCV_Storage::get<cv::Mat>(FOCV_JsiObject::id_from_wrap (runtime, arguments[1 ]));
38
+ cv::Mat dst = FOCV_Storage::get<cv::Mat>(FOCV_JsiObject::id_from_wrap (runtime, arguments[2 ]));
36
39
cv::cvtColor (src, dst, arguments[3 ].getNumber ());
37
- FOCV_Storage::save (getId ( arguments[2 ]), dst) );
40
+ FOCV_Storage::save (FOCV_JsiObject::id_from_wrap (runtime, arguments[2 ]), dst);
38
41
} break ;
39
42
case hashString (" inRange" , 7 ): {
40
- cv::Mat src = FOCV_Storage::get<cv::Mat>(getId (arguments[0 ]));
41
- cv::Vec3b src = FOCV_Storage::get<cv::Vec3b>(getId (arguments[1 ]));
42
- cv::Vec3b src = FOCV_Storage::get<cv::Vec3b>(getId (arguments[2 ]));
43
- cv::Mat dst = FOCV_Storage::get<cv::Mat>(getId (arguments[3 ]));
43
+ cv::Mat src = FOCV_Storage::get<cv::Mat>(FOCV_JsiObject::id_from_wrap (runtime, arguments[1 ]));
44
+ std::string s = FOCV_JsiObject::id_from_wrap (runtime, arguments[2 ]);
45
+ std::string id = FOCV_JsiObject::type_from_wrap (runtime, arguments[2 ]);
46
+ cv::Vec3b lowerBound = FOCV_Storage::get<cv::Vec3b>(FOCV_JsiObject::id_from_wrap (runtime, arguments[2 ]));
47
+ cv::Vec3b upperBound = FOCV_Storage::get<cv::Vec3b>(FOCV_JsiObject::id_from_wrap (runtime, arguments[3 ]));
48
+ cv::Mat dst = FOCV_Storage::get<cv::Mat>(FOCV_JsiObject::id_from_wrap (runtime, arguments[4 ]));
44
49
cv::inRange (src, lowerBound, upperBound, dst);
45
- FOCV_Storage::save (getId ( arguments[3 ]), dst);
50
+ FOCV_Storage::save (FOCV_JsiObject::id_from_wrap (runtime, arguments[4 ]), dst);
46
51
} break ;
47
52
case hashString (" split" , 5 ): {
48
- cv::Mat src = FOCV_Storage::get<cv::Mat>(getId ( arguments[0 ]));
49
- std::vector<cv::Mat> dst = FOCV_Storage::get<std::vector<cv::Mat>>(getId ( arguments[1 ]));
53
+ cv::Mat src = FOCV_Storage::get<cv::Mat>(FOCV_JsiObject::id_from_wrap (runtime, arguments[1 ]));
54
+ std::vector<cv::Mat> dst = FOCV_Storage::get<std::vector<cv::Mat>>(FOCV_JsiObject::id_from_wrap (runtime, arguments[2 ]));
50
55
cv::split (src, dst);
51
-
52
- auto ids = FOCV_Ids ();
53
-
54
- for (size_t i = 0 ; i < dst.size (); i++) {
55
- auto id = FOCV_Mat::saveMat (dst.at (i));
56
- ids.push (id);
57
- }
58
- value.setProperty (runtime, " array" , ids.toJsiArray (runtime));
56
+ FOCV_Storage::save (FOCV_JsiObject::id_from_wrap (runtime, arguments[2 ]), dst);
59
57
} break ;
60
58
case hashString (" findContours" , 12 ): {
61
- cv::Mat src = FOCV_Storage::get<cv::Mat>(getId ( arguments[0 ]));
59
+ cv::Mat src = FOCV_Storage::get<cv::Mat>(FOCV_JsiObject::id_from_wrap (runtime, arguments[1 ]));
62
60
std::vector<std::vector<cv::Point>> contours;
63
61
64
- cv::findContours (src, contours, arguments[1 ].getNumber (), arguments[2 ].getNumber ());
62
+ cv::findContours (src, contours, arguments[2 ].getNumber (), arguments[3 ].getNumber ());
65
63
66
64
auto ids = FOCV_Ids ();
67
65
@@ -70,18 +68,22 @@ jsi::Object FOCV_Function::invoke(jsi::Runtime& runtime, const jsi::Value* argum
70
68
ids.push (id);
71
69
}
72
70
73
- value. setProperty (runtime, " array " , ids. toJsiArray (runtime) );
71
+ return ids. toJsiArray (runtime, " point_vector " );
74
72
} break ;
75
73
case hashString (" contourArea" , 11 ): {
76
- std::vector<cv::Point> src = FOCV_Storage::get<std::vector<cv::Point>>(getId ( arguments[0 ]));
74
+ std::vector<cv::Point> src = FOCV_Storage::get<std::vector<cv::Point>>(FOCV_JsiObject::id_from_wrap (runtime, arguments[1 ]));
77
75
78
- value.setProperty (runtime, " area" , contourArea (src, arguments[1 ].getBool ()));
76
+ value.setProperty (runtime, " area" , contourArea (src, arguments[2 ].getBool ()));
77
+ } break ;
78
+ case hashString (" boundingRect" , 12 ): {
79
+ std::vector<cv::Point> src = FOCV_Storage::get<std::vector<cv::Point>>(FOCV_JsiObject::id_from_wrap (runtime, arguments[1 ]));
80
+ cv::Rect rect = cv::boundingRect (src);
81
+
82
+ std::string id = FOCV_Storage::save (rect);
83
+
84
+ return FOCV_JsiObject::wrap (runtime, " rect" , id);
79
85
} break ;
80
-
81
86
}
82
87
83
- jsi::Object object (runtime);
84
- object.setProperty (runtime, " value" , value);
85
-
86
- return object;
88
+ return value;
87
89
}
0 commit comments