iPhone을 사용하여 카메라 입력에서 일부 삼각형 패턴을 감지하고 싶습니다. AVFoundation을 사용하여 QR/바코드를 감지 할 수있는 몇 가지 예제 코드를 발견했습니다. 주요 부분은 AVMetadataMachineReadableCodeObject 클래스 인 것 같습니다. 위의 코드에서iOS AVFoundation 용 사용자 정의 감지기를 정의하는 방법은 무엇입니까?
func captureOutput(captureOutput: AVCaptureOutput!, didOutputMetadataObjects metadataObjects: [AnyObject]!, fromConnection connection: AVCaptureConnection!) {
// Check if the metadataObjects array is not nil and it contains at least one object.
if metadataObjects == nil || metadataObjects.count == 0 {
qrCodeFrameView?.frame = CGRectZero
messageLabel.text = "No barcode/QR code is detected"
return
}
// Get the metadata object.
let metadataObj = metadataObjects[0] as! AVMetadataMachineReadableCodeObject
// Here we use filter method to check if the type of metadataObj is supported
// Instead of hardcoding the AVMetadataObjectTypeQRCode, we check if the type
// can be found in the array of supported bar codes.
if supportedBarCodes.contains(metadataObj.type) {
// if metadataObj.type == AVMetadataObjectTypeQRCode {
// If the found metadata is equal to the QR code metadata then update the status label's text and set the bounds
let barCodeObject = videoPreviewLayer?.transformedMetadataObjectForMetadataObject(metadataObj)
qrCodeFrameView?.frame = barCodeObject!.bounds
if metadataObj.stringValue != nil {
messageLabel.text = metadataObj.stringValue
}
}
, QR 코드가 감지되면, 경계 상자가 그려 질과 텍스트 필드가 업데이트됩니다 여기에 AppCoda에서 몇 가지 예제 코드입니다. 마찬가지로 AVMetadataFaceObject 클래스는 얼굴 인식 응용 프로그램에서 사용됩니다. 참조에서 두 클래스 모두 AVMetadataObject의 하위 클래스라는 것을 알았습니다.
AVMetadataObject의 하위 클래스를 작성하여 삼각형 탐지기를 사용자 정의 할 수 있는지 궁금합니다. 예를 들어 AVMetadataTriangleObject 하위 클래스를 호출합니다. (나는 쉽게 사용할 수있는 탐지 알고리즘을 가지고 있고 Matlab로 작성된 코드를 가지고있다. 이것을 신속하게 말하면 힘들지 않을 것이다.)이 접근법이 가능하지 않다면 위의 목표를 달성하기위한 다른 방법을 제안 할 수 있는가?
정말 고마워요!
빠른 응답을 위해 Rhythmic에게 감사드립니다. 이제는'CMSampleBuffer'를 살펴 보겠습니다. – waterworld