Skip to content

Commit 5aacca5

Browse files
feat: initial commit
1 parent 8da07eb commit 5aacca5

33 files changed

+16722
-64
lines changed

cpp/FOCV_Ids.cpp

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
//
2+
// FOCV_Ids.cpp
3+
//
4+
// Created by Łukasz Kurant on 04/08/2024.
5+
//
6+
7+
#include "FOCV_Ids.hpp"
8+
#include <jsi/jsilib.h>
9+
#include <jsi/jsi.h>
10+
11+
using namespace facebook;
12+
13+
void FOCV_Ids::push(std::string id) {
14+
ids.push_back(id);
15+
}
16+
17+
jsi::Array FOCV_Ids::toJsiArray(jsi::Runtime& runtime) {
18+
auto result = jsi::Array(runtime, ids.size());
19+
20+
for (int i = 0; i < ids.size(); i++) {
21+
result.setValueAtIndex(runtime, i, ids[i]);
22+
}
23+
24+
return result;
25+
}

cpp/FOCV_Ids.hpp

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
//
2+
// FOCV_Ids.hpp
3+
//
4+
// Created by Łukasz Kurant on 04/08/2024.
5+
//
6+
7+
#ifndef FOCV_Ids_hpp
8+
#define FOCV_Ids_hpp
9+
10+
#include <stdio.h>
11+
#include <jsi/jsilib.h>
12+
#include <jsi/jsi.h>
13+
14+
class FOCV_Ids {
15+
private:
16+
std::vector<std::string> ids;
17+
18+
public:
19+
void push(std::string id);
20+
facebook::jsi::Array toJsiArray(facebook::jsi::Runtime& runtime);
21+
};
22+
23+
#endif /* FOCV_Ids_hpp */

cpp/FOCV_Mat.cpp

+52
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
//
2+
// FOCV_Mat.cpp
3+
//
4+
// Created by Łukasz Kurant on 03/08/2024.
5+
//
6+
7+
#include "FOCV_Mat.hpp"
8+
#include <boost/uuid/uuid.hpp>
9+
#include <boost/uuid/uuid_generators.hpp>
10+
#include <boost/uuid/uuid_io.hpp>
11+
#include <opencv2/opencv.hpp>
12+
13+
std::unordered_map<std::string, cv::Mat> FOCV_Mat::_matrices = std::unordered_map<std::string, cv::Mat>();
14+
15+
void FOCV_Mat::clear() {
16+
FOCV_Mat::_matrices.clear();
17+
}
18+
19+
std::string FOCV_Mat::saveMat(cv::Mat mat) {
20+
boost::uuids::uuid uuid = boost::uuids::random_generator()();
21+
std::string tmp = boost::uuids::to_string(uuid);
22+
23+
FOCV_Mat::_matrices.insert_or_assign(tmp, mat);
24+
25+
return tmp;
26+
}
27+
28+
std::string FOCV_Mat::saveMat(std::string name, cv::Mat mat) {
29+
FOCV_Mat::_matrices.insert_or_assign(name, mat);
30+
31+
return name;
32+
}
33+
34+
std::string FOCV_Mat::createMat() {
35+
cv::Mat mat;
36+
return saveMat(mat);
37+
}
38+
39+
std::string FOCV_Mat::createMat(std::string name) {
40+
cv::Mat mat;
41+
return saveMat(name, mat);
42+
}
43+
44+
std::string FOCV_Mat::createMat(int rows, int cols, uint8_t* buffer) {
45+
cv::Mat mat(rows, cols, CV_8UC3, buffer);
46+
return saveMat(mat);
47+
}
48+
49+
cv::Mat FOCV_Mat::getMat(std::string id) {
50+
// Validation
51+
return FOCV_Mat::_matrices.at(id);
52+
}

cpp/FOCV_Mat.hpp

+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
//
2+
// FOCV_Mat.hpp
3+
//
4+
// Created by Łukasz Kurant on 03/08/2024.
5+
//
6+
7+
#ifndef FOCV_Mat_hpp
8+
#define FOCV_Mat_hpp
9+
10+
#ifdef __cplusplus
11+
#undef YES
12+
#undef NO
13+
#include <opencv2/opencv.hpp>
14+
using namespace cv;
15+
#if __has_feature(objc_bool)
16+
#define YES __objc_yes
17+
#define NO __objc_no
18+
#else
19+
#define YES ((BOOL)1)
20+
#define NO ((BOOL)0)
21+
#endif
22+
#endif
23+
24+
#include <stdio.h>
25+
26+
class FOCV_Mat {
27+
private:
28+
static std::unordered_map<std::string, cv::Mat> _matrices;
29+
30+
public:
31+
static void clear();
32+
33+
static std::string createMat();
34+
static std::string createMat(std::string name);
35+
static std::string createMat(int rows, int cols, uint8_t* buffer);
36+
37+
static std::string saveMat(cv::Mat);
38+
static std::string saveMat(std::string name, cv::Mat);
39+
40+
static cv::Mat getMat(std::string id);
41+
};
42+
43+
#endif /* FOCV_Mat_hpp */

