@mleonard9/vin-scanner 0.2.8 → 0.2.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -5,7 +5,6 @@
|
|
|
5
5
|
#import <VisionCamera/Frame.h>
|
|
6
6
|
#import <VisionCamera/SharedArray.h>
|
|
7
7
|
#import <React/RCTBridgeModule.h>
|
|
8
|
-
#import <CoreVideo/CoreVideo.h>
|
|
9
8
|
@import MLKitVision;
|
|
10
9
|
|
|
11
10
|
@interface VisionCameraBarcodeScannerPlugin : FrameProcessorPlugin
|
|
@@ -59,14 +58,30 @@
|
|
|
59
58
|
orientation = [self orientationFromValue:orientationOverride fallback:orientation];
|
|
60
59
|
}
|
|
61
60
|
|
|
62
|
-
//
|
|
63
|
-
|
|
64
|
-
|
|
61
|
+
// Fix vertical flip issue on iOS by rotating orientation 180 degrees
|
|
62
|
+
// This ensures ML Kit processes the image in the correct orientation
|
|
63
|
+
UIImageOrientation correctedOrientation = orientation;
|
|
64
|
+
switch (orientation) {
|
|
65
|
+
case UIImageOrientationUp:
|
|
66
|
+
correctedOrientation = UIImageOrientationDown;
|
|
67
|
+
break;
|
|
68
|
+
case UIImageOrientationDown:
|
|
69
|
+
correctedOrientation = UIImageOrientationUp;
|
|
70
|
+
break;
|
|
71
|
+
case UIImageOrientationLeft:
|
|
72
|
+
correctedOrientation = UIImageOrientationRight;
|
|
73
|
+
break;
|
|
74
|
+
case UIImageOrientationRight:
|
|
75
|
+
correctedOrientation = UIImageOrientationLeft;
|
|
76
|
+
break;
|
|
77
|
+
default:
|
|
78
|
+
break;
|
|
79
|
+
}
|
|
65
80
|
|
|
66
81
|
// VisionCamera already normalizes orientation per https://react-native-vision-camera.com/docs/guides/orientation,
|
|
67
82
|
// so ML Kit just needs the frame's orientation metadata instead of rotating pixels manually.
|
|
68
83
|
MLKVisionImage *image = [[MLKVisionImage alloc] initWithBuffer:buffer];
|
|
69
|
-
image.orientation =
|
|
84
|
+
image.orientation = correctedOrientation;
|
|
70
85
|
NSMutableArray *detections = [NSMutableArray array];
|
|
71
86
|
__block NSDictionary *resultPayload = @{};
|
|
72
87
|
dispatch_group_t dispatchGroup = dispatch_group_create();
|
|
@@ -97,13 +112,9 @@
|
|
|
97
112
|
if (boxData != nil) {
|
|
98
113
|
CGRect frameRect = barcode.frame;
|
|
99
114
|
const NSUInteger baseIndex = idx * 6;
|
|
100
|
-
//
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
float maxY = CGRectGetMaxY(frameRect);
|
|
104
|
-
float imageHeightFloat = (float)imageHeight;
|
|
105
|
-
boxData[baseIndex] = imageHeightFloat - maxY; // top = height - bottom
|
|
106
|
-
boxData[baseIndex + 1] = imageHeightFloat - minY; // bottom = height - top
|
|
115
|
+
// Coordinates are now correct after orientation fix
|
|
116
|
+
boxData[baseIndex] = CGRectGetMinY(frameRect);
|
|
117
|
+
boxData[baseIndex + 1] = CGRectGetMaxY(frameRect);
|
|
107
118
|
boxData[baseIndex + 2] = CGRectGetMinX(frameRect);
|
|
108
119
|
boxData[baseIndex + 3] = CGRectGetMaxX(frameRect);
|
|
109
120
|
boxData[baseIndex + 4] = CGRectGetWidth(frameRect);
|
|
@@ -9,7 +9,6 @@
|
|
|
9
9
|
#import <VisionCamera/VisionCameraProxyHolder.h>
|
|
10
10
|
#import <VisionCamera/Frame.h>
|
|
11
11
|
#import <VisionCamera/SharedArray.h>
|
|
12
|
-
#import <CoreVideo/CoreVideo.h>
|
|
13
12
|
@import MLKitVision;
|
|
14
13
|
|
|
15
14
|
@interface VisionCameraTextRecognitionPlugin : FrameProcessorPlugin
|
|
@@ -88,13 +87,28 @@
|
|
|
88
87
|
orientation = [self orientationFromValue:orientationOverride fallback:orientation];
|
|
89
88
|
}
|
|
90
89
|
|
|
91
|
-
//
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
90
|
+
// Fix vertical flip issue on iOS by rotating orientation 180 degrees
|
|
91
|
+
// This ensures ML Kit processes the image in the correct orientation
|
|
92
|
+
UIImageOrientation correctedOrientation = orientation;
|
|
93
|
+
switch (orientation) {
|
|
94
|
+
case UIImageOrientationUp:
|
|
95
|
+
correctedOrientation = UIImageOrientationDown;
|
|
96
|
+
break;
|
|
97
|
+
case UIImageOrientationDown:
|
|
98
|
+
correctedOrientation = UIImageOrientationUp;
|
|
99
|
+
break;
|
|
100
|
+
case UIImageOrientationLeft:
|
|
101
|
+
correctedOrientation = UIImageOrientationRight;
|
|
102
|
+
break;
|
|
103
|
+
case UIImageOrientationRight:
|
|
104
|
+
correctedOrientation = UIImageOrientationLeft;
|
|
105
|
+
break;
|
|
106
|
+
default:
|
|
107
|
+
break;
|
|
108
|
+
}
|
|
95
109
|
|
|
96
110
|
MLKVisionImage *image = [[MLKVisionImage alloc] initWithBuffer:buffer];
|
|
97
|
-
image.orientation =
|
|
111
|
+
image.orientation = correctedOrientation;
|
|
98
112
|
NSMutableArray *detections = [NSMutableArray array];
|
|
99
113
|
NSMutableArray<NSArray<NSNumber *> *> *boxValues = [NSMutableArray array];
|
|
100
114
|
NSString *language = arguments[@"language"] ?: self.preferredLanguage ?: @"latin";
|
|
@@ -112,11 +126,7 @@
|
|
|
112
126
|
NSString *resultText = result.text;
|
|
113
127
|
for (MLKTextBlock *block in result.blocks) {
|
|
114
128
|
CGRect blockFrame = block.frame;
|
|
115
|
-
//
|
|
116
|
-
float blockMinY = CGRectGetMinY(blockFrame);
|
|
117
|
-
float blockMaxY = CGRectGetMaxY(blockFrame);
|
|
118
|
-
float blockTransformedMinY = imageHeightFloat - blockMaxY;
|
|
119
|
-
float blockTransformedMaxY = imageHeightFloat - blockMinY;
|
|
129
|
+
// Coordinates are now correct after orientation fix
|
|
120
130
|
|
|
121
131
|
if (block.lines.count == 0) {
|
|
122
132
|
NSMutableDictionary *entry = [[NSMutableDictionary alloc] init];
|
|
@@ -125,7 +135,7 @@
|
|
|
125
135
|
entry[@"boxIndex"] = @(boxValues.count);
|
|
126
136
|
[detections addObject:entry];
|
|
127
137
|
[boxValues addObject:@[
|
|
128
|
-
@(
|
|
138
|
+
@(CGRectGetMinY(blockFrame)), @(CGRectGetMaxY(blockFrame)),
|
|
129
139
|
@(CGRectGetMinX(blockFrame)), @(CGRectGetMaxX(blockFrame)),
|
|
130
140
|
@(-1.f), @(-1.f), @(-1.f), @(-1.f),
|
|
131
141
|
@(-1.f), @(-1.f), @(-1.f), @(-1.f)
|
|
@@ -133,11 +143,6 @@
|
|
|
133
143
|
}
|
|
134
144
|
for (MLKTextLine *line in block.lines) {
|
|
135
145
|
CGRect lineFrame = line.frame;
|
|
136
|
-
// Transform Y coordinates for line frame
|
|
137
|
-
float lineMinY = CGRectGetMinY(lineFrame);
|
|
138
|
-
float lineMaxY = CGRectGetMaxY(lineFrame);
|
|
139
|
-
float lineTransformedMinY = imageHeightFloat - lineMaxY;
|
|
140
|
-
float lineTransformedMaxY = imageHeightFloat - lineMinY;
|
|
141
146
|
|
|
142
147
|
if (line.elements.count == 0) {
|
|
143
148
|
NSMutableDictionary *entry = [[NSMutableDictionary alloc] init];
|
|
@@ -147,20 +152,15 @@
|
|
|
147
152
|
entry[@"boxIndex"] = @(boxValues.count);
|
|
148
153
|
[detections addObject:entry];
|
|
149
154
|
[boxValues addObject:@[
|
|
150
|
-
@(
|
|
155
|
+
@(CGRectGetMinY(blockFrame)), @(CGRectGetMaxY(blockFrame)),
|
|
151
156
|
@(CGRectGetMinX(blockFrame)), @(CGRectGetMaxX(blockFrame)),
|
|
152
|
-
@(
|
|
157
|
+
@(CGRectGetMinY(lineFrame)), @(CGRectGetMaxY(lineFrame)),
|
|
153
158
|
@(CGRectGetMinX(lineFrame)), @(CGRectGetMaxX(lineFrame)),
|
|
154
159
|
@(-1.f), @(-1.f), @(-1.f), @(-1.f)
|
|
155
160
|
]];
|
|
156
161
|
}
|
|
157
162
|
for (MLKTextElement *element in line.elements) {
|
|
158
163
|
CGRect elementFrame = element.frame;
|
|
159
|
-
// Transform Y coordinates for element frame
|
|
160
|
-
float elementMinY = CGRectGetMinY(elementFrame);
|
|
161
|
-
float elementMaxY = CGRectGetMaxY(elementFrame);
|
|
162
|
-
float elementTransformedMinY = imageHeightFloat - elementMaxY;
|
|
163
|
-
float elementTransformedMaxY = imageHeightFloat - elementMinY;
|
|
164
164
|
|
|
165
165
|
NSMutableDictionary *entry = [[NSMutableDictionary alloc] init];
|
|
166
166
|
entry[@"resultText"] = resultText ?: (id)kCFNull;
|
|
@@ -170,11 +170,11 @@
|
|
|
170
170
|
entry[@"boxIndex"] = @(boxValues.count);
|
|
171
171
|
[detections addObject:entry];
|
|
172
172
|
[boxValues addObject:@[
|
|
173
|
-
@(
|
|
173
|
+
@(CGRectGetMinY(blockFrame)), @(CGRectGetMaxY(blockFrame)),
|
|
174
174
|
@(CGRectGetMinX(blockFrame)), @(CGRectGetMaxX(blockFrame)),
|
|
175
|
-
@(
|
|
175
|
+
@(CGRectGetMinY(lineFrame)), @(CGRectGetMaxY(lineFrame)),
|
|
176
176
|
@(CGRectGetMinX(lineFrame)), @(CGRectGetMaxX(lineFrame)),
|
|
177
|
-
@(
|
|
177
|
+
@(CGRectGetMinY(elementFrame)), @(CGRectGetMaxY(elementFrame)),
|
|
178
178
|
@(CGRectGetMinX(elementFrame)), @(CGRectGetMaxX(elementFrame))
|
|
179
179
|
]];
|
|
180
180
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mleonard9/vin-scanner",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.9",
|
|
4
4
|
"description": "High-performance VIN scanner for React Native Vision Camera powered by Google ML Kit barcode + text recognition.",
|
|
5
5
|
"main": "lib/commonjs/index",
|
|
6
6
|
"module": "lib/module/index",
|