Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Sep 5, 2025

The OpenCV.js library includes QR code detection functionality (cv.QRCodeDetector and cv.QRCodeDetectorAruco), but these classes were missing from the TypeScript definitions, preventing developers from using them with proper type checking and IntelliSense support.

This PR adds comprehensive TypeScript definitions for:

  • QRCodeDetector - Standard QR code detection and decoding
  • QRCodeDetectorAruco - Aruco-based QR code detection for improved robustness
  • QRCodeDetectorAruco_Params - Configuration parameters for Aruco detection

Key Features Added

All standard QR code detection methods are now properly typed:

  • detect() - Detect QR codes and return corner points
  • decode() - Decode a previously detected QR code
  • detectAndDecode() - Detect and decode in one step
  • detectMulti() / decodeMulti() / detectAndDecodeMulti() - Handle multiple QR codes
  • Proper memory management with delete() method

Comprehensive Testing

The implementation includes both API verification tests and functional tests with real QR code images:

  • API Tests: Verify all classes and methods are properly exposed
  • Functional Tests: Use an actual QR code image to test detection and decoding functionality
  • Integration Tests: Demonstrate proper image loading, format conversion, and memory management
// Example of functional test
const detector = new cv.QRCodeDetector();
const jimpSrc = await Jimp.read("test-qr.png");
const img = cv.matFromImageData(jimpSrc.bitmap);
const imgBGR = new cv.Mat();
cv.cvtColor(img, imgBGR, cv.COLOR_RGBA2BGR);

const points = new cv.Mat();
const decodedText = detector.detectAndDecode(imgBGR, points);
expect(decodedText).toBe("Hello OpenCV.js QR Test!");

Usage Example

import cvReadyPromise from "@techstark/opencv-js";

async function detectQRCode() {
  const cv = await cvReadyPromise;
  
  // TypeScript now provides full IntelliSense support
  const detector = new cv.QRCodeDetector();
  const points = new cv.Mat();
  
  // All methods have proper type checking
  const decoded: string = detector.detectAndDecode(image, points);
  
  // For multiple QR codes
  const arucoDetector = new cv.QRCodeDetectorAruco();
  const decodedInfo: string[] = [];
  const found: boolean = arucoDetector.detectAndDecodeMulti(image, decodedInfo);
  
  detector.delete();
  arucoDetector.delete();
}

The implementation follows existing patterns in the codebase and includes 23 comprehensive tests that verify both API availability and actual QR code detection functionality. All tests pass, confirming that existing functionality remains unaffected.

Fixes #35.


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

Copilot AI and others added 2 commits September 5, 2025 03:37
Co-authored-by: ttt43ttt <132509+ttt43ttt@users.noreply.github.com>
Co-authored-by: ttt43ttt <132509+ttt43ttt@users.noreply.github.com>
Copilot AI changed the title [WIP] does it support qrcode reader? Add TypeScript definitions for QRCodeDetector and QRCodeDetectorAruco Sep 5, 2025
Copilot AI requested a review from ttt43ttt September 5, 2025 03:39
@ttt43ttt
Copy link
Contributor

ttt43ttt commented Sep 5, 2025

@copilot needs to add more tests: add an image that contains a QR code and detect & decode the QR code from it

Co-authored-by: ttt43ttt <132509+ttt43ttt@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Sep 5, 2025

@copilot needs to add more tests: add an image that contains a QR code and detect & decode the QR code from it

Added comprehensive functional tests that use a real QR code image. The tests now include:

  • A test QR code image containing "Hello OpenCV.js QR Test!"
  • Functional test for detectAndDecode() method that verifies the decoded text matches the expected content
  • Functional test for detect() method that verifies corner points are detected correctly
  • Functional test for decode() method using previously detected points
  • Additional test for QRCodeDetectorAruco detector with the same QR code image

All tests pass and demonstrate that both QRCodeDetector and QRCodeDetectorAruco can successfully detect and decode QR codes from real images.

Commit: 3036fef

Copilot AI changed the title Add TypeScript definitions for QRCodeDetector and QRCodeDetectorAruco Add TypeScript definitions for QRCodeDetector and QRCodeDetectorAruco with comprehensive tests Sep 5, 2025
@ttt43ttt ttt43ttt marked this pull request as ready for review September 5, 2025 06:30
@ttt43ttt ttt43ttt merged commit 1871ae4 into main Sep 5, 2025
3 checks passed
@ttt43ttt ttt43ttt deleted the copilot/fix-35 branch September 5, 2025 06:39
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.

does it support qrcode reader?

2 participants