Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: affine transform and get rotation matrix functions #62

Merged
merged 1 commit into from
Feb 20, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions cpp/FOCV_Function.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -382,6 +382,14 @@ jsi::Object FOCV_Function::invoke(jsi::Runtime& runtime, const jsi::Value* argum
auto result = cv::getOptimalDFTSize(vecsize);
value.setProperty(runtime, "value", result);
} break;
case hashString("getRotationMatrix2D", 19): {
auto center = args.asPoint2fPtr(1);
auto angle = args.asNumber(2);
auto scale = args.asNumber(3);
auto dst = args.asMatPtr(4);

*dst = cv::getRotationMatrix2D(*center, angle, scale);
} break;
case hashString("hconcat", 7): {
auto srcs = args.asMatVectorPtr(1);
auto dst = args.asMatPtr(2);
Expand Down Expand Up @@ -1428,6 +1436,14 @@ jsi::Object FOCV_Function::invoke(jsi::Runtime& runtime, const jsi::Value* argum
}
(*src).convertTo(*dst, rtype);
} break;
case hashString("warpAffine", 10): {
auto src = args.asMatPtr(1);
auto dst = args.asMatPtr(2);
auto rotation = args.asMatPtr(3);
auto size = args.asSizePtr(4);

cv::warpAffine(*src, *dst, *rotation, *size);
} break;
case hashString("warpPerspective", 15): {
auto src = args.asMatPtr(1);
auto dst = args.asMatPtr(2);
Expand Down
11 changes: 11 additions & 0 deletions cpp/FOCV_FunctionArguments.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,13 @@ std::shared_ptr<std::vector<cv::Point>> FOCV_FunctionArguments::asPointVectorPtr
return FOCV_Storage::get<std::vector<cv::Point>>(FOCV_JsiObject::id_from_wrap(*this->runtime, arguments[index]));
}

std::shared_ptr<cv::Point2f> FOCV_FunctionArguments::asPoint2fPtr(int index) {
if (!this->isPoint2f(index)) {
throw std::runtime_error("Fast OpenCV Error: Argument (" + std::to_string(index) + ") is not a Point2f!");
}
return FOCV_Storage::get<cv::Point2f>(FOCV_JsiObject::id_from_wrap(*this->runtime, arguments[index]));
}

