Tag: avcapturesession

如何从AVCapture中将图像裁剪到显示屏上显示的矩形

这让我疯狂,因为我无法工作。 我有以下情况: 我正在使用AVCaptureSession和AVCaptureVideoPreviewLayer来创build我自己的相机界面。 界面显示一个矩形。 下面是填充整个屏幕的AVCaptureVideoPreviewLayer 。 我希望以某种方式裁剪捕捉的图像,使得生成的图像精确显示在显示器上显示的内容。 我的设置看起来像这样: _session = [[AVCaptureSession alloc] init]; AVCaptureSession *session = _session; session.sessionPreset = AVCaptureSessionPresetPhoto; AVCaptureDevice *camera = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeVideo]; if (camera == nil) { [self showImagePicker]; _isSetup = YES; return; } AVCaptureVideoPreviewLayer *captureVideoPreviewLayer = [[AVCaptureVideoPreviewLayer alloc] initWithSession:session]; captureVideoPreviewLayer.videoGravity = AVLayerVideoGravityResizeAspectFill; captureVideoPreviewLayer.frame = self.liveCapturePlaceholderView.bounds; [self.liveCapturePlaceholderView.layer addSublayer:captureVideoPreviewLayer]; NSError *error; AVCaptureDeviceInput *input […]

iOS 7 AVCaptureMetadataOutput委托(QRCode扫描器)

