2012-01-21 49 views
2

我们尝试从每个网络摄像机通过可可应用程序最好支持的分辨率捕获来自多个外部网络摄像机的图像。我们无法同时捕获所有提要点,即在所有网络摄像头上同时捕获,因为我们无法同时打开所有网络摄像头并调用捕获方法。以支持的图像分辨率在多个网络摄像机上同时捕获图像

我们已经成功地从每个摄像头拍摄支持的分辨率的图像,但仅在2张图像之间延迟3秒,因为我们正在分别为每个摄像头触发捕获过程。

我们有2个为这个应用程序非常具体的要求...捕获应该是一个摄像头支持最高分辨率的

  1. 图像。
  2. 从各种Feed中捕获的图像应该绝对没有时间延迟。

在支持的分辨率但3秒延时拍摄图像的源代码...

-(void)initailzeCamera{ 
    if([cameraArray count] == 0) { 
       exit(1); 
    } 
    if(cameraCount >= [cameraArray count]){ 
     cameraCount = 0; 
    } 
    if(videoDevice){ 
     //[mCaptureSession stopRunning]; 

    } 
    videoDevice = [cameraArray objectAtIndex:cameraCount]; 
    if(![videoDevice isOpen]) 
     [videoDevice open:nil]; 

    if(!videoDevice) { 
     exit(1); 
    } 
    if(mCaptureDeviceInput){ 
     [mCaptureDeviceInput release]; 
    } 
    mCaptureDeviceInput = [[QTCaptureDeviceInput alloc] initWithDevice:videoDevice]; 
    mCaptureSession = [[QTCaptureSession alloc] init]; 
    [mCaptureSession addInput:mCaptureDeviceInput error:nil]; 
    [mCaptureSession startRunning]; 
    [mCaptureView setCaptureSession:mCaptureSession]; 
    [mCaptureView setVideoPreviewConnection:[[mCaptureView availableVideoPreviewConnections] objectAtIndex:0]]; 
    [mCaptureView setHidden:YES]; 
    [mCaptureSession startRunning]; 

    [self performSelector:@selector(stopCamera) withObject:nil afterDelay:2.0]; 

} 

// This delegate method is called whenever the QTCaptureDecompressedVideoOutput receives a frame 
- (CIImage *)view:(QTCaptureView *)view willDisplayImage:(CIImage *)image{ 

    NSBitmapImageRep *bitmapRep = [[NSBitmapImageRep alloc] initWithCIImage:image]; 
    jpegData =[[bitmapRep representationUsingType:NSJPEGFileType properties:nil]retain]; 

    return image; 

} 
-(void)stopCamera{ 
    @try { 
     [mCaptureSession stopRunning]; 
     NSString *path= [NSString stringWithFormat:@"%@",[locationLabel stringValue]]; 

     NSString *imagePath=[[NSString stringWithFormat:@"%@",path] retain]; 
     NSString *imageName=[NSString stringWithFormat:@"%@.jpg",[[[NSDate date]description] substringToIndex:19]]; 
     imageName = [imageName stringByReplacingOccurrencesOfString:@":" withString:@"."]; 
     NSString *appFile = [imagePath stringByAppendingPathComponent:imageName]; 


     if(jpegData != nil){ 
      if([jpegData writeToFile:[appFile stringByExpandingTildeInPath] atomically:YES]){ 
        }else { 
      } 
     } 
     else { 
       NSException* jpegDataNullException= [NSException exceptionWithName:@"JpegDataNullException" 
                reason:@"jpegData null found" 
                userInfo:nil]; 
      @throw jpegDataNullException; 
     } 


     cameraCount++; 

     if(!flagForPause){ 
      if(cameraCount < [cameraArray count]){ 
       [self performSelector:@selector(initailzeCamera) withObject:nil afterDelay:1.0]; 
      }else{ 
       if(flagForAutoMode){ 
        [self performSelector:@selector(initailzeCamera) withObject:nil afterDelay:[timeREcquire intValue]-5]; 
       } 
      } 
     } 
    } 
    @catch (NSException * e) { 

    } 
} 

回答

3

捕捉多个摄像头只是正常使用QTKit。您只需打开两个会话并让它们并行运行(如果您不需要单独控制它们,您甚至可以打开一个会话并添加两个输入源)。启动设备捕获需要几秒钟的时间,这就是为什么上述方法无法正常工作的原因之一 - 您必须保持两个会话都在运行。另一个问题是您正在使用预览进行捕获,这可能导致质量下降。如果你想全分辨率捕捉,你应该使用captureOutput:didOutputVideoFrame:withSampleBuffer:fromConnection:提供全尺寸帧。

它如何可以做一个例子在http://svn.rforge.net/osx/trunk/tools/wcam.m

该代码是用于缓慢拍摄(1帧),所以您的使用,你可以删除或修改[dvo setMinimumVideoFrameInterval:1.0];,以满足您的需求(但要注意保存图像必须足够快,不会窒息捕获)。

1

试图使用您提供的源代码,但我遇到的问题是一个摄像头只拍摄一张照片并停止,第二个摄像头不停地拍照。

devices = [[[NSMutableArray alloc] initWithArray:[QTCaptureDevice inputDevicesWithMediaType:QTMediaTypeVideo]] retain]; 
   //[devices removeObject:[QTCaptureDevice defaultInputDeviceWithMediaType:QTMediaTypeVideo]]; 
    
   int devId = 0; 
   for (QTCaptureDevice *device in devices) { 
       NSLog(@"device: %@", device); 
       Capture *cap = [[Capture alloc] initWithDevice: device]; 
       [cap setFileName:[NSString stringWithFormat:@"image.%d.%%04d.jpeg", ++devId]]; 
       [cap start]; 
   } 
   if ([devices count] == 0) { 
       NSLog(@"no devices found, terminating"); 
       exit (1); 
   }