Skip to content

Commit 6bb2a07

Browse files
Merge pull request #62 from lukaszkurantdev/feat/warpAffine
feat: affine transform and get rotation matrix functions
2 parents 4f0e725 + 22c2e9c commit 6bb2a07

File tree

8 files changed

+137
-47
lines changed

8 files changed

+137
-47
lines changed

cpp/FOCV_Function.cpp

+16
Original file line numberDiff line numberDiff line change
@@ -382,6 +382,14 @@ jsi::Object FOCV_Function::invoke(jsi::Runtime& runtime, const jsi::Value* argum
382382
auto result = cv::getOptimalDFTSize(vecsize);
383383
value.setProperty(runtime, "value", result);
384384
} break;
385+
case hashString("getRotationMatrix2D", 19): {
386+
auto center = args.asPoint2fPtr(1);
387+
auto angle = args.asNumber(2);
388+
auto scale = args.asNumber(3);
389+
auto dst = args.asMatPtr(4);
390+
391+
*dst = cv::getRotationMatrix2D(*center, angle, scale);
392+
} break;
385393
case hashString("hconcat", 7): {
386394
auto srcs = args.asMatVectorPtr(1);
387395
auto dst = args.asMatPtr(2);
@@ -1428,6 +1436,14 @@ jsi::Object FOCV_Function::invoke(jsi::Runtime& runtime, const jsi::Value* argum
14281436
}
14291437
(*src).convertTo(*dst, rtype);
14301438
} break;
1439+
case hashString("warpAffine", 10): {
1440+
auto src = args.asMatPtr(1);
1441+
auto dst = args.asMatPtr(2);
1442+
auto rotation = args.asMatPtr(3);
1443+
auto size = args.asSizePtr(4);
1444+
1445+
cv::warpAffine(*src, *dst, *rotation, *size);
1446+
} break;
14311447
case hashString("warpPerspective", 15): {
14321448
auto src = args.asMatPtr(1);
14331449
auto dst = args.asMatPtr(2);

cpp/FOCV_FunctionArguments.cpp

+11
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,13 @@ std::shared_ptr<std::vector<cv::Point>> FOCV_FunctionArguments::asPointVectorPtr
6565
return FOCV_Storage::get<std::vector<cv::Point>>(FOCV_JsiObject::id_from_wrap(*this->runtime, arguments[index]));
6666
}
6767

