視頻,掃描,識別相關

來源:互聯網
上載者:User

標籤:color   os   io   ar   for   檔案   資料   art   cti   

標頭檔

包含AVFoundation.framework

1、初始化Capture    // Grab the back-facing camera
    AVCaptureDevice *backFacingCamera = nil;
    NSArray *devices = [AVCaptureDevice devicesWithMediaType:AVMediaTypeVideo];
    for (AVCaptureDevice *device in devices)
    {
        if ([device position] == AVCaptureDevicePositionBack)
        {
            backFacingCamera = device;
            break;
        }
    }
    
    // Create the capture session
    _captureSession = [[AVCaptureSession alloc] init];
    
    // Add the video input
    NSError *error = nil;
    _videoInput = [[AVCaptureDeviceInput alloc] initWithDevice:backFacingCamera error:&error];
    if ([_captureSession canAddInput:_videoInput])
    {
        [_captureSession addInput:_videoInput];
    }
    // Add the video frame output
    _videoOutput = [[AVCaptureVideoDataOutput alloc] init];
    [_videoOutput setAlwaysDiscardsLateVideoFrames:YES];
    // Use RGB frames instead of YUV to ease color processing
    NSDictionary *settings = @{(id)kCVPixelBufferPixelFormatTypeKey: [NSNumber numberWithInt:kCVPixelFormatType_32BGRA]};
    [_videoOutput setVideoSettings:settings];
    //    dispatch_queue_t videoQueue = dispatch_queue_create("com.sunsetlakesoftware.colortracking.videoqueue", NULL);
    //    [videoOutput setSampleBufferDelegate:self queue:videoQueue];
    
    [_videoOutput setSampleBufferDelegate:self queue:dispatch_get_main_queue()];
    
    if ([_captureSession canAddOutput:_videoOutput])
    {
        [_captureSession addOutput:_videoOutput];
    }
    else
    {
        NSLog(@"Couldn‘t add video output");
    }
    
    [_captureSession setSessionPreset:AVCaptureSessionPresetMedium];
 

2、啟動 錄製

[_captureSession startRunning];

3、檢測識別

- (void)captureOutput:(AVCaptureOutput *)captureOutput
didOutputSampleBuffer:(CMSampleBufferRef)sampleBuffer
       fromConnection:(AVCaptureConnection *)connection {
    CVPixelBufferRef pixelBuffer = (CVPixelBufferRef)CMSampleBufferGetImageBuffer(sampleBuffer);
    
    CVPixelBufferLockBaseAddress(pixelBuffer, 0);
    
    unsigned char *data = (unsigned char *)CVPixelBufferGetBaseAddress(pixelBuffer);
    //        int bytesPerRow = CVPixelBufferGetBytesPerRow(pixelBuffer);
    
    int bufferHeight = (int)CVPixelBufferGetHeight(pixelBuffer);
    int bufferWidth = (int)CVPixelBufferGetWidth(pixelBuffer);
    int countPerRow = bufferWidth * 4;
   

    //do something


    CVPixelBufferUnlockBaseAddress(pixelBuffer, 0);

}

 

3、停止 錄製

 [_captureSession stopRunning];

 

4、注意事項

    > 處理時,盡量避免演算法過於複雜,導致卡頓

    > 注意資料的 R、G、B、A分量與設定一致

 

視頻,掃描,識別相關

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.