cpp/FOCV_PointsGroup.cpp

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
//
2+
// FOCV_PointsGroup.cpp
3+
// react-native-fast-opencv
4+
//
5+
// Created by Łukasz Kurant on 04/08/2024.
6+
//
7+
8+
#include "FOCV_PointsGroup.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+
14+
std::unordered_map<std::string, std::vector<cv::Point>> FOCV_PointsGroup::_groups = std::unordered_map<std::string, std::vector<cv::Point>>();
15+
16+
void FOCV_PointsGroup::clear() {
17+
_groups.clear();
18+
}
19+
20+
std::string FOCV_PointsGroup::saveGroup(std::vector<cv::Point> group) {
21+
boost::uuids::uuid uuid = boost::uuids::random_generator()();
22+
std::string tmp = boost::uuids::to_string(uuid);
23+
24+
_groups.insert_or_assign(tmp, group);
25+
26+
return tmp;
27+
}
28+
29+
std::string FOCV_PointsGroup::saveGroup(std::string name, std::vector<cv::Point> group) {
30+
_groups.insert_or_assign(name, group);
31+
32+
return name;
33+
}
34+
35+
std::vector<cv::Point> FOCV_PointsGroup::getGroup(std::string id) {
36+
// Validation
37+
return _groups.at(id);
38+
}

cpp/FOCV_PointsGroup.hpp

+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
//
2+
// FOCV_PointsGroup.hpp
3+
// react-native-fast-opencv
4+
//
5+
// Created by Łukasz Kurant on 04/08/2024.
6+
//
7+
8+
#ifndef FOCV_PointsGroup_hpp
9+
#define FOCV_PointsGroup_hpp
10+
11+
#ifdef __cplusplus
12+
#undef YES
13+
#undef NO
14+
#include <opencv2/opencv.hpp>
15+
using namespace cv;
16+
#if __has_feature(objc_bool)
17+
#define YES __objc_yes
18+
#define NO __objc_no
19+
#else
20+
#define YES ((BOOL)1)
21+
#define NO ((BOOL)0)
22+
#endif
23+
#endif
24+
25+
#include <stdio.h>
26+
27+
class FOCV_PointsGroup {
28+
private:
29+
static std::unordered_map<std::string, std::vector<cv::Point>> _groups;
30+
31+
public:
32+
static void clear();
33+
34+
static std::string saveGroup(std::vector<cv::Point>);
35+
static std::string saveGroup(std::string, std::vector<cv::Point>);
36+
37+
static std::vector<cv::Point> getGroup(std::string id);
38+
};
39+
40+
#endif /* FOCV_PointsGroup_hpp */

cpp/FOCV_Rect.cpp

+53
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
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+
}

cpp/FOCV_Rect.hpp

+44
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
//
2+
// FOCV_Rect.hpp
3+
// react-native-fast-opencv
4+
//
5+
// Created by Łukasz Kurant on 04/08/2024.
6+
//
7+
8+
#ifndef FOCV_Rect_hpp
9+
#define FOCV_Rect_hpp
10+
11+
#include <jsi/jsilib.h>
12+
#include <jsi/jsi.h>
13+
14+
#ifdef __cplusplus
15+
#undef YES
16+
#undef NO
17+
#include <opencv2/opencv.hpp>
18+
using namespace cv;
19+
#if __has_feature(objc_bool)
20+
#define YES __objc_yes
21+
#define NO __objc_no
22+
#else
23+
#define YES ((BOOL)1)
24+
#define NO ((BOOL)0)
25+
#endif
26+
#endif
27+
28+
#include <stdio.h>
29+
30+
class FOCV_Rect {
31+
private:
32+
static std::unordered_map<std::string, cv::Rect> _rects;
33+
34+
public:
35+
static void clear();
36+
37+
static std::string saveRect(cv::Rect);
38+
static std::string saveRect(std::string, cv::Rect);
39+
40+
static cv::Rect getRect(std::string id);
41+
static facebook::jsi::Object getJsiRect(std::string id, facebook::jsi::Runtime& runtime);
42+
};
43+
44+
#endif /* FOCV_Rect_hpp */

cpp/FOCV_Storage.cpp

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
//
2+
// FOCV_Storage.cpp
3+
// react-native-fast-opencv
4+
//
5+
// Created by Łukasz Kurant on 05/08/2024.
6+
//
7+
8+
#include "FOCV_Storage.hpp"

0 commit comments

Comments
 (0)