|
| 1 | +// |
| 2 | +// FOCV_Rect.cpp |
| 3 | +// react-native-fast-opencv |
| 4 | +// |
| 5 | +// Created by Łukasz Kurant on 04/08/2024. |
| 6 | +// |
| 7 | + |
| 8 | +#include "FOCV_Rect.hpp" |
| 9 | +#include <boost/uuid/uuid.hpp> |
| 10 | +#include <boost/uuid/uuid_generators.hpp> |
| 11 | +#include <boost/uuid/uuid_io.hpp> |
| 12 | +#include <opencv2/opencv.hpp> |
| 13 | +#include <jsi/jsilib.h> |
| 14 | +#include <jsi/jsi.h> |
| 15 | + |
| 16 | +using namespace facebook; |
| 17 | + |
| 18 | +std::unordered_map<std::string, cv::Rect> FOCV_Rect::_rects = std::unordered_map<std::string, cv::Rect>(); |
| 19 | + |
| 20 | +void FOCV_Rect::clear() { |
| 21 | + _rects.clear(); |
| 22 | +} |
| 23 | + |
| 24 | +std::string FOCV_Rect::saveRect(cv::Rect rect) { |
| 25 | + boost::uuids::uuid uuid = boost::uuids::random_generator()(); |
| 26 | + std::string tmp = boost::uuids::to_string(uuid); |
| 27 | + |
| 28 | + _rects.insert_or_assign(tmp, rect); |
| 29 | + |
| 30 | + return tmp; |
| 31 | +} |
| 32 | + |
| 33 | +std::string FOCV_Rect::saveRect(std::string name, cv::Rect rect) { |
| 34 | + _rects.insert_or_assign(name, rect); |
| 35 | + |
| 36 | + return name; |
| 37 | +} |
| 38 | + |
| 39 | +cv::Rect FOCV_Rect::getRect(std::string id) { |
| 40 | + // Validation |
| 41 | + return _rects.at(id); |
| 42 | +} |
| 43 | + |
| 44 | +jsi::Object FOCV_Rect::getJsiRect(std::string id, facebook::jsi::Runtime& runtime) { |
| 45 | + cv::Rect rect = _rects.at(id); |
| 46 | + jsi::Object jsiRect = jsi::Object(runtime); |
| 47 | + jsiRect.setProperty(runtime, "x", jsi::Value(rect.x)); |
| 48 | + jsiRect.setProperty(runtime, "y", jsi::Value(rect.y)); |
| 49 | + jsiRect.setProperty(runtime, "width", jsi::Value(rect.width)); |
| 50 | + jsiRect.setProperty(runtime, "height", jsi::Value(rect.height)); |
| 51 | + |
| 52 | + return jsiRect; |
| 53 | +} |
0 commit comments