我正在開發一種檢測ID卡的應用程序,並試圖使用內置於ios中的CIDetector在實時預覽中檢測矩形形狀對象。我使用該解決方案在本教程中解釋這裏 CoreImage Detectors如何使用CIDetector和Swift在圖像中裁剪檢測到的矩形
我得到流動結果 image
我的問題:有沒有辦法來提取和作物的檢測長方形?
我正在開發一種檢測ID卡的應用程序,並試圖使用內置於ios中的CIDetector在實時預覽中檢測矩形形狀對象。我使用該解決方案在本教程中解釋這裏 CoreImage Detectors如何使用CIDetector和Swift在圖像中裁剪檢測到的矩形
我得到流動結果 image
我的問題:有沒有辦法來提取和作物的檢測長方形?
func cropBusinessCardForPoints(image: CIImage, topLeft: CGPoint, topRight: CGPoint, bottomLeft: CGPoint, bottomRight: CGPoint) -> CIImage {
var businessCard: CIImage
businessCard = image.imageByApplyingFilter(
"CIPerspectiveTransformWithExtent",
withInputParameters: [
"inputExtent": CIVector(CGRect: image.extent),
"inputTopLeft": CIVector(CGPoint: topLeft),
"inputTopRight": CIVector(CGPoint: topRight),
"inputBottomLeft": CIVector(CGPoint: bottomLeft),
"inputBottomRight": CIVector(CGPoint: bottomRight)])
businessCard = image.imageByCroppingToRect(businessCard.extent)
return businessCard
}
夫特3,簡單的解決方案
讓faceScanningArea =的CGRect(X:0,Y:0,寬度:50,高度:50)
theFaceFrame.image = UIImage的(cgImage(orginalImage .image?.cgImage)!裁剪(到:faceScanningArea)!)