我试图用新的iOS 7function实现一个QRCode扫描器,但是我的代码没有调用主AVCaptureMetadataOutputObjectsDelegate方法。 我已经使用AVFoundation摄像头之前和我目前的实现我有预览层运行没有问题。 即使切换我的输出回到AVCaptureVideoDataOutputvalidation我的会话设置。 我使用这个NSHipster职位作为指导,这里是我的代码到目前为止: 接口: @import AVFoundation; @interface QRCodeViewController () <AVCaptureMetadataOutputObjectsDelegate> @property (strong, nonatomic) AVCaptureDevice* device; @property (strong, nonatomic) AVCaptureDeviceInput* input; @property (strong, nonatomic) AVCaptureMetadataOutput* output; @property (strong, nonatomic) AVCaptureSession* session; @property (strong, nonatomic) AVCaptureVideoPreviewLayer* preview; @end build立: – (void)setupCamera { // Device self.device = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeVideo]; // Input self.input = [AVCaptureDeviceInput deviceInputWithDevice:self.device error:nil]; […]

如何在不使用预设的情况下在iOS上录制video?

在iOS上录制video更简单的方法是设置AVCaptureSession.sessionPreset 。 但是,这并不适合我,因为我想控制像binning,稳定(电影,标准,或无)和ISO参数。 我find了我想要的格式并将其分配给activeFormat ,但是当我尝试开始录制时,出现错误: Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[AVCaptureMovieFileOutput startRecordingToOutputFileURL:recordingDelegate:] No active/enabled connections' 这是我的初始化代码: let device = AVCaptureDevice.defaultDevice( withDeviceType: .builtInWideAngleCamera, mediaType: AVMediaTypeVideo, position: .back)! let session = AVCaptureSession() session.addInput(try! AVCaptureDeviceInput(device: device)) output = AVCaptureMovieFileOutput() session.addOutput(output) device.setFormatWithHighestIso() session.startRunning() setFormatWithHighestIso()被定义为: extension AVCaptureDevice { var goodVideoFormats: [AVCaptureDeviceFormat] { return (formats as! [AVCaptureDeviceFormat]) […]

支持使用AVCaptureSession进行video的后台录制

我正在尝试在后台录制video,但是目前我的代码是在前台录制video时,应用程序将背景的方法。 -(void)captureOutput:(AVCaptureFileOutput *)captureOutput didFinishRecordingToOutputFileAtURL:(NSURL *)outputFileURL fromConnections:(NSArray *)connections error:(NSError *)error 立即发生错误 error:Error Domain=AVFoundationErrorDomain Code=-11818 "Recording Stopped" UserInfo=0x176aa180 {NSLocalizedRecoverySuggestion=Stop any other actions using the recording device and try again., NSUnderlyingError=0x1766c0e0 "The operation couldn't be completed. (OSStatus error -16133.)", NSLocalizedDescription=Recording Stopped} 我在DemoApp-Info.plist中设置了以下值 Required background modes->App plays audio or streams audio/video using AirPlay Application does not run in background->NO […]

AVCAPTURE图像方向

我有一个视图控制器,允许用户拍照。 我将隐藏界限定为屏幕上的一个观点的界限。 在这个视图上方,我有一个集合视图。 因此,用户可以捕捉多个图片,然后将其添加到上面的集合视图。 我在上面的预览中出现正确的方向时遇到问题。 代码如下: @IBOutlet weak var imagePreviews: UICollectionView! @IBOutlet weak var imgPreview: UIView! var session: AVCaptureSession? var stillImageOutput: AVCaptureStillImageOutput? var videoPreviewLayer: AVCaptureVideoPreviewLayer? var images: [UIImage] = [UIImage]() var isLandscapeLeft : Bool = false var isLandscapeRight : Bool = false var isPortrait : Bool = false var isPortraitUpsideDown: Bool = false @IBAction func […]

从CVImageBufferRef获取内存的所有权

我正在做一个简单的pipe道,从AVCaptureSession获取图像,在OpenCV中处理它们,然后在OpenGL中渲染它们。 它基于RosyWriter,但没有audio和录音function。 OpenCV处理看起来像 – (void)processPixelBuffer: (CVImageBufferRef)pixelBuffer { CVPixelBufferLockBaseAddress( pixelBuffer, 0 ); int bufferWidth = CVPixelBufferGetWidth(pixelBuffer); int bufferHeight = CVPixelBufferGetHeight(pixelBuffer); unsigned char *pixel = (unsigned char *)CVPixelBufferGetBaseAddress(pixelBuffer); cv::Mat image = cv::Mat(bufferWidth,bufferHeight,CV_8UC4,pixel); //do any processing [self setDisplay_matrix:image]; CVPixelBufferUnlockBaseAddress( pixelBuffer, 0 ); } 在这个函数到目前为止,我没有复制任何内存,我想保持这种方式。 问题是pixelBuffer可能仍然拥有display_image中包含的内存。 处理代码可能会或可能不会分配新的内存并将其存储在映像中。 如果处理没有分配新的内存,我必须使用display_matrix来传递pixelBuffer,以防止数据被擦除。 有没有办法让我获得内存的所有权? 我想销毁pixelBuffer而不破坏它指向的内存。 在相关的说明中,LockBaseAddress究竟干什么? 如果我传递一个cv :: Mat,CVImageBufferRef对将我必须locking基地址每次我想修改/使用cv :: Mat的数据?

裁剪AVCaptureVideoPreviewLayer输出到一个正方形

抓取可视屏幕的裁剪UIImage时,遇到AVCaptureVideoPreviewLayer方法问题。 目前它正在工作,但没有输出我需要的正确作物。 我正在尝试输出一个正方形,但它(按其外观)似乎正在给出完整的高度并压缩图像。 之前的图像显示实时屏幕和后图像显示图像一旦捕获button已被按下。 你可以看到它已经垂直改变,以适应广场,但高度没有被垂直裁剪。 捕获图像代码 [stillImageOutput captureStillImageAsynchronouslyFromConnection:videoConnection completionHandler: ^(CMSampleBufferRef imageSampleBuffer, NSError *error) { if (imageSampleBuffer != NULL) { NSData *imageData = [AVCaptureStillImageOutput jpegStillImageNSDataRepresentation:imageSampleBuffer]; [self processImage:[UIImage imageWithData:imageData]]; } }]; 裁剪代码 – (void) processImage:(UIImage *)image { //process captured image, crop, resize and rotate haveImage = YES; CGRect deviceScreen = _previewLayer.bounds; CGFloat width = deviceScreen.size.width; CGFloat height […]

AVCapture会话捕获图像SWIFT

我创build了一个AVCaptureSession来捕获video输出并通过UIView将其显示给用户。 现在我想能够点击一个button(takePhoto方法),并显示在UIImageView中的会话的图像。 我试图遍历每个设备连接,并尝试保存输出,但没有奏效。 我的代码如下 let captureSession = AVCaptureSession() var stillImageOutput: AVCaptureStillImageOutput! @IBOutlet var imageView: UIImageView! @IBOutlet var cameraView: UIView! // If we find a device we'll store it here for later use var captureDevice : AVCaptureDevice? override func viewDidLoad() { // Do any additional setup after loading the view, typically from a nib. super.viewDidLoad() println("I […]

ios AVCaptureVideoPreviewLayer捕获当前图像

一旦默认的iPhone相机应用程序拍摄照片,预览出现,图像animation到相机滚动button。 我正试图复制这个animation。 session = [[AVCaptureSession alloc] init]; session.sessionPreset = AVCaptureSessionPresetPhoto; CALayer *viewLayer = self.vImagePreview.layer; NSLog(@"viewLayer = %@", viewLayer); captureVideoPreviewLayer = [[AVCaptureVideoPreviewLayer alloc] initWithSession:session]; captureVideoPreviewLayer.frame = CGRectMake(0, 0, 322, 425); [self.vImagePreview.layer addSublayer:captureVideoPreviewLayer]; device = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeVideo]; NSError *error = nil; AVCaptureDeviceInput *input = [AVCaptureDeviceInput deviceInputWithDevice:device error:&error]; if (!input) { // Handle the error appropriately. NSLog(@"ERROR: trying […]

更改AVCaptureDeviceInput导致AVAssetWriterStatusFailed

我试图改变相机视图Front和Back它工作正常。如果录像没有翻转与Pause/Record选项它工作正常。但如果我们Flip Camera View一次然后,进一步录制video不保存哪些线索到AVAssetWriterStatusFailed – The operation could not be completed 。 任何人都可以帮助我find我出错的地方吗? 以下是我的代码。 Camera.m – (void)flipCamera{ NSArray * inputs = _session.inputs; for ( AVCaptureDeviceInput * INPUT in inputs ) { AVCaptureDevice * Device = INPUT.device ; if ( [ Device hasMediaType : AVMediaTypeVideo ] ) { AVCaptureDevicePosition position = Device . position ; AVCaptureDevice * […]