2016-11-16 7 views
0

における実際の製品のバーコードのために働いて、なくはないマギーなどのような実際の製品にAVCapturesessionは、バーコードスキャナは、Macの画面上で動作するiOSの

-(void)viewDidLoad 
{ 
    [super viewDidLoad]; 

    _highlightView = [[UIView alloc] init]; 
    _highlightView.autoresizingMask = UIViewAutoresizingFlexibleTopMargin|UIViewAutoresizingFlexibleLeftMargin|UIViewAutoresizingFlexibleRightMargin|UIViewAutoresizingFlexibleBottomMargin; 
    _highlightView.layer.borderColor = [UIColor greenColor].CGColor; 
    _highlightView.layer.borderWidth = 3; 
    [self.view addSubview:_highlightView]; 

    _label = [[UILabel alloc] init]; 
    _label.frame = CGRectMake(0, self.view.bounds.size.height - 40, self.view.bounds.size.width, 40); 
    _label.autoresizingMask = UIViewAutoresizingFlexibleTopMargin; 
    _label.backgroundColor = [UIColor colorWithWhite:0.15 alpha:0.65]; 
    _label.textColor = [UIColor whiteColor]; 
    _label.textAlignment = NSTextAlignmentCenter; 
    _label.text = @"(none)"; 
    [self.view addSubview:_label]; 

    _session = [[AVCaptureSession alloc] init]; 
    _device = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeVideo]; 
    NSError *error = nil; 

    _input = [AVCaptureDeviceInput deviceInputWithDevice:_device error:&error]; 
    if (_input) { 
     [_session addInput:_input]; 
    } else { 
     NSLog(@"Error: %@", error); 
    } 

    _output = [[AVCaptureMetadataOutput alloc] init]; 
    [_output setMetadataObjectsDelegate:self queue:dispatch_get_main_queue()]; 
    [_session addOutput:_output]; 

    _output.metadataObjectTypes = [_output availableMetadataObjectTypes]; 

    _prevLayer = [AVCaptureVideoPreviewLayer layerWithSession:_session]; 
    _prevLayer.frame = self.view.bounds; 
    _prevLayer.videoGravity = AVLayerVideoGravityResizeAspectFill; 
    [self.view.layer addSublayer:_prevLayer]; 

    [_session startRunning]; 

    [self.view bringSubviewToFront:_highlightView]; 
    [self.view bringSubviewToFront:_label]; 
} 

は問題がありますか?私はavcapturesession、AVmetadataoutputなどのコードをほとんど使用していますが、lcd画面でのみ読み込みます。

答えて

0

_output.metadataObjectTypesを確認するには、その中にすべてのタイプのバーコードを追加する必要があります。例えば(EAN8、EAN13 ..... e.t.c)

+0

おかげSagarのようなあなたのAVCaptureMetadataOutputObjectsDelegateを作成しますが、そのも試みられて。しかし、それは実際の世界ではなく、すべてのフォーマットをlcdの画面から読み取った。 –

+0

_output = [[AVCaptureMetadataOutput alloc] init]; [_output setMetadataObjectsDelegate:自己キュー:dispatch_get_main_queue()]; [_session addOutput:_output]; _output.metadataObjectTypes = [_output availableMetadataObjectTypes]; //ここにすべてのタイプのバーコードを配列に追加します –

+0

は同じサガールを作成しました。 –

1

- (void)captureOutput:(AVCaptureOutput *)captureOutput didOutputMetadataObjects:(NSArray *)metadataObjects fromConnection:(AVCaptureConnection *)connection 
{ 
CGRect highlightViewRect = CGRectZero; 
AVMetadataMachineReadableCodeObject *barCodeObject; 
NSString *detectionString = nil; 
NSArray *barCodeTypes = @[AVMetadataObjectTypeUPCECode, AVMetadataObjectTypeCode39Code, AVMetadataObjectTypeCode39Mod43Code, 
          AVMetadataObjectTypeEAN13Code, AVMetadataObjectTypeEAN8Code, AVMetadataObjectTypeCode93Code, AVMetadataObjectTypeCode128Code, 
          AVMetadataObjectTypePDF417Code, AVMetadataObjectTypeQRCode, AVMetadataObjectTypeAztecCode]; 
for (AVMetadataObject *metadata in metadataObjects) { 
    for (NSString *type in barCodeTypes) { 
     if ([metadata.type isEqualToString:type]) 
     { 
      barCodeObject = (AVMetadataMachineReadableCodeObject *)[_prevLayer transformedMetadataObjectForMetadataObject:(AVMetadataMachineReadableCodeObject *)metadata]; 
      highlightViewRect = barCodeObject.bounds; 
      detectionString = [(AVMetadataMachineReadableCodeObject *)metadata stringValue]; 

      break; 
     } 
    } 
} 
} 
+0

はい。 Davidに感謝します。しかしこれは前に行われました。表示画面でのみ動作します。 –

関連する問題