std::shared_ptr<std::vector<cv::Point2f>> FOCV_FunctionArguments::asPoint2fVectorPtr(int index) {
if (!this->isPoint2fVector(index)) {
throw std::runtime_error("Fast OpenCV Error: Argument (" + std::to_string(index) + ") is not a Point2fVector!");
Expand Down Expand Up @@ -157,6 +164,10 @@ bool FOCV_FunctionArguments::isPointVector(int index) {
return this->isObject(index) && FOCV_JsiObject::type_from_wrap(*this->runtime, arguments[index]) == "point_vector";
}

bool FOCV_FunctionArguments::isPoint2f(int index) {
return this->isObject(index) && FOCV_JsiObject::type_from_wrap(*this->runtime, arguments[index]) == "point2f";
}

bool FOCV_FunctionArguments::isPoint2fVector(int index) {
return this->isObject(index) && FOCV_JsiObject::type_from_wrap(*this->runtime, arguments[index]) == "point2f_vector";
}
Expand Down
2 changes: 2 additions & 0 deletions cpp/FOCV_FunctionArguments.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ class FOCV_FunctionArguments {
std::shared_ptr<std::vector<cv::Mat>> asMatVectorPtr(int index);
std::shared_ptr<cv::Point> asPointPtr(int index);
std::shared_ptr<std::vector<cv::Point>> asPointVectorPtr(int index);
std::shared_ptr<cv::Point2f> asPoint2fPtr(int index);
std::shared_ptr<std::vector<cv::Point2f>> asPoint2fVectorPtr(int index);
std::shared_ptr<std::vector<std::vector<cv::Point>>> asPointVectorOfVectorsPtr(int index);
std::shared_ptr<cv::Rect> asRectPtr(int index);
Expand All @@ -67,6 +68,7 @@ class FOCV_FunctionArguments {
bool isMatVector(int index);
bool isPoint(int index);
bool isPointVector(int index);
bool isPoint2f(int index);
bool isPoint2fVector(int index);
bool isPointVectorOfVectors(int index);
bool isRect(int index);
Expand Down
33 changes: 33 additions & 0 deletions docs/pages/availablefunctions.md
Original file line number Diff line number Diff line change
Expand Up @@ -565,6 +565,19 @@ Calculates the optimal DFT size for a given vector size.
invoke(name: 'getOptimalDFTSize', vecsize: number): { value: number };
```

### getRotationMatrix2D

Calculates rotation matrix.
- name Function name.
- center center point
- angle angle value
- scale scale value
- dst output matrix

```js
invoke(name: 'getRotationMatrix2D', center: Point2f, angle: number, scale: number, dst: Mat): void;
```

### hconcat

Applies horizontal concatenation to given matrices
Expand Down Expand Up @@ -2393,6 +2406,26 @@ Finds a rotated rectangle of the minimum area enclosing the input 2D point set.
invoke(name: 'minAreaRect', points: Mat): RotatedRect;
```

### warpAffine

Applies an affine transformation to an image.

- name Function name.
- src input image.
- dst output image that has the size dsize and the same type as src
- M transformation matrix
- dsize size of the output image

```js
invoke(
name: 'warpAffine',
src: Mat,
dst: Mat,
M: Mat,
dsize: Size
): Mat;
```

### warpPerspective

Applies a perspective transformation to an image.
Expand Down
1 change: 1 addition & 0 deletions example/ios/.xcode.env.local
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export NODE_BINARY=/Users/lukasz/.nvm/versions/node/v22.14.0/bin/node
94 changes: 47 additions & 47 deletions example/ios/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -936,7 +936,7 @@ PODS:
- React-Mapbuffer (0.74.4):
- glog
- React-debug
- react-native-fast-opencv (0.3.4):
- react-native-fast-opencv (0.4.0):
- DoubleConversion
- FastOpenCV-iOS (= 1.0.4)
- glog
Expand Down Expand Up @@ -1609,65 +1609,65 @@ SPEC CHECKSUMS:
fmt: 4c2741a687cc09f0634a2e2c72a838b99f1ff120
glog: fdfdfe5479092de0c4bdbebedd9056951f092c4f
hermes-engine: 6312f669c895e05f0f6029554061593711770ea6
RCT-Folly: 02617c592a293bd6d418e0a88ff4ee1f88329b47
RCT-Folly: 5dc73daec3476616d19e8a53f0156176f7b55461
RCTDeprecation: d83da85890d5bb18efd2809a733865c1c5c11487
RCTRequired: e109419eacfb10fbb79a3ecb57ebcad198593d8a
RCTTypeSafety: 9d0307c2738867b9850f096914a15294124b2439
React: 40ad59420ae403a6d2d49f2787f0bfaabaed4fdf
React-callinvoker: a5fb605689272d6f5640738311aa510d3f59869f
React-Codegen: 3267a426718c8a0a979d0cd0495ba793cfdba7ca
React-Core: b1eeb2b94117f6ef5b4b0ed38f2f8d482ce915ce
React-CoreModules: e60a158a4e1b109ccdd781fb649f36691eb954d7
React-cxxreact: 3749b5548f8b66a304729e159dfaf3cfd7196c3a
React-Codegen: bbed4e177d9fec064c94d33f09f81bfd6b5621d8
React-Core: a4da9046c0753d0c4cc088b55d0283e5c0f3d1d7
React-CoreModules: 24222c73e6dee4668cecbc290afb1ac71e5a9d4a
React-cxxreact: 2cd16e23d93b7308fe95b24cdee539e6f3f7d416
React-debug: 8e15e6d6456f9b8521958deb40157eeeaac2914d
React-Fabric: 52cf1f94d5c6b05fe6057ba07796a633daf93735
React-FabricImage: 6e0f28a6ec040be4b5bd1a6e5eeda7263639a24c
React-Fabric: 7d1aa28a7c3c531777df4c2cd2c4253159c9f233
React-FabricImage: ae1205bd5090e678151d4ff845159ce56e54406b
React-featureflags: 81279a0d43736e9867cf0b736c868257af04c827
React-graphics: 37c161d8e634526897f12837f3e62a2895dede95
React-hermes: 3cfa4668970c810db0f6b43bd5c32f5927fd0500
React-ImageManager: 276987aeb4008fe8abe10bfc53d7160c96c31052
React-jserrorhandler: 0cdb976ee0e2ed4b93f501491e84954f80bf5f34
React-jsi: 18011ef308cc43e2fb21a1de0b61eabd9f899887
React-jsiexecutor: 156298b2ddebed0f6bcc526edd3deb4d240437bc
React-jsinspector: ed6c5a768dea8e344f07242bd9946b666b78228e
React-jsitracing: 4e9c99e73a6269b27b0d4cbab277dd90df3e5ac0
React-logger: fbfb50e2a2b1b46ee087f0a52739fadecc5e81a4
React-Mapbuffer: d39610dff659d8cf1fea485abae08bbf6f9c8279
react-native-fast-opencv: 35b0442a0b585bc919de50a28344e5454c024b13
react-native-image-picker: c3afe5472ef870d98a4b28415fc0b928161ee5f7
react-native-safe-area-context: 4532f1a0c5d34a46b9324ccaaedcb5582a302b7d
react-native-skia: 2bae63532997971033b297348f4156d6a012cbef
react-native-worklets-core: e0a05ed7887519277942efc866fd2785a24c86db
React-graphics: 6901357fb89a276092625728791f35e80f245d72
React-hermes: 505a7387f351708c20ff29a4e93ed2f92f648f25
React-ImageManager: 2f969e08c1f37cfd1d2ee8b6eca9178b8874c179
React-jserrorhandler: 3a8fb4b4f4da233ad569d1759f23129c80b69912
React-jsi: d97f74443db2d84f0ec50e5a82fc030bc349c02b
React-jsiexecutor: b6671962bf6228d342d5b04425d45cd8c4dd9803
React-jsinspector: 9891477c4da0560a729c23db1eaafde5627ee649
React-jsitracing: 7246bbdc12aa5ac7f25f5d14eb0e080038d75b00
React-logger: b4440a25b9c41b28042d289998d90b18c79ce2b0
React-Mapbuffer: fe1b4b0aa9c3fb49768dee7e322ee33d2dd6929e
react-native-fast-opencv: ec12ddebad1905298f63036fb9dfbfb5a1cfa502
react-native-image-picker: 6f7695f6e5aa43dc6275cbb3198cfa066a2f5be4
react-native-safe-area-context: b13be9714d9771fbde0120bc519c963484de3a71
react-native-skia: d0f075344d4e9333110c4f82dcf86d61105e90f9
react-native-worklets-core: 8fecea56d0f58f39a12f683522f96ff42bfda765
React-nativeconfig: 2be4363c2c4ac2b42419577774e83e4e4fd2af9f
React-NativeModulesApple: 453ada38f826a508e48872c7a7877c431af48bba
React-NativeModulesApple: d577ba690340c5c6487165ac74cbcbfc7abea9f6
React-perflogger: 9745f800ab4d12ec4325bde7bd090eafb87c5570
React-RCTActionSheet: 4225e883c5feaffc072c86128cc42cb070097010
React-RCTAnimation: 6b318e7e475ea574abf6a65e58e4989dd19d9ec4
React-RCTAppDelegate: 00d29b205df54386bc4e9c8929c500ed00ee1d57
React-RCTBlob: cf152386cc829be9323b2845fd9ec25122a986c3
React-RCTFabric: 071b326a331bd1ccb59e5886c0cd38e414ec9c9f
React-RCTImage: d3d5e0f0740fbd53705f7e9acc067bafe395026c
React-RCTLinking: 3ed7d222d3534287b408855b9d378d6576b7661b
React-RCTNetwork: 33a6bb615c1f7678538298aed9f27ecd69d512f3
React-RCTSettings: bbadd0bedde8fc5f4ef337534b1368d61e104e76
React-RCTText: 1a41cd4ce814366745b6107e6f15eb0ada7ff240
React-RCTVibration: 8275c91f707e03ead0a010e9fbeda53a645335ca
React-rendererdebug: 6ba24e1d975c89a6e92440be4f246ba8bed432c6
React-RCTAnimation: d4716aa6dc14eaf0b597a3768c98d57f2f7aa785
React-RCTAppDelegate: 6d08b0b042e3c88949a21d7a531ea3cbebf6b9a7
React-RCTBlob: 2ba96d2882b180d7d6f1c5f0ba7e424a599a4bf7
React-RCTFabric: 336b15547c00d1274a6e5283cfc2683904964c1d
React-RCTImage: 3acac00bd560aba753f3e66467209ce91ea75e9d
React-RCTLinking: b743c915842ae402ab796683acfa89c4cdbce692
React-RCTNetwork: 92a97a215fcf54d1539685d6e7da7d4157970669
React-RCTSettings: 220e858a57992d28d3af6f3bdee38477f19ff980
React-RCTText: e53aa7ebe46b910f1bb10e74895cf8d22cdbfba1
React-RCTVibration: dbe8f4d5a5d77b6104b99a05d858158ecea5f260
React-rendererdebug: 5354f6e36f7b0b0239d58bae27234021e1330e0a
React-rncore: 65fe0264f5c93ccb65bd6cae6201c80d34e625c0
React-RuntimeApple: 93e7c4c6a0be2eb3ce8dc31fdddea5708cd2ad2b
React-RuntimeCore: 1a2f2dfcba853d01c083db2b7d96f32f9768a677
React-RuntimeApple: d005a67a7b670f0526f952a1f2e70416436e9678
React-RuntimeCore: 54dc23c26596c9fdf6b3db21455a31d0a3c5abb8
React-runtimeexecutor: 6abf418f2d0038fb3fef15444d9c691db198771c
React-RuntimeHermes: fb6f76a5cd4212a0af4789794d4a9f5147e2f1aa
React-runtimescheduler: 3f312d33f475467a59864e0c5ab8708461387d1c
React-utils: e8b0eac797c81c574b24f6515fec4015599b643c
ReactCommon: eebffb37a90138c6db6eb8b2d952e7e5c6bc083c
RNReanimated: af4e059a8fd0fb7a9cdf5ad35ead4699598a9447
RNScreens: 6b641f232990a9d505a6d139fd18c3c759c9d290
React-RuntimeHermes: 78f32e04989ee89a4eaffae81a2c17d8a4cd5bd8
React-runtimescheduler: 9141803094972343dfb141530048347f849439a4
React-utils: bd629b1ced110779df5c362417b21d64ff059648
ReactCommon: 1bf12f3b537e3235f5173a3ec08bd125c80c861d
RNReanimated: cb3c4fff2228af59972b299d09e1fc15922418fe
RNScreens: 8a3ba045e7e8b5dd1b9a7764496430e17d00dfed
SocketRocket: abac6f5de4d4d62d24e11868d7a2f427e0ef940d
vision-camera-resize-plugin: 8847ccd1940a61e84e23a3148bc1f1a20cecfd5f
VisionCamera: 88df4dae7196c93ecd331f105f0e5d7d95702cb3
Yoga: 6259f968a4fdf516d76a4432dead624d71aa0fb1
vision-camera-resize-plugin: 322e0d4c6ebaade97534a324500aa0e95d6e694e
VisionCamera: 251834c639403d63fafff8a4111f7ca0b6e29f9a
Yoga: 0efb3e1bd40ba59b009f01badea863281101de78

PODFILE CHECKSUM: ded8a41f26047703e900afe99b8a72ca375b02ca

COCOAPODS: 1.15.2
COCOAPODS: 1.16.2
17 changes: 17 additions & 0 deletions src/functions/Core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import type {
Mat,
MatVector,
Point,
Point2f,
PointVector,
Rect,
Scalar,
Expand Down Expand Up @@ -447,6 +448,22 @@ export type Core = {
*/
invoke(name: 'getOptimalDFTSize', vecsize: number): { value: number };

/**
* Calculates rotation matrix.
* @param name Function name.
* @param center center point
* @param angle angle value
* @param scale scale value
* @param dst output matrix
*/
invoke(
name: 'getRotationMatrix2D',
center: Point2f,
angle: number,
scale: number,
dst: Mat
): void;

/**
* Applies horizontal concatenation to given matrices
* @param name Function name.
Expand Down
10 changes: 10 additions & 0 deletions src/functions/ImageProcessing/ImageTransform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,16 @@ export type ImageTransform = {
solveMethod: DecompTypes
): Mat;

/**
* Applies an affine transformation to an image.
* @param name Function name.
* @param src input image.
* @param dst output image that has the size dsize and the same type as src
* @param M transformation matrix
* @param dsize size of the output image
*/
invoke(name: 'warpAffine', src: Mat, dst: Mat, M: Mat, dsize: Size): Mat;

/**
* Applies a perspective transformation to an image.
* @param name Function name.
Expand Down
Loading