1

iOS を 7.0.6 から 7.1.0 にアップグレードした後、問題が発生しています。iOS 7.1 を実行している iPhone 4s、5、5c、または 5s では、この問題は見られません。カメラの初期化コードを投稿しています:

- (void)initCapture
{
    //Setting up the AVCaptureDevice (camera)
    AVCaptureDevice* inputDevice = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeVideo];

    NSError* cameraError;
    if ([inputDevice lockForConfiguration:&cameraError])
    {
        if ([inputDevice isFocusModeSupported:AVCaptureFocusModeContinuousAutoFocus])
        {
            NSLog(@"AVCaptureDevice is set to video with continuous auto focus");
            CGPoint autofocusPoint = CGPointMake(0.5f, 0.5f);
            [inputDevice setFocusPointOfInterest:autofocusPoint];
            [inputDevice setFocusMode:AVCaptureFocusModeContinuousAutoFocus];
        }

        [inputDevice unlockForConfiguration];
    }

    //setting up the input streams
    AVCaptureDeviceInput *captureInput = [AVCaptureDeviceInput deviceInputWithDevice:inputDevice error:nil];

    //setting up up the AVCaptureVideoDataOutput
    AVCaptureVideoDataOutput *captureOutput = [[AVCaptureVideoDataOutput alloc] init];
    captureOutput.alwaysDiscardsLateVideoFrames = YES;
    [captureOutput setSampleBufferDelegate:self queue:dispatch_get_main_queue()];

    //setting up video settings
    NSString* key = (NSString*)kCVPixelBufferPixelFormatTypeKey;
    NSNumber* value = [NSNumber numberWithUnsignedInt:kCVPixelFormatType_32BGRA];
    NSDictionary* videoSettings = [NSDictionary dictionaryWithObject:value forKey:key];

    //passing the settings to the AVCaptureVideoDataOutput
[captureOutput setVideoSettings:videoSettings];

    //setting up the AVCaptureSession
    captureSession = [[AVCaptureSession alloc] init];
    captureSession.sessionPreset = AVCaptureSessionPresetMedium;

    [captureSession addInput:captureInput];
    [captureSession addOutput:captureOutput];

    if (!prevLayer)
{
        prevLayer = [AVCaptureVideoPreviewLayer layerWithSession:captureSession];
    }
    NSLog(@"initCapture preview Layer %p %@", self.prevLayer, self.prevLayer);
    self.prevLayer.frame = self.view.bounds;
    self.prevLayer.videoGravity = AVLayerVideoGravityResizeAspectFill;
    [self.view.layer addSublayer: self.prevLayer];

    [self.captureSession startRunning];
}

どんな助けでも大歓迎です...

4

4 に答える 4

1

このスレッドを閉じるために、libzxing に加えて QR コードのスキャンにカメラを使用していました。以前の AVCaptureVideoDataOutputSampleBufferDelegate の代わりに、ネイティブの iOS 7.0 AVCaptureMetadataOutputObjectsDelegate を実装することにしました。メタデータ デリゲートははるかにシンプルでクリーンです。http://nshipster.com/ios7/の例が非常に役立ちます。

于 2014-04-10T20:39:05.780 に答える
1

あなたが使用している Apple 提供のコードは古くなっています - 彼らは今それを完全に書き直しました。運を試して、新しいワークフローに進みます。

ここでチェックしてください

于 2014-04-08T17:14:17.717 に答える
0

libzxing の何かがリフォーカスを妨げているという neuman8 のコメントに続いて、私は自分で調査を

行い、Decoder.mm ファイルの次の行が原因であることがわかりました。

ArrayRef<char> subsetData (subsetBytesPerRow * subsetHeight);

ArrayRef は、指定されたサイズの配列を割り当てようとする zxing/common/Array.h ファイル内のクラスのようです。何も悪いことをしているようには見えませんでしたが、約 170k の char 要素配列の割り当てに時間がかかり、他のスレッドの実行を妨げるほどブロッキング呼び出しが遅くなる原因になっているのではないかと推測しました。

そこで、仮説を検証するために力ずくのソリューションを入れようとしました。割り当て直後にスリープを追加しました。

[NSThread sleepForTimeInterval:0.02];

カメラは再び焦点を合わせ始め、QRコードを解読することができました.

これを解決するためのより良い方法をまだ見つけることができません。大きな配列のより効率的な割り当てを把握できる人、またはカメラ フォーカスのスレッドを生成するよりエレガントな方法を持っている人はいますか?
それ以外の場合は、醜い場合でも、これで問題は解決するはずです。

于 2014-08-23T04:47:29.767 に答える