gpt4 book ai didi

xcode - 以支持的图像分辨率在多个网络摄像头上同时捕获图像

转载 作者:行者123 更新时间:2023-12-03 16:29:16 25 4
gpt4 key购买 nike

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

我们已设法从每个网络摄像头以支持的分辨率拍摄图像,但两张图像之间仅延迟 3 秒,因为我们分别触发每个网络摄像头的捕获过程。

我们对此应用程序有 2 个非常具体的要求......

  1. 捕获的图像应具有网络摄像头支持的最高分辨率。
  2. 从各种源捕获的图像绝对不应该有时间延迟。

以支持的分辨率捕获图像的源代码,但有 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) {

}
}

最佳答案

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

http://svn.rforge.net/osx/trunk/tools/wcam.m 中提供了如何完成此操作的示例。

该代码适用于慢速捕获 (1 fps),因此为了您的使用,您可以删除或修改 [dvo setMinimumVideoFrameInterval:1.0]; 以满足您的需求(但请注意,存储图像必须仍然足够快,以免妨碍捕获)。

关于xcode - 以支持的图像分辨率在多个网络摄像头上同时捕获图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8950636/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com