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.
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:
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.