Skip to content

Commit 24d9a23

Browse files
fix: 优化识别inset
1 parent b721be1 commit 24d9a23

1 file changed

Lines changed: 20 additions & 6 deletions

File tree

Source/ZYVisionRetangleDetector.swift

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ open class ZYVisionRetangleDetector {
2525
/// - Parameters:
2626
/// - clipImage: 图片
2727
/// - boxSize: imageview 大小
28+
/// - insets: 识别区域的内边距
2829
/// - result: 识别结果 在imageview里面的 有8个点, 前4个是 比例值, 后4个是确切值
2930
public static func visionImage(clipImage: UIImage,boxSize: CGSize, insets: UIEdgeInsets = .zero, result: @escaping VisionRetangleDetectorResult) {
3031

@@ -87,12 +88,25 @@ open class ZYVisionRetangleDetector {
8788

8889
func vnretanglePoints2ZYQuadranglePoints(rectangle: VNRectangleObservation, boxSize: CGSize) -> ((CGPoint, CGPoint, CGPoint, CGPoint), (CGPoint, CGPoint, CGPoint, CGPoint)) {
8990
let translateTransform = CGAffineTransform.identity.scaledBy(x: boxSize.width, y: boxSize.height)
90-
91-
let convertedTopLeft = CGPoint(x: rectangle.topLeft.x + self.insets.left, y: rectangle.topLeft.y + self.insets.top) .applying(translateTransform)
92-
let convertedTopRight = CGPoint(x: rectangle.topRight.x - self.insets.right, y: rectangle.topRight.y + self.insets.top).applying(translateTransform)
93-
let convertedBottomLeft = CGPoint(x: rectangle.bottomLeft.x + self.insets.left, y: rectangle.bottomLeft.y - self.insets.bottom).applying(translateTransform)
94-
let convertedBottomRight = CGPoint(x: rectangle.bottomRight.x - self.insets.right, y: rectangle.bottomRight.y - self.insets.bottom).applying(translateTransform)
95-
91+
print("vsion -> \(rectangle.topLeft)--\(rectangle.topRight)--\(rectangle.bottomLeft)--\(rectangle.bottomRight)")
92+
// let convertedTopLeft = CGPoint(x: rectangle.topLeft.x + self.insets.left, y: rectangle.topLeft.y + self.insets.top) .applying(translateTransform)
93+
// let convertedTopRight = CGPoint(x: rectangle.topRight.x - self.insets.right, y: rectangle.topRight.y + self.insets.top).applying(translateTransform)
94+
// let convertedBottomLeft = CGPoint(x: rectangle.bottomLeft.x + self.insets.left, y: rectangle.bottomLeft.y - self.insets.bottom).applying(translateTransform)
95+
// let convertedBottomRight = CGPoint(x: rectangle.bottomRight.x - self.insets.right, y: rectangle.bottomRight.y - self.insets.bottom).applying(translateTransform)
96+
97+
98+
var convertedTopLeft = rectangle.topLeft.applying(translateTransform)
99+
var convertedTopRight = rectangle.topRight.applying(translateTransform)
100+
var convertedBottomLeft = rectangle.bottomLeft.applying(translateTransform)
101+
var convertedBottomRight = rectangle.bottomRight.applying(translateTransform)
102+
103+
print("before inset = \(convertedTopLeft)--\(convertedTopRight)--\(convertedBottomLeft)--\(convertedBottomRight)")
104+
convertedTopLeft = CGPoint(x: convertedTopLeft.x + self.insets.left, y: convertedTopLeft.y + self.insets.top)
105+
convertedTopRight = CGPoint(x: convertedTopRight.x - self.insets.right, y: convertedTopRight.y + self.insets.top)
106+
convertedBottomLeft = CGPoint(x: convertedBottomLeft.x + self.insets.left, y: convertedBottomLeft.y - self.insets.bottom)
107+
convertedBottomRight = CGPoint(x: convertedBottomRight.x - self.insets.right, y: convertedBottomRight.y - self.insets.bottom)
108+
109+
print("aftet inset= \(convertedTopLeft)--\(convertedTopRight)--\(convertedBottomLeft)--\(convertedBottomRight)")
96110

97111
let fliptrans = CGAffineTransform.identity.scaledBy(x: 1, y: -1)
98112
fliptrans.translatedBy(x: 0, y: boxSize.height)

0 commit comments

Comments
 (0)