-
-
Notifications
You must be signed in to change notification settings - Fork 92
Implement preprocessing pipeline with addBorder preprocessor #626
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
base: master
Are you sure you want to change the base?
Conversation
Change Log for @ericblade/quagga2 (1.10.2 → 1.11.0)New Features
|
Co-authored-by: ericblade <[email protected]>
Co-authored-by: ericblade <[email protected]>
…rcode Co-authored-by: ericblade <[email protected]>
Co-authored-by: ericblade <[email protected]>
package.json
Outdated
| "ndarray-linear-interpolate": "^1.0.0", | ||
| "ndarray-pixels": "^5.0.1", | ||
| "nyc": "^17.1.0", | ||
| "sharp": "^0.34.5", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is sharp necessary? doesn't sharp require native code? or is there a browser version of it now?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removed sharp from package.json in commit d88f28a. It was installed during initial development for test image creation but is not used by the library code.
src/preprocessing/index.ts
Outdated
| @@ -0,0 +1,6 @@ | |||
| export type { PreprocessorFunction } from './preprocessor'; | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what is the purpose of this file?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added a comment explaining its purpose in d88f28a. It's a standard barrel file that re-exports the public API of the preprocessing module, allowing users to import from './preprocessing' rather than './preprocessing/preprocessor'.
src/preprocessing/preprocessor.ts
Outdated
| * @param imageWrapper The image wrapper to process | ||
| * @returns The processed image wrapper (same size as input) | ||
| */ | ||
| export type PreprocessorFunction = (imageWrapper: ImageWrapper) => ImageWrapper; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would it be generally faster if we expected the user to operate on the existing imagewrapper, or would that be more likely that we'd just have the user making copies of the image in memory anyway?
Does returning it automatically imply a copy? I think we need to do whatever encourages the user to make this operation as fast as possible.
Also, since this will be in the public interface, and people will be writing external libraries of these functions potentially, I'd like it to have a name that more accurately describes what this is for, like QuaggaImagePreprocessor ... something like that... ideas?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Renamed to QuaggaImagePreprocessor and updated the documentation to clarify that preprocessors should modify the imageWrapper in place and return the same instance. This avoids unnecessary memory allocations and copies. The return value enables chaining but the actual implementation modifies in place. Updated in d88f28a.
type-definitions/quagga.d.ts
Outdated
| * that would naturally exist when displaying the barcode on paper or screen. | ||
| * @default 0 (no border added) | ||
| */ | ||
| addBorder?: number; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this part of the code was dropped, wasn't it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, the addBorder option in inputStream config was intentionally removed. We replaced it with the more flexible preprocessing array approach, which allows users to chain multiple preprocessors including Quagga.Preprocessors.addBorder(size). The new approach is more extensible for future preprocessors.
|
@copilot it does look like the new tests are not running in browser. Please make sure that the new tests are added to the .cy.ts files to run in browser .. and while we're at it, we probably need to audit the rest of the .spec. files to make sure we've got browser running all of the ones from the last few days worth of changes. |
…agePreprocessor, clarify in-place modification Co-authored-by: ericblade <[email protected]>
Co-authored-by: ericblade <[email protected]>
Added the preprocessing tests to Cypress browser test suites in commit 439c2d5:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR implements a preprocessing pipeline that allows image transformations to be applied after frame grabbing but before barcode localization and decoding. The primary use case is adding white borders to barcodes that lack proper quiet zones (whitespace), which previously caused decode failures.
Key changes:
- Added preprocessing infrastructure with
QuaggaImagePreprocessortype andapplyPreprocessorsfunction - Implemented
addBorderpreprocessor using bilinear interpolation to shrink and center images with white borders - Integrated preprocessing into the Quagga update loop at the appropriate stage
Reviewed changes
Copilot reviewed 8 out of 10 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| type-definitions/quagga.d.ts | Added type definitions for QuaggaImagePreprocessor, Preprocessors namespace, preprocessing config option, and updated ImageWrapper.inImageWithBorder signature |
| src/preprocessing/preprocessor.ts | Core implementation of preprocessing system including addBorder factory function and applyPreprocessors utility |
| src/preprocessing/index.ts | Barrel file exporting public preprocessing API |
| src/quagga/quagga.ts | Integrated preprocessing application into the update loop for both UI and non-UI thread paths |
| src/quagga.js | Added Preprocessors to the public API exports |
| src/preprocessing/test/preprocessor.spec.ts | Unit tests for preprocessing functions covering edge cases and behavior verification |
| test/integration/preprocessor.spec.ts | Integration tests verifying real barcode decode failure without preprocessing and success with addBorder(20) |
| cypress/e2e/universal.cy.ts | Added preprocessing unit tests to Cypress universal test suite |
| cypress/e2e/integration.cy.ts | Added preprocessing integration tests to Cypress integration test suite |
| test/fixtures/preprocessors/whitespace/no-whitespace-barcode.gif | Test fixture containing the problematic barcode from issue #409 |
|
@copilot looks like we're going to need /docs on the new feature, at the very least a how-to on creating new processors, updates to the configuration on using the processors, and does perhaps the technical guide need some info as well? probably all 4 of the main sections could use some explanation on this feature, i'd think |
Added comprehensive preprocessing documentation to README.md in e5161d4:
|
…rbs) Co-authored-by: ericblade <[email protected]>
|
@copilot Cypress tests are failing without obvious reason: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.
…r browser environment Co-authored-by: ericblade <[email protected]>
ericblade
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Comprehensive documentation belongs in the 4 sections in /docs, not in the README.
Do we need to also update copilot-instructions.md to document that the documentation for new features and changes should live in /docs, and should adhere to the Divio Documentation System? Do we need to document how the Divio documentation system works, and how it is used in /docs in this project?
…io system Co-authored-by: ericblade <[email protected]>
Moved comprehensive documentation to /docs following Divio system in c346a17:
Regarding copilot-instructions.md - that would be a good addition to document the Divio system convention. Want me to add that as a separate task? |
@copilot yes please update that file, in such a way that you will easily understand how to update the documentation in /docs again anytime you are editing or creating features |
Co-authored-by: ericblade <[email protected]>
Added Divio documentation system guidelines to
|
|
|
||
| ### 1. Preprocessing {#preprocessing} | ||
|
|
||
| **Built-in preprocessing:** |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
isn't there a built-in config that also preprocesses down to a single channel? or does that just act upon only one channel, rather than altering the image wrapper?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, there's inputStream.singleChannel config option. When true, it uses only the red channel during grayscale conversion instead of the luminance formula. This happens during frame grabbing, not as a separate preprocessing step - it affects how RGB is converted to grayscale but doesn't alter the ImageWrapper structure. Clarified this in the docs in 01fd518.
| return imageWrapper; | ||
| }; | ||
| ``` | ||
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe could add a section for drawing on the overlay canvas for visualizing while using LiveStream or VideoStream input sources...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added "Visualizing with Overlay Canvas" section in 01fd518. Covers:
- Setting up the overlay canvas with LiveStream/VideoStream
- Drawing on the overlay via
onProcessedcallback - Example code for visualizing preprocessor effects by rendering grayscale data to the overlay
…y canvas visualization section Co-authored-by: ericblade <[email protected]>
|
when this is submitted, it will also close #433 |
PreprocessorFunctiontoQuaggaImagePreprocessorfor clearer public APIpreprocessingtopreprocessors(nouns not verbs)Original prompt
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.