@mleonard9/vin-scanner 0.2.7 → 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.
|
@@ -57,10 +57,31 @@
|
|
|
57
57
|
if (orientationOverride.length > 0) {
|
|
58
58
|
orientation = [self orientationFromValue:orientationOverride fallback:orientation];
|
|
59
59
|
}
|
|
60
|
+
|
|
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
|
+
}
|
|
80
|
+
|
|
60
81
|
// VisionCamera already normalizes orientation per https://react-native-vision-camera.com/docs/guides/orientation,
|
|
61
|
-
// so ML Kit just needs the frame
|
|
82
|
+
// so ML Kit just needs the frame's orientation metadata instead of rotating pixels manually.
|
|
62
83
|
MLKVisionImage *image = [[MLKVisionImage alloc] initWithBuffer:buffer];
|
|
63
|
-
image.orientation =
|
|
84
|
+
image.orientation = correctedOrientation;
|
|
64
85
|
NSMutableArray *detections = [NSMutableArray array];
|
|
65
86
|
__block NSDictionary *resultPayload = @{};
|
|
66
87
|
dispatch_group_t dispatchGroup = dispatch_group_create();
|
|
@@ -91,6 +112,7 @@
|
|
|
91
112
|
if (boxData != nil) {
|
|
92
113
|
CGRect frameRect = barcode.frame;
|
|
93
114
|
const NSUInteger baseIndex = idx * 6;
|
|
115
|
+
// Coordinates are now correct after orientation fix
|
|
94
116
|
boxData[baseIndex] = CGRectGetMinY(frameRect);
|
|
95
117
|
boxData[baseIndex + 1] = CGRectGetMaxY(frameRect);
|
|
96
118
|
boxData[baseIndex + 2] = CGRectGetMinX(frameRect);
|
|
@@ -86,8 +86,29 @@
|
|
|
86
86
|
if (orientationOverride.length > 0) {
|
|
87
87
|
orientation = [self orientationFromValue:orientationOverride fallback:orientation];
|
|
88
88
|
}
|
|
89
|
+
|
|
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
|
+
}
|
|
109
|
+
|
|
89
110
|
MLKVisionImage *image = [[MLKVisionImage alloc] initWithBuffer:buffer];
|
|
90
|
-
image.orientation =
|
|
111
|
+
image.orientation = correctedOrientation;
|
|
91
112
|
NSMutableArray *detections = [NSMutableArray array];
|
|
92
113
|
NSMutableArray<NSArray<NSNumber *> *> *boxValues = [NSMutableArray array];
|
|
93
114
|
NSString *language = arguments[@"language"] ?: self.preferredLanguage ?: @"latin";
|
|
@@ -105,6 +126,8 @@
|
|
|
105
126
|
NSString *resultText = result.text;
|
|
106
127
|
for (MLKTextBlock *block in result.blocks) {
|
|
107
128
|
CGRect blockFrame = block.frame;
|
|
129
|
+
// Coordinates are now correct after orientation fix
|
|
130
|
+
|
|
108
131
|
if (block.lines.count == 0) {
|
|
109
132
|
NSMutableDictionary *entry = [[NSMutableDictionary alloc] init];
|
|
110
133
|
entry[@"resultText"] = resultText ?: (id)kCFNull;
|
|
@@ -120,6 +143,7 @@
|
|
|
120
143
|
}
|
|
121
144
|
for (MLKTextLine *line in block.lines) {
|
|
122
145
|
CGRect lineFrame = line.frame;
|
|
146
|
+
|
|
123
147
|
if (line.elements.count == 0) {
|
|
124
148
|
NSMutableDictionary *entry = [[NSMutableDictionary alloc] init];
|
|
125
149
|
entry[@"resultText"] = resultText ?: (id)kCFNull;
|
|
@@ -137,6 +161,7 @@
|
|
|
137
161
|
}
|
|
138
162
|
for (MLKTextElement *element in line.elements) {
|
|
139
163
|
CGRect elementFrame = element.frame;
|
|
164
|
+
|
|
140
165
|
NSMutableDictionary *entry = [[NSMutableDictionary alloc] init];
|
|
141
166
|
entry[@"resultText"] = resultText ?: (id)kCFNull;
|
|
142
167
|
entry[@"blockText"] = block.text ?: (id)kCFNull;
|
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",
|