Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Sep 5, 2025

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 Add TypeScript definitions for QRCodeDetector and QRCodeDetectorAruco with comprehensive tests #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 Fix boxPoints type definition to match runtime behavior #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 Add TypeScript definitions for QRCodeDetector and QRCodeDetectorAruco with comprehensive tests #92), boxPoints fix (PR Fix boxPoints type definition to match runtime behavior #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 AI changed the title [WIP] no cv.QRCodeEncoder Add missing QRCode type definitions and comprehensive documentation Sep 5, 2025
Copilot AI requested a review from ttt43ttt September 5, 2025 03:39
@ttt43ttt
Copy link
Contributor

ttt43ttt commented Oct 7, 2025

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

# Conflicts:
#	src/types/opencv/objdetect.ts
#	test/QRCodeDetector.test.ts
Copy link
Contributor Author

Copilot AI commented Oct 7, 2025

@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 AI changed the title Add missing QRCode type definitions and comprehensive documentation Add QRCodeEncoder type definitions with main branch integration Oct 7, 2025
@ttt43ttt
Copy link
Contributor

ttt43ttt commented Oct 7, 2025

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

Copy link
Contributor Author

Copilot AI commented Oct 7, 2025

@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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

no cv.QRCodeEncoder

2 participants