react-native-rectangle-doc-scanner 0.27.0 → 0.28.0

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.
@@ -150,33 +150,29 @@ const DocScanner = ({ onCapture, overlayColor = '#e7a649', autoCapture = true, m
150
150
  step = 'cvtColor';
151
151
  reportStage(step);
152
152
  react_native_fast_opencv_1.OpenCV.invoke('cvtColor', mat, mat, react_native_fast_opencv_1.ColorConversionCodes.COLOR_BGR2GRAY);
153
- // Apply bilateral filter for better edge preservation
154
- step = 'bilateralFilter';
155
- reportStage(step);
156
- const filtered = react_native_fast_opencv_1.OpenCV.createObject(react_native_fast_opencv_1.ObjectType.Mat);
157
- react_native_fast_opencv_1.OpenCV.invoke('bilateralFilter', mat, filtered, 9, 75, 75);
158
- // Use adaptive threshold for better contrast in varying lighting
159
- step = 'adaptiveThreshold';
153
+ // Apply Gaussian blur to reduce noise
154
+ const gaussianKernel = react_native_fast_opencv_1.OpenCV.createObject(react_native_fast_opencv_1.ObjectType.Size, 5, 5);
155
+ step = 'GaussianBlur';
160
156
  reportStage(step);
161
- const thresh = react_native_fast_opencv_1.OpenCV.createObject(react_native_fast_opencv_1.ObjectType.Mat);
162
- react_native_fast_opencv_1.OpenCV.invoke('adaptiveThreshold', filtered, thresh, 255, 1, 1, 11, 2);
163
- // Morphological operations to clean up noise
157
+ react_native_fast_opencv_1.OpenCV.invoke('GaussianBlur', mat, mat, gaussianKernel, 0);
158
+ // Morphological operations to enhance edges
164
159
  const morphologyKernel = react_native_fast_opencv_1.OpenCV.createObject(react_native_fast_opencv_1.ObjectType.Size, 3, 3);
165
160
  step = 'getStructuringElement';
166
161
  reportStage(step);
167
162
  const element = react_native_fast_opencv_1.OpenCV.invoke('getStructuringElement', react_native_fast_opencv_1.MorphShapes.MORPH_RECT, morphologyKernel);
168
163
  step = 'morphologyEx';
169
164
  reportStage(step);
170
- react_native_fast_opencv_1.OpenCV.invoke('morphologyEx', thresh, mat, react_native_fast_opencv_1.MorphTypes.MORPH_CLOSE, element);
171
- // Apply Gaussian blur before Canny for smoother edges
172
- const gaussianKernel = react_native_fast_opencv_1.OpenCV.createObject(react_native_fast_opencv_1.ObjectType.Size, 5, 5);
173
- step = 'GaussianBlur';
174
- reportStage(step);
175
- react_native_fast_opencv_1.OpenCV.invoke('GaussianBlur', mat, mat, gaussianKernel, 0);
176
- // Use higher Canny thresholds for cleaner edges
165
+ react_native_fast_opencv_1.OpenCV.invoke('morphologyEx', mat, mat, react_native_fast_opencv_1.MorphTypes.MORPH_CLOSE, element);
166
+ // Canny edge detection with optimized thresholds
177
167
  step = 'Canny';
178
168
  reportStage(step);
179
169
  react_native_fast_opencv_1.OpenCV.invoke('Canny', mat, mat, 50, 150);
170
+ // Dilate edges slightly to connect nearby contours
171
+ step = 'dilate';
172
+ reportStage(step);
173
+ const dilateKernel = react_native_fast_opencv_1.OpenCV.createObject(react_native_fast_opencv_1.ObjectType.Size, 2, 2);
174
+ const dilateElement = react_native_fast_opencv_1.OpenCV.invoke('getStructuringElement', react_native_fast_opencv_1.MorphShapes.MORPH_RECT, dilateKernel);
175
+ react_native_fast_opencv_1.OpenCV.invoke('dilate', mat, mat, dilateElement);
180
176
  step = 'createContours';
181
177
  reportStage(step);
182
178
  const contours = react_native_fast_opencv_1.OpenCV.createObject(react_native_fast_opencv_1.ObjectType.PointVectorOfVectors);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-rectangle-doc-scanner",
3
- "version": "0.27.0",
3
+ "version": "0.28.0",
4
4
  "main": "dist/index.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "repository": {
@@ -167,38 +167,33 @@ export const DocScanner: React.FC<Props> = ({
167
167
  reportStage(step);
168
168
  OpenCV.invoke('cvtColor', mat, mat, ColorConversionCodes.COLOR_BGR2GRAY);
169
169
 
170
- // Apply bilateral filter for better edge preservation
171
- step = 'bilateralFilter';
172
- reportStage(step);
173
- const filtered = OpenCV.createObject(ObjectType.Mat);
174
- OpenCV.invoke('bilateralFilter', mat, filtered, 9, 75, 75);
175
-
176
- // Use adaptive threshold for better contrast in varying lighting
177
- step = 'adaptiveThreshold';
170
+ // Apply Gaussian blur to reduce noise
171
+ const gaussianKernel = OpenCV.createObject(ObjectType.Size, 5, 5);
172
+ step = 'GaussianBlur';
178
173
  reportStage(step);
179
- const thresh = OpenCV.createObject(ObjectType.Mat);
180
- OpenCV.invoke('adaptiveThreshold', filtered, thresh, 255, 1, 1, 11, 2);
174
+ OpenCV.invoke('GaussianBlur', mat, mat, gaussianKernel, 0);
181
175
 
182
- // Morphological operations to clean up noise
176
+ // Morphological operations to enhance edges
183
177
  const morphologyKernel = OpenCV.createObject(ObjectType.Size, 3, 3);
184
178
  step = 'getStructuringElement';
185
179
  reportStage(step);
186
180
  const element = OpenCV.invoke('getStructuringElement', MorphShapes.MORPH_RECT, morphologyKernel);
187
181
  step = 'morphologyEx';
188
182
  reportStage(step);
189
- OpenCV.invoke('morphologyEx', thresh, mat, MorphTypes.MORPH_CLOSE, element);
190
-
191
- // Apply Gaussian blur before Canny for smoother edges
192
- const gaussianKernel = OpenCV.createObject(ObjectType.Size, 5, 5);
193
- step = 'GaussianBlur';
194
- reportStage(step);
195
- OpenCV.invoke('GaussianBlur', mat, mat, gaussianKernel, 0);
183
+ OpenCV.invoke('morphologyEx', mat, mat, MorphTypes.MORPH_CLOSE, element);
196
184
 
197
- // Use higher Canny thresholds for cleaner edges
185
+ // Canny edge detection with optimized thresholds
198
186
  step = 'Canny';
199
187
  reportStage(step);
200
188
  OpenCV.invoke('Canny', mat, mat, 50, 150);
201
189
 
190
+ // Dilate edges slightly to connect nearby contours
191
+ step = 'dilate';
192
+ reportStage(step);
193
+ const dilateKernel = OpenCV.createObject(ObjectType.Size, 2, 2);
194
+ const dilateElement = OpenCV.invoke('getStructuringElement', MorphShapes.MORPH_RECT, dilateKernel);
195
+ OpenCV.invoke('dilate', mat, mat, dilateElement);
196
+
202
197
  step = 'createContours';
203
198
  reportStage(step);
204
199
  const contours = OpenCV.createObject(ObjectType.PointVectorOfVectors);