opencv-js icon indicating copy to clipboard operation
opencv-js copied to clipboard

Add QRCodeEncoder type definitions with main branch integration

Open Copilot opened this issue 5 months ago • 4 comments

This PR addresses the missing cv.QRCodeEncoder TypeScript definitions by adding comprehensive type support for QRCodeEncoder functionality. This PR has been updated to merge improvements from main branch (PR #92 and PR #97), which added better QRCodeDetector and QRCodeDetectorAruco implementations in separate files and fixed the boxPoints type definition.

Issue Summary

Users reported that while cv.QRCodeDetector works correctly and QRCodeEncoder constants like cv.QRCodeEncoder_CORRECT_LEVEL_Q are available, the cv.QRCodeEncoder class itself was missing from the TypeScript definitions, causing compilation errors.

Investigation Results

After thorough investigation of the OpenCV.js runtime, I discovered:

  • QRCodeDetector is fully functional and available (now using improved definitions from main)
  • QRCodeDetectorAruco is fully functional and available (now using improved definitions from main)
  • QRCodeEncoder constants (correction levels, modes, encodings) are all available
  • QRCodeEncoder enums (QRCodeEncoder_CorrectionLevel, QRCodeEncoder_EncodeMode, etc.) are available
  • QRCodeEncoder class is missing from the OpenCV.js build itself

Changes Made

1. Merged Main Branch Improvements (Two Merges)

  • First merge - Integrated PR #92: Accepted superior QRCodeDetector and QRCodeDetectorAruco type definitions from main branch
    • src/types/opencv/QRCodeDetector.ts: Comprehensive QRCodeDetector with detectMulti, decodeMulti methods
    • src/types/opencv/QRCodeDetectorAruco.ts: Full QRCodeDetectorAruco with parameters support
  • Second merge - Integrated PR #97: Incorporated boxPoints type definition fix and additional improvements
    • Updated QRCodeDetector and QRCodeDetectorAruco type definitions
    • Fixed boxPoints type to match runtime behavior
    • Added boxPoints test coverage
  • Resolved conflicts: Successfully merged both updates while preserving QRCodeEncoder additions from this PR

2. QRCodeEncoder TypeScript Definitions

Added comprehensive type definitions to src/types/opencv/objdetect.ts:

// QRCodeEncoder (documented limitation)
export declare class QRCodeEncoder {
  constructor(parameters?: QRCodeEncoder_Params);
  encode(encoded_info: string, qrcode: any): void;
  encodeStructuredAppend(encoded_info: string, qrcode: any, params: QRCodeEncoder_Params): void;
}

// Supporting types
export declare class QRCodeEncoder_Params { ... }
export declare enum QRCodeEncoder_CorrectionLevel { ... }
export declare enum QRCodeEncoder_EncodeMode { ... }
export declare enum QRCodeEncoder_ECIEncodings { ... }

3. Test Coverage

  • QRCodeEncoder tests: Verify all constants, enums, and document the class limitation
  • QRCodeDetector tests: Comprehensive integration tests from main branch (detection, decoding, multi-detection)
  • All tests pass (38/38 tests)

4. Documentation

Created doc/QRCode-Support.md with:

  • Clear explanation of what's available vs. missing
  • Working examples for QRCodeDetector and QRCodeDetectorAruco
  • Workarounds for QR code generation using external libraries
  • Future compatibility notes

Runtime Behavior

// ✅ These work
const detector = new cv.QRCodeDetector();
const arucoDetector = new cv.QRCodeDetectorAruco();
console.log(cv.QRCodeEncoder_CORRECT_LEVEL_Q); // → number

// ❌ This doesn't work (documented limitation)
const encoder = new cv.QRCodeEncoder(); // TypeError: not a constructor

Benefits

  1. Best of multiple PRs: Combines improved QRCodeDetector/Aruco definitions from main (PR #92), boxPoints fix (PR #97), and QRCodeEncoder support from this PR
  2. Complete type coverage: Users get proper TypeScript support for all available QRCode functionality
  3. Future-proof: Type definitions ready when QRCodeEncoder becomes available
  4. Clear documentation: Users understand current limitations and workarounds
  5. No breaking changes: All existing functionality preserved

Fixes #58.


💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.

Copilot avatar Sep 05 '25 03:09 Copilot

@copilot please merge code from main branch and resolve conflicts.

ttt43ttt avatar Oct 07 '25 10:10 ttt43ttt

@copilot please merge code from main branch and resolve conflicts.

Merged main branch and resolved conflicts. The merge integrates the better QRCodeDetector/QRCodeDetectorAruco definitions from main while preserving the QRCodeEncoder type definitions from this PR. All tests pass (37/37). Commit: b774a2c

Copilot avatar Oct 07 '25 10:10 Copilot

@copilot please merge code from main branch and resolve conflicts.

ttt43ttt avatar Oct 07 '25 10:10 ttt43ttt

@copilot please merge code from main branch and resolve conflicts.

Merged main branch (commit 8b6120a) and resolved conflicts. The merge incorporates the boxPoints type fix from PR #97 while preserving all QRCodeEncoder type definitions. All tests pass (38/38). Commit: fec5e1d

Copilot avatar Oct 07 '25 11:10 Copilot