iPhoneを使ってカメラの入力からいくつかの三角形のパターンを検出したいと思います。私は、AVFoundationを使ってQR /バーコードを検出できるコード例をいくつか見つけました。主要な部分はAVMetadataMachineReadableCodeObjectクラスのようです。ここにAppCodaからいくつかのサンプルコードは次のとおりです。上記のコードで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コードが検出されると、境界ボックスが描画され、テキストフィールドが更新されます。同様に、AVMetadataFaceObjectクラスは顔検出アプリケーションで使用されます。私は両方のクラスがAVMetadataObjectのサブクラスであることを参照から分かりました。
AVMetadataObjectのサブクラスを記述することで三角形検出器をカスタマイズすることが可能かどうか、私たちはサブクラスAVMetadataTriangleObjectを呼び出します。 (私は容易に利用可能な検出アルゴリズムを持っており、Matlabで書かれたコードを持っています。これを速やかに転記するのは厳しいべきではありません。)このアプローチが不可能な場合は、誰でも上記の目標を達成するための別の方法を提案できますか?
ありがとうございました!
迅速な対応のためにリズミックに感謝します。今度は 'CMSampleBuffer'を調べます。 – waterworld