68+
std::shared_ptr<cv::Point2f> FOCV_FunctionArguments::asPoint2fPtr(int index) {
69+
if (!this->isPoint2f(index)) {
70+
throw std::runtime_error("Fast OpenCV Error: Argument (" + std::to_string(index) + ") is not a Point2f!");
71+
}
72+
return FOCV_Storage::get<cv::Point2f>(FOCV_JsiObject::id_from_wrap(*this->runtime, arguments[index]));
73+
}
74+
6875
std::shared_ptr<std::vector<cv::Point2f>> FOCV_FunctionArguments::asPoint2fVectorPtr(int index) {
6976
if (!this->isPoint2fVector(index)) {
7077
throw std::runtime_error("Fast OpenCV Error: Argument (" + std::to_string(index) + ") is not a Point2fVector!");
@@ -157,6 +164,10 @@ bool FOCV_FunctionArguments::isPointVector(int index) {
157164
return this->isObject(index) && FOCV_JsiObject::type_from_wrap(*this->runtime, arguments[index]) == "point_vector";
158165
}
159166

167+
bool FOCV_FunctionArguments::isPoint2f(int index) {
168+
return this->isObject(index) && FOCV_JsiObject::type_from_wrap(*this->runtime, arguments[index]) == "point2f";
169+
}
170+
160171
bool FOCV_FunctionArguments::isPoint2fVector(int index) {
161172
return this->isObject(index) && FOCV_JsiObject::type_from_wrap(*this->runtime, arguments[index]) == "point2f_vector";
162173
}

cpp/FOCV_FunctionArguments.hpp

+2
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ class FOCV_FunctionArguments {
5050
std::shared_ptr<std::vector<cv::Mat>> asMatVectorPtr(int index);
5151
std::shared_ptr<cv::Point> asPointPtr(int index);
5252
std::shared_ptr<std::vector<cv::Point>> asPointVectorPtr(int index);
53+
std::shared_ptr<cv::Point2f> asPoint2fPtr(int index);
5354
std::shared_ptr<std::vector<cv::Point2f>> asPoint2fVectorPtr(int index);
5455
std::shared_ptr<std::vector<std::vector<cv::Point>>> asPointVectorOfVectorsPtr(int index);
5556
std::shared_ptr<cv::Rect> asRectPtr(int index);
@@ -67,6 +68,7 @@ class FOCV_FunctionArguments {
6768
bool isMatVector(int index);
6869
bool isPoint(int index);
6970
bool isPointVector(int index);
71+
bool isPoint2f(int index);
7072
bool isPoint2fVector(int index);
7173
bool isPointVectorOfVectors(int index);
7274
bool isRect(int index);

docs/pages/availablefunctions.md

+33
Original file line numberDiff line numberDiff line change
@@ -565,6 +565,19 @@ Calculates the optimal DFT size for a given vector size.
565565
invoke(name: 'getOptimalDFTSize', vecsize: number): { value: number };
566566
```
567567

568+
### getRotationMatrix2D
569+
570+
Calculates rotation matrix.
571+
- name Function name.
572+
- center center point
573+
- angle angle value
574+
- scale scale value
575+
- dst output matrix
576+
577+
```js
578+
invoke(name: 'getRotationMatrix2D', center: Point2f, angle: number, scale: number, dst: Mat): void;
579+
```
580+
568581
### hconcat
569582

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

2409+
### warpAffine
2410+
2411+
Applies an affine transformation to an image.
2412+
2413+
- name Function name.
2414+
- src input image.
2415+
- dst output image that has the size dsize and the same type as src
2416+
- M transformation matrix
2417+
- dsize size of the output image
2418+
2419+
```js
2420+
invoke(
2421+
name: 'warpAffine',
2422+
src: Mat,
2423+
dst: Mat,
2424+
M: Mat,
2425+
dsize: Size
2426+
): Mat;
2427+
```
2428+
23962429
### warpPerspective
23972430

23982431
Applies a perspective transformation to an image.

example/ios/.xcode.env.local

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export NODE_BINARY=/Users/lukasz/.nvm/versions/node/v22.14.0/bin/node

example/ios/Podfile.lock

+47-47
Original file line numberDiff line numberDiff line change
@@ -936,7 +936,7 @@ PODS:
936936
- React-Mapbuffer (0.74.4):
937937
- glog
938938
- React-debug
939-
- react-native-fast-opencv (0.3.4):
939+
- react-native-fast-opencv (0.4.0):
940940
- DoubleConversion
941941
- FastOpenCV-iOS (= 1.0.4)
942942
- glog
@@ -1609,65 +1609,65 @@ SPEC CHECKSUMS:
16091609
fmt: 4c2741a687cc09f0634a2e2c72a838b99f1ff120
16101610
glog: fdfdfe5479092de0c4bdbebedd9056951f092c4f
16111611
hermes-engine: 6312f669c895e05f0f6029554061593711770ea6
1612-
RCT-Folly: 02617c592a293bd6d418e0a88ff4ee1f88329b47
1612+
RCT-Folly: 5dc73daec3476616d19e8a53f0156176f7b55461
16131613
RCTDeprecation: d83da85890d5bb18efd2809a733865c1c5c11487
16141614
RCTRequired: e109419eacfb10fbb79a3ecb57ebcad198593d8a
16151615
RCTTypeSafety: 9d0307c2738867b9850f096914a15294124b2439
16161616
React: 40ad59420ae403a6d2d49f2787f0bfaabaed4fdf
16171617
React-callinvoker: a5fb605689272d6f5640738311aa510d3f59869f
1618-
React-Codegen: 3267a426718c8a0a979d0cd0495ba793cfdba7ca
1619-
React-Core: b1eeb2b94117f6ef5b4b0ed38f2f8d482ce915ce
1620-
React-CoreModules: e60a158a4e1b109ccdd781fb649f36691eb954d7
1621-
React-cxxreact: 3749b5548f8b66a304729e159dfaf3cfd7196c3a
1618+
React-Codegen: bbed4e177d9fec064c94d33f09f81bfd6b5621d8
1619+
React-Core: a4da9046c0753d0c4cc088b55d0283e5c0f3d1d7
1620+
React-CoreModules: 24222c73e6dee4668cecbc290afb1ac71e5a9d4a
1621+
React-cxxreact: 2cd16e23d93b7308fe95b24cdee539e6f3f7d416
16221622
React-debug: 8e15e6d6456f9b8521958deb40157eeeaac2914d
1623-
React-Fabric: 52cf1f94d5c6b05fe6057ba07796a633daf93735
1624-
React-FabricImage: 6e0f28a6ec040be4b5bd1a6e5eeda7263639a24c
1623+
React-Fabric: 7d1aa28a7c3c531777df4c2cd2c4253159c9f233
1624+
React-FabricImage: ae1205bd5090e678151d4ff845159ce56e54406b
16251625
React-featureflags: 81279a0d43736e9867cf0b736c868257af04c827
1626-
React-graphics: 37c161d8e634526897f12837f3e62a2895dede95
1627-
React-hermes: 3cfa4668970c810db0f6b43bd5c32f5927fd0500
1628-
React-ImageManager: 276987aeb4008fe8abe10bfc53d7160c96c31052
1629-
React-jserrorhandler: 0cdb976ee0e2ed4b93f501491e84954f80bf5f34
1630-
React-jsi: 18011ef308cc43e2fb21a1de0b61eabd9f899887
1631-
React-jsiexecutor: 156298b2ddebed0f6bcc526edd3deb4d240437bc
1632-
React-jsinspector: ed6c5a768dea8e344f07242bd9946b666b78228e
1633-
React-jsitracing: 4e9c99e73a6269b27b0d4cbab277dd90df3e5ac0
1634-
React-logger: fbfb50e2a2b1b46ee087f0a52739fadecc5e81a4
1635-
React-Mapbuffer: d39610dff659d8cf1fea485abae08bbf6f9c8279
1636-
react-native-fast-opencv: 35b0442a0b585bc919de50a28344e5454c024b13
1637-
react-native-image-picker: c3afe5472ef870d98a4b28415fc0b928161ee5f7
1638-
react-native-safe-area-context: 4532f1a0c5d34a46b9324ccaaedcb5582a302b7d
1639-
react-native-skia: 2bae63532997971033b297348f4156d6a012cbef
1640-
react-native-worklets-core: e0a05ed7887519277942efc866fd2785a24c86db
1626+
React-graphics: 6901357fb89a276092625728791f35e80f245d72
1627+
React-hermes: 505a7387f351708c20ff29a4e93ed2f92f648f25
1628+
React-ImageManager: 2f969e08c1f37cfd1d2ee8b6eca9178b8874c179
1629+
React-jserrorhandler: 3a8fb4b4f4da233ad569d1759f23129c80b69912
1630+
React-jsi: d97f74443db2d84f0ec50e5a82fc030bc349c02b
1631+
React-jsiexecutor: b6671962bf6228d342d5b04425d45cd8c4dd9803
1632+
React-jsinspector: 9891477c4da0560a729c23db1eaafde5627ee649
1633+
React-jsitracing: 7246bbdc12aa5ac7f25f5d14eb0e080038d75b00
1634+
React-logger: b4440a25b9c41b28042d289998d90b18c79ce2b0
1635+
React-Mapbuffer: fe1b4b0aa9c3fb49768dee7e322ee33d2dd6929e
1636+
react-native-fast-opencv: ec12ddebad1905298f63036fb9dfbfb5a1cfa502
1637+
react-native-image-picker: 6f7695f6e5aa43dc6275cbb3198cfa066a2f5be4
1638+
react-native-safe-area-context: b13be9714d9771fbde0120bc519c963484de3a71
1639+
react-native-skia: d0f075344d4e9333110c4f82dcf86d61105e90f9
1640+
react-native-worklets-core: 8fecea56d0f58f39a12f683522f96ff42bfda765
16411641
React-nativeconfig: 2be4363c2c4ac2b42419577774e83e4e4fd2af9f
1642-
React-NativeModulesApple: 453ada38f826a508e48872c7a7877c431af48bba
1642+
React-NativeModulesApple: d577ba690340c5c6487165ac74cbcbfc7abea9f6
16431643
React-perflogger: 9745f800ab4d12ec4325bde7bd090eafb87c5570
16441644
React-RCTActionSheet: 4225e883c5feaffc072c86128cc42cb070097010
1645-
React-RCTAnimation: 6b318e7e475ea574abf6a65e58e4989dd19d9ec4
1646-
React-RCTAppDelegate: 00d29b205df54386bc4e9c8929c500ed00ee1d57
1647-
React-RCTBlob: cf152386cc829be9323b2845fd9ec25122a986c3
1648-
React-RCTFabric: 071b326a331bd1ccb59e5886c0cd38e414ec9c9f
1649-
React-RCTImage: d3d5e0f0740fbd53705f7e9acc067bafe395026c
1650-
React-RCTLinking: 3ed7d222d3534287b408855b9d378d6576b7661b
1651-
React-RCTNetwork: 33a6bb615c1f7678538298aed9f27ecd69d512f3
1652-
React-RCTSettings: bbadd0bedde8fc5f4ef337534b1368d61e104e76
1653-
React-RCTText: 1a41cd4ce814366745b6107e6f15eb0ada7ff240
1654-
React-RCTVibration: 8275c91f707e03ead0a010e9fbeda53a645335ca
1655-
React-rendererdebug: 6ba24e1d975c89a6e92440be4f246ba8bed432c6
1645+
React-RCTAnimation: d4716aa6dc14eaf0b597a3768c98d57f2f7aa785
1646+
React-RCTAppDelegate: 6d08b0b042e3c88949a21d7a531ea3cbebf6b9a7
1647+
React-RCTBlob: 2ba96d2882b180d7d6f1c5f0ba7e424a599a4bf7
1648+
React-RCTFabric: 336b15547c00d1274a6e5283cfc2683904964c1d
1649+
React-RCTImage: 3acac00bd560aba753f3e66467209ce91ea75e9d
1650+
React-RCTLinking: b743c915842ae402ab796683acfa89c4cdbce692
1651+
React-RCTNetwork: 92a97a215fcf54d1539685d6e7da7d4157970669
1652+
React-RCTSettings: 220e858a57992d28d3af6f3bdee38477f19ff980
1653+
React-RCTText: e53aa7ebe46b910f1bb10e74895cf8d22cdbfba1
1654+
React-RCTVibration: dbe8f4d5a5d77b6104b99a05d858158ecea5f260
1655+
React-rendererdebug: 5354f6e36f7b0b0239d58bae27234021e1330e0a
16561656
React-rncore: 65fe0264f5c93ccb65bd6cae6201c80d34e625c0
1657-
React-RuntimeApple: 93e7c4c6a0be2eb3ce8dc31fdddea5708cd2ad2b
1658-
React-RuntimeCore: 1a2f2dfcba853d01c083db2b7d96f32f9768a677
1657+
React-RuntimeApple: d005a67a7b670f0526f952a1f2e70416436e9678
1658+
React-RuntimeCore: 54dc23c26596c9fdf6b3db21455a31d0a3c5abb8
16591659
React-runtimeexecutor: 6abf418f2d0038fb3fef15444d9c691db198771c
1660-
React-RuntimeHermes: fb6f76a5cd4212a0af4789794d4a9f5147e2f1aa
1661-
React-runtimescheduler: 3f312d33f475467a59864e0c5ab8708461387d1c
1662-
React-utils: e8b0eac797c81c574b24f6515fec4015599b643c
1663-
ReactCommon: eebffb37a90138c6db6eb8b2d952e7e5c6bc083c
1664-
RNReanimated: af4e059a8fd0fb7a9cdf5ad35ead4699598a9447
1665-
RNScreens: 6b641f232990a9d505a6d139fd18c3c759c9d290
1660+
React-RuntimeHermes: 78f32e04989ee89a4eaffae81a2c17d8a4cd5bd8
1661+
React-runtimescheduler: 9141803094972343dfb141530048347f849439a4
1662+
React-utils: bd629b1ced110779df5c362417b21d64ff059648
1663+
ReactCommon: 1bf12f3b537e3235f5173a3ec08bd125c80c861d
1664+
RNReanimated: cb3c4fff2228af59972b299d09e1fc15922418fe
1665+
RNScreens: 8a3ba045e7e8b5dd1b9a7764496430e17d00dfed
16661666
SocketRocket: abac6f5de4d4d62d24e11868d7a2f427e0ef940d
1667-
vision-camera-resize-plugin: 8847ccd1940a61e84e23a3148bc1f1a20cecfd5f
1668-
VisionCamera: 88df4dae7196c93ecd331f105f0e5d7d95702cb3
1669-
Yoga: 6259f968a4fdf516d76a4432dead624d71aa0fb1
1667+
vision-camera-resize-plugin: 322e0d4c6ebaade97534a324500aa0e95d6e694e
1668+
VisionCamera: 251834c639403d63fafff8a4111f7ca0b6e29f9a
1669+
Yoga: 0efb3e1bd40ba59b009f01badea863281101de78
16701670

16711671
PODFILE CHECKSUM: ded8a41f26047703e900afe99b8a72ca375b02ca
16721672

1673-
COCOAPODS: 1.15.2
1673+
COCOAPODS: 1.16.2

src/functions/Core.ts

+17
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import type {
1515
Mat,
1616
MatVector,
1717
Point,
18+
Point2f,
1819
PointVector,
1920
Rect,
2021
Scalar,
@@ -447,6 +448,22 @@ export type Core = {
447448
*/
448449
invoke(name: 'getOptimalDFTSize', vecsize: number): { value: number };
449450

451+
/**
452+
* Calculates rotation matrix.
453+
* @param name Function name.
454+
* @param center center point
455+
* @param angle angle value
456+
* @param scale scale value
457+
* @param dst output matrix
458+
*/
459+
invoke(
460+
name: 'getRotationMatrix2D',
461+
center: Point2f,
462+
angle: number,
463+
scale: number,
464+
dst: Mat
465+
): void;
466+
450467
/**
451468
* Applies horizontal concatenation to given matrices
452469
* @param name Function name.

src/functions/ImageProcessing/ImageTransform.ts

+10
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,16 @@ export type ImageTransform = {
1717
solveMethod: DecompTypes
1818
): Mat;
1919

20+
/**
21+
* Applies an affine transformation to an image.
22+
* @param name Function name.
23+
* @param src input image.
24+
* @param dst output image that has the size dsize and the same type as src
25+
* @param M transformation matrix
26+
* @param dsize size of the output image
27+
*/
28+
invoke(name: 'warpAffine', src: Mat, dst: Mat, M: Mat, dsize: Size): Mat;
29+
2030
/**
2131
* Applies a perspective transformation to an image.
2232
* @param name Function name.

0 commit comments

Comments
 (0)