include/opencv2/highgui/cap_ios.h
Go to the documentation of this file.
00001 /*
00002  *  cap_ios.h
00003  *  For iOS video I/O
00004  *  by Eduard Feicho on 29/07/12
00005  *  Copyright 2012. All rights reserved.
00006  *
00007  * Redistribution and use in source and binary forms, with or without
00008  * modification, are permitted provided that the following conditions are met:
00009  *
00010  * 1. Redistributions of source code must retain the above copyright notice,
00011  *    this list of conditions and the following disclaimer.
00012  * 2. Redistributions in binary form must reproduce the above copyright notice,
00013  *    this list of conditions and the following disclaimer in the documentation
00014  *    and/or other materials provided with the distribution.
00015  * 3. The name of the author may not be used to endorse or promote products
00016  *    derived from this software without specific prior written permission.
00017  *
00018  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR IMPLIED
00019  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
00020  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
00021  * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
00022  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
00023  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
00024  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
00025  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
00026  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
00027  * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00028  *
00029  */
00030 
00031 #import <UIKit/UIKit.h>
00032 #import <Accelerate/Accelerate.h>
00033 #import <AVFoundation/AVFoundation.h>
00034 #import <ImageIO/ImageIO.h>
00035 #include "opencv2/core/core.hpp"
00036 
00038 
00039 @class CvAbstractCamera;
00040 
00041 @interface CvAbstractCamera : NSObject
00042 {
00043     AVCaptureSession* captureSession;
00044     AVCaptureConnection* videoCaptureConnection;
00045     AVCaptureVideoPreviewLayer *captureVideoPreviewLayer;
00046 
00047     UIDeviceOrientation currentDeviceOrientation;
00048 
00049     BOOL cameraAvailable;
00050     BOOL captureSessionLoaded;
00051     BOOL running;
00052     BOOL useAVCaptureVideoPreviewLayer;
00053 
00054     AVCaptureDevicePosition defaultAVCaptureDevicePosition;
00055     AVCaptureVideoOrientation defaultAVCaptureVideoOrientation;
00056     NSString *const defaultAVCaptureSessionPreset;
00057 
00058     int defaultFPS;
00059 
00060     UIView* parentView;
00061 
00062     int imageWidth;
00063     int imageHeight;
00064 }
00065 
00066 @property (nonatomic, retain) AVCaptureSession* captureSession;
00067 @property (nonatomic, retain) AVCaptureConnection* videoCaptureConnection;
00068 
00069 @property (nonatomic, readonly) BOOL running;
00070 @property (nonatomic, readonly) BOOL captureSessionLoaded;
00071 
00072 @property (nonatomic, assign) int defaultFPS;
00073 @property (nonatomic, assign) AVCaptureDevicePosition defaultAVCaptureDevicePosition;
00074 @property (nonatomic, assign) AVCaptureVideoOrientation defaultAVCaptureVideoOrientation;
00075 @property (nonatomic, assign) BOOL useAVCaptureVideoPreviewLayer;
00076 @property (nonatomic, strong) NSString *const defaultAVCaptureSessionPreset;
00077 
00078 @property (nonatomic, assign) int imageWidth;
00079 @property (nonatomic, assign) int imageHeight;
00080 
00081 @property (nonatomic, retain) UIView* parentView;
00082 
00083 - (void)start;
00084 - (void)stop;
00085 - (void)switchCameras;
00086 
00087 - (id)initWithParentView:(UIView*)parent;
00088 
00089 - (void)createCaptureOutput;
00090 - (void)createVideoPreviewLayer;
00091 - (void)updateOrientation;
00092 
00093 
00094 @end
00095 
00097 
00098 @class CvVideoCamera;
00099 
00100 @protocol CvVideoCameraDelegate <NSObject>
00101 
00102 #ifdef __cplusplus
00103 // delegate method for processing image frames
00104 - (void)processImage:(cv::Mat&)image;
00105 #endif
00106 
00107 @end
00108 
00109 @interface CvVideoCamera : CvAbstractCamera<AVCaptureVideoDataOutputSampleBufferDelegate>
00110 {
00111     AVCaptureVideoDataOutput *videoDataOutput;
00112 
00113     dispatch_queue_t videoDataOutputQueue;
00114     CALayer *customPreviewLayer;
00115 
00116     BOOL grayscaleMode;
00117 
00118     BOOL recordVideo;
00119     AVAssetWriterInput* recordAssetWriterInput;
00120     AVAssetWriterInputPixelBufferAdaptor* recordPixelBufferAdaptor;
00121     AVAssetWriter* recordAssetWriter;
00122 
00123     CMTime lastSampleTime;
00124 
00125 }
00126 
00127 @property (nonatomic, assign) id<CvVideoCameraDelegate> delegate;
00128 @property (nonatomic, assign) BOOL grayscaleMode;
00129 
00130 @property (nonatomic, assign) BOOL recordVideo;
00131 @property (nonatomic, retain) AVAssetWriterInput* recordAssetWriterInput;
00132 @property (nonatomic, retain) AVAssetWriterInputPixelBufferAdaptor* recordPixelBufferAdaptor;
00133 @property (nonatomic, retain) AVAssetWriter* recordAssetWriter;
00134 
00135 - (void)adjustLayoutToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation;
00136 - (void)layoutPreviewLayer;
00137 - (void)saveVideo;
00138 - (NSURL *)videoFileURL;
00139 
00140 
00141 @end
00142 
00144 
00145 @class CvPhotoCamera;
00146 
00147 @protocol CvPhotoCameraDelegate <NSObject>
00148 
00149 - (void)photoCamera:(CvPhotoCamera*)photoCamera capturedImage:(UIImage *)image;
00150 - (void)photoCameraCancel:(CvPhotoCamera*)photoCamera;
00151 
00152 @end
00153 
00154 @interface CvPhotoCamera : CvAbstractCamera
00155 {
00156     AVCaptureStillImageOutput *stillImageOutput;
00157 }
00158 
00159 @property (nonatomic, assign) id<CvPhotoCameraDelegate> delegate;
00160 
00161 - (void)takePicture;
00162 
00163 @end