Skip to content

Commit 3038e1e

Browse files
feat: add object to vector
1 parent 6605baa commit 3038e1e

File tree

5 files changed

+51
-0
lines changed

5 files changed

+51
-0
lines changed

cpp/FOCV_Object.cpp

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -366,3 +366,35 @@ jsi::Object FOCV_Object::copyObjectFromVector(jsi::Runtime& runtime, const jsi::
366366

367367
return value;
368368
}
369+
370+
void FOCV_Object::addObjectToVector(jsi::Runtime& runtime, const jsi::Value* arguments, size_t count) {
371+
std::string createdId;
372+
373+
jsi::Object value(runtime);
374+
std::string objectType = FOCV_JsiObject::type_from_wrap(runtime, arguments[0]);
375+
std::string vectorId = FOCV_JsiObject::id_from_wrap(runtime, arguments[0]);
376+
std::string objectId = FOCV_JsiObject::id_from_wrap(runtime, arguments[1]);
377+
378+
switch(hashString(objectType.c_str(), objectType.size())) {
379+
case hashString("mat_vector", 10): {
380+
auto array = *FOCV_Storage::get<std::vector<cv::Mat>>(vectorId);
381+
auto object = *FOCV_Storage::get<cv::Mat>(objectId);
382+
array.push_back(object);
383+
} break;
384+
case hashString("rect_vector", 11): {
385+
auto array = *FOCV_Storage::get<std::vector<cv::Rect>>(vectorId);
386+
auto object = *FOCV_Storage::get<cv::Rect>(objectId);
387+
array.push_back(object);
388+
} break;
389+
case hashString("point_vector", 12): {
390+
auto array = *FOCV_Storage::get<std::vector<cv::Point>>(vectorId);
391+
auto object = *FOCV_Storage::get<cv::Point>(objectId);
392+
array.push_back(object);
393+
} break;
394+
case hashString("point_vector_vector", 19): {
395+
auto array = *FOCV_Storage::get<std::vector<std::vector<cv::Point>>>(vectorId);
396+
auto object = *FOCV_Storage::get<std::vector<cv::Point>>(objectId);
397+
array.push_back(object);
398+
} break;
399+
}
400+
}

cpp/FOCV_Object.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ class FOCV_Object {
3333
static jsi::Object create(jsi::Runtime& runtime, const jsi::Value* arguments, size_t count);
3434
static jsi::Object convertToJSI(jsi::Runtime& runtime, const jsi::Value* arguments, size_t count);
3535
static jsi::Object copyObjectFromVector(jsi::Runtime& runtime, const jsi::Value* arguments, size_t count);
36+
static void addObjectToVector(jsi::Runtime& runtime, const jsi::Value* arguments, size_t count);
3637
};
3738

3839
#endif /* FOCV_Object_hpp */

cpp/react-native-fast-opencv.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,17 @@ jsi::Value OpenCVPlugin::get(jsi::Runtime& runtime, const jsi::PropNameID& propN
233233
return FOCV_Object::copyObjectFromVector(runtime, arguments, count);
234234
});
235235
}
236+
else if (propName == "addObjectToVector") {
237+
return jsi::Function::createFromHostFunction(
238+
runtime, jsi::PropNameID::forAscii(runtime, "addObjectToVector"), 1,
239+
[=](jsi::Runtime& runtime, const jsi::Value& thisValue, const jsi::Value* arguments,
240+
size_t count) -> jsi::Value {
241+
242+
FOCV_Object::addObjectToVector(runtime, arguments, count);
243+
244+
return jsi::Value(true);
245+
});
246+
}
236247
else if (propName == "invoke") {
237248
return jsi::Function::createFromHostFunction(
238249
runtime, jsi::PropNameID::forAscii(runtime, "invoke"), 1,

src/objects/Objects.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,4 +144,9 @@ export type Objects = {
144144
itemIndex: number
145145
): PointVector;
146146
copyObjectFromVector(vector: RectVector, itemIndex: number): Rect;
147+
148+
addObjectToVector(vector: MatVector, object: Mat): void;
149+
addObjectToVector(vector: PointVector, object: Point): void;
150+
addObjectToVector(vector: RectVector, object: Rect): void;
151+
addObjectToVector(vector: PointVectorOfVectors, object: PointVector): void;
147152
};

src/utils/UtilsFunctions.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,4 +67,6 @@ export type UtilsFunctions = {
6767
channels: number;
6868
buffer: BufferType[T];
6969
};
70+
71+
inpaint(src: Mat, mask: Mat, dst: Mat, radius: number, flag: unknown): void;
7072
};

0 commit comments

Comments
 (0)