28

アプリケーションInstant Heart Rateと同じ機能が必要です。

基本的なプロセスでは、ユーザーは次のことを行う必要があります。

  1. カメラのレンズに人差し指の先をそっと置きます。
  2. 均等に圧力をかけ、レンズ全体を覆います。
  3. 10 秒間静止して心拍数を測定します。

これは、フラッシュをオンにして、血液が人差し指を通って移動するにつれて光が変化するのを見ることで実現できます。

ビデオ キャプチャから光レベル データを取得するにはどうすればよいですか? これはどこで探せばいいですか?クラスを調べましたAVCaptureDeviceが、役立つものは何も見つかりませんでした。

私も見つけましたAVCaptureDeviceSubjectAreaDidChangeNotification、それは役に立ちますか?

4

3 に答える 3

27

これをチェックしてください..

// switch on the flash in torch mode  
 if([camera isTorchModeSupported:AVCaptureTorchModeOn]) {  
 [camera lockForConfiguration:nil];  
 camera.torchMode=AVCaptureTorchModeOn;  
 [camera unlockForConfiguration];  
 }  

  [session setSessionPreset:AVCaptureSessionPresetLow];

   // Create the AVCapture Session  
   session = [[AVCaptureSession alloc] init];  

  // Get the default camera device  
   AVCaptureDevice* camera = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeVideo];  
  if([camera isTorchModeSupported:AVCaptureTorchModeOn]) {  
    [camera lockForConfiguration:nil];  
  camera.torchMode=AVCaptureTorchModeOn;  
    [camera unlockForConfiguration];  
 }  
 // Create a AVCaptureInput with the camera device  
    NSError *error=nil;  
     AVCaptureInput* cameraInput = [[AVCaptureDeviceInput alloc] initWithDevice:camera error:&error];  
   if (cameraInput == nil) {  
    NSLog(@"Error to create camera capture:%@",error);  
  }  

    // Set the output  
    AVCaptureVideoDataOutput* videoOutput = [[AVCaptureVideoDataOutput alloc] init];  

   // create a queue to run the capture on  
  dispatch_queue_t captureQueue=dispatch_queue_create("catpureQueue", NULL);  

   // setup our delegate  
   [videoOutput setSampleBufferDelegate:self queue:captureQueue];  

    // configure the pixel format  
    videoOutput.videoSettings = [NSDictionary dictionaryWithObjectsAndKeys:[NSNumber     numberWithUnsignedInt:kCVPixelFormatType_32BGRA], (id)kCVPixelBufferPixelFormatTypeKey,  
     nil];  
   // cap the framerate  
   videoOutput.minFrameDuration=CMTimeMake(1, 10);  
  // and the size of the frames we want  
  [session setSessionPreset:AVCaptureSessionPresetLow];  

   // Add the input and output  
   [session addInput:cameraInput];  
   [session addOutput:videoOutput];  

   // Start the session  

    [session startRunning];  

   - (void)captureOutput:(AVCaptureOutput *)captureOutput didOutputSampleBuffer:(CMSampleBufferRef)sampleBuffer fromConnection:(AVCaptureConnection *)connection {  



   // this is the image buffer  

  CVImageBufferRef cvimgRef = CMSampleBufferGetImageBuffer(sampleBuffer);  


   // Lock the image buffer  

  CVPixelBufferLockBaseAddress(cvimgRef,0);  


  // access the data  

  int width=CVPixelBufferGetWidth(cvimgRef);  
  int height=CVPixelBufferGetHeight(cvimgRef);  


  // get the raw image bytes  
  uint8_t *buf=(uint8_t *) CVPixelBufferGetBaseAddress(cvimgRef);  
  size_t bprow=CVPixelBufferGetBytesPerRow(cvimgRef);  


// get the average red green and blue values from the image  

 float r=0,g=0,b=0;  
 for(int y=0; y<height; y++) {  
 for(int x=0; x<width*4; x+=4) {  
  b+=buf[x];  
  g+=buf[x+1];  
  r+=buf[x+2];  
 }  
 buf+=bprow;  
 }  
  r/=255*(float) (width*height);  
  g/=255*(float) (width*height);  
  b/=255*(float) (width*height);  

  NSLog(@"%f,%f,%f", r, g, b);  
  }  

サンプルコード はこちら

于 2013-03-27T07:24:31.320 に答える
3

実際、単純な場合もあります。キャプチャした画像のピクセル値を分析する必要があります。簡単なアルゴリズムの1つは、画像の中央の領域を選択してグレースケールに変換し、各画像のピクセルの中央値を取得すると、2D関数になり、この関数で最小値までの距離を計算します。または最大で問題が解決しました。

取得した画像のヒストグラムを5秒間見ると、グレーレベル分布の変化に気付くでしょう。より堅牢な計算が必要な場合は、ヒストグラムを分析してください。

于 2012-05-18T12:55:37.907 に答える
3

補足として、この研究論文に興味があるかもしれません。この方法では、レンズに直接指 (または何か) を当てる必要さえありません。

于 2013-03-27T09:44:50.467 に答える