Skip to content
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

Quad drawing off #383

Closed
nichita-stefanita opened this issue May 22, 2024 · 1 comment
Closed

Quad drawing off #383

nichita-stefanita opened this issue May 22, 2024 · 1 comment
Labels

Comments

@nichita-stefanita
Copy link

Disclaimer: it's most likely not an issue with the library but I hope someone could give me an idea of what the issue is, with a bit of context.

Note: My project written on SwiftUI, but camera module is using UIKit and integrated via UIViewControllerRepresentable.

I didn't add weScan as a dependency, but only added the Rectangle detection and quad drawing features. And somehow my quad coordinates are way off and do not represent what the user sees from the videoPreviewLayer.

I've only managed to "correct" that by changing the rotation angle in CGAffineTransform from 90 to 180 degrees and swapping imageSize.width and imageSize.height:

let portraitImageSize = CGSize(width: imageSize.width, height: imageSize.height)

let scaleTransform = CGAffineTransform.scaleTransform(forSize: portraitImageSize, aspectFillInSize: quadView.bounds.size)
        
let scaledImageSize = imageSize.applying(scaleTransform)
        
let rotationTransform = CGAffineTransform(rotationAngle: CGFloat.pi * 2)

let imageBounds = CGRect(origin: .zero, size: scaledImageSize).applying(rotationTransform)
let translationTransform = CGAffineTransform.translateTransform(fromCenterOfRect: imageBounds, toCenterOfRect: quadView.bounds)

let transforms = [scaleTransform, rotationTransform, translationTransform]

let transformedQuad = quad.applyTransforms(transforms)

quadView.drawQuadrilateral(quad: transformedQuad, animated: true)

It now displays the quad as expected, but I still don't understand what causes that deviation and why the original calculus doesn't apply in my case.

Copy link

This issue is stale because it has been open for 30 days with no activity. Remove the Stale label or comment or this will be closed in 10 days.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant