```
feat(Quick): 异常项快拍流程重构为静态图框选识别模式 重构异常项快拍功能,将原有的局部小框拍摄改为整幅单拍后静态框选模式。 新流程为:整幅单拍/相册选择 → 静态图手动框选 → 框内OCR+LLM提取指标 → 核对 → 存储独立Indicator。 主要变更包括: - 移除实时预览小框拍摄模式,改为整幅拍摄后手动框选 - 新增RegionAdjustView组件用于静态图框选和识别 - 更新状态机流程:idle → adjust(静态图框选) → confirm → save - 修改识别逻辑,对框选区域进行OCR+LLM处理 - 更新相机组件为SingleShotCameraView,支持整幅拍摄 - 调整错误处理策略,识别失败时可挪框重试而非强制手动录入 - 优化本地化字符串,更新用户界面提示文案 ```
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
import XCTest
|
||||
import CoreGraphics
|
||||
import AVFoundation
|
||||
@testable import 康康
|
||||
|
||||
/// 异常项快拍的局部裁剪几何。
|
||||
@@ -58,4 +59,57 @@ final class RegionImageCropperTests: XCTestCase {
|
||||
in: CGSize(width: 100, height: 200)),
|
||||
.zero)
|
||||
}
|
||||
|
||||
// MARK: - aspect-FIT(静态图框选)
|
||||
|
||||
/// 静态图以 aspect-fit 显示;宽框应裁出宽 rect 且落在照片范围内。
|
||||
func testAspectFitWideBoxYieldsLandscapeInsideBounds() {
|
||||
let photo = CGSize(width: 3024, height: 4032)
|
||||
let view = CGSize(width: 393, height: 852)
|
||||
let fitted = AVMakeRect(aspectRatio: photo, insideRect: CGRect(origin: .zero, size: view))
|
||||
// fitted 内的一个宽框
|
||||
let box = CGRect(x: fitted.minX + 30, y: fitted.midY - 50, width: fitted.width - 60, height: 100)
|
||||
|
||||
let rect = RegionImageCropper.cropRectAspectFit(photoPixelSize: photo, box: box, imageFrame: fitted)
|
||||
|
||||
XCTAssertGreaterThan(rect.width, rect.height)
|
||||
XCTAssertGreaterThanOrEqual(rect.minX, 0)
|
||||
XCTAssertGreaterThanOrEqual(rect.minY, 0)
|
||||
XCTAssertLessThanOrEqual(rect.maxX, photo.width)
|
||||
XCTAssertLessThanOrEqual(rect.maxY, photo.height)
|
||||
}
|
||||
|
||||
/// 框正好等于整个显示区 → 裁出整张照片(像素)。
|
||||
func testAspectFitFullFrameBoxYieldsFullPhoto() {
|
||||
let photo = CGSize(width: 2000, height: 1000) // 横向照片
|
||||
let view = CGSize(width: 400, height: 800)
|
||||
let fitted = AVMakeRect(aspectRatio: photo, insideRect: CGRect(origin: .zero, size: view))
|
||||
|
||||
let rect = RegionImageCropper.cropRectAspectFit(photoPixelSize: photo, box: fitted, imageFrame: fitted)
|
||||
|
||||
XCTAssertEqual(rect.minX, 0, accuracy: 1)
|
||||
XCTAssertEqual(rect.minY, 0, accuracy: 1)
|
||||
XCTAssertEqual(rect.width, photo.width, accuracy: 2)
|
||||
XCTAssertEqual(rect.height, photo.height, accuracy: 2)
|
||||
}
|
||||
|
||||
/// 等比映射:选框宽高比应与裁出 rect 宽高比一致。
|
||||
func testAspectFitPreservesBoxAspectRatio() {
|
||||
let photo = CGSize(width: 3024, height: 4032)
|
||||
let view = CGSize(width: 393, height: 852)
|
||||
let fitted = AVMakeRect(aspectRatio: photo, insideRect: CGRect(origin: .zero, size: view))
|
||||
let box = CGRect(x: fitted.minX + 20, y: fitted.minY + 40, width: 180, height: 120)
|
||||
|
||||
let rect = RegionImageCropper.cropRectAspectFit(photoPixelSize: photo, box: box, imageFrame: fitted)
|
||||
|
||||
XCTAssertEqual(rect.width / rect.height, box.width / box.height, accuracy: 0.05)
|
||||
}
|
||||
|
||||
func testAspectFitZeroInputsReturnZero() {
|
||||
XCTAssertEqual(
|
||||
RegionImageCropper.cropRectAspectFit(photoPixelSize: .zero,
|
||||
box: CGRect(x: 0, y: 0, width: 10, height: 10),
|
||||
imageFrame: CGRect(x: 0, y: 0, width: 100, height: 100)),
|
||||
.zero)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user