cap_ios.h
Go to the documentation of this file.
1 /* For iOS video I/O
2  * by Eduard Feicho on 29/07/12
3  * Copyright 2012. All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions are met:
7  *
8  * 1. Redistributions of source code must retain the above copyright notice,
9  * this list of conditions and the following disclaimer.
10  * 2. Redistributions in binary form must reproduce the above copyright notice,
11  * this list of conditions and the following disclaimer in the documentation
12  * and/or other materials provided with the distribution.
13  * 3. The name of the author may not be used to endorse or promote products
14  * derived from this software without specific prior written permission.
15  *
16  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR IMPLIED
17  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
18  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
19  * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
20  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
21  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
22  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
23  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
24  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
25  * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26  *
27  */
28 
29 #import <UIKit/UIKit.h>
30 #import <Accelerate/Accelerate.h>
31 #import <AVFoundation/AVFoundation.h>
32 #import <ImageIO/ImageIO.h>
33 #include "opencv2/core/core.hpp"
34 
36 
37 @class CvAbstractCamera;
38 
39 @interface CvAbstractCamera : NSObject
40 {
41  AVCaptureSession* captureSession;
42  AVCaptureConnection* videoCaptureConnection;
43  AVCaptureVideoPreviewLayer *captureVideoPreviewLayer;
44 
45  UIDeviceOrientation currentDeviceOrientation;
46 
49  BOOL running;
51 
52  AVCaptureDevicePosition defaultAVCaptureDevicePosition;
53  AVCaptureVideoOrientation defaultAVCaptureVideoOrientation;
55 
57 
58  UIView* parentView;
59 
62 }
63 
64 @property (nonatomic, retain) AVCaptureSession* captureSession;
65 @property (nonatomic, retain) AVCaptureConnection* videoCaptureConnection;
66 
67 @property (nonatomic, readonly) BOOL running;
68 @property (nonatomic, readonly) BOOL captureSessionLoaded;
69 
70 @property (nonatomic, assign) int defaultFPS;
71 @property (nonatomic, assign) AVCaptureDevicePosition defaultAVCaptureDevicePosition;
72 @property (nonatomic, assign) AVCaptureVideoOrientation defaultAVCaptureVideoOrientation;
73 @property (nonatomic, assign) BOOL useAVCaptureVideoPreviewLayer;
74 @property (nonatomic, strong) NSString *const defaultAVCaptureSessionPreset;
75 
76 @property (nonatomic, assign) int imageWidth;
77 @property (nonatomic, assign) int imageHeight;
78 
79 @property (nonatomic, retain) UIView* parentView;
80 
81 - (void)start;
82 - (void)stop;
83 - (void)switchCameras;
84 
85 - (id)initWithParentView:(UIView*)parent;
86 
87 - (void)createCaptureOutput;
88 - (void)createVideoPreviewLayer;
89 - (void)updateOrientation;
90 
91 - (void)lockFocus;
92 - (void)unlockFocus;
93 - (void)lockExposure;
94 - (void)unlockExposure;
95 - (void)lockBalance;
96 - (void)unlockBalance;
97 
98 @end
99 
101 
102 @class CvVideoCamera;
103 
104 @protocol CvVideoCameraDelegate <NSObject>
105 
106 #ifdef __cplusplus
107 // delegate method for processing image frames
108 - (void)processImage:(cv::Mat&)image;
109 #endif
110 
111 @end
112 
113 @interface CvVideoCamera : CvAbstractCamera<AVCaptureVideoDataOutputSampleBufferDelegate>
114 {
115  AVCaptureVideoDataOutput *videoDataOutput;
117  dispatch_queue_t videoDataOutputQueue;
120  BOOL grayscaleMode;
122  BOOL recordVideo;
124  AVAssetWriterInput* recordAssetWriterInput;
125  AVAssetWriterInputPixelBufferAdaptor* recordPixelBufferAdaptor;
126  AVAssetWriter* recordAssetWriter;
128  CMTime lastSampleTime;
130 }
131 
132 @property (nonatomic, assign) id<CvVideoCameraDelegate> delegate;
133 @property (nonatomic, assign) BOOL grayscaleMode;
134 
135 @property (nonatomic, assign) BOOL recordVideo;
136 @property (nonatomic, assign) BOOL rotateVideo;
137 @property (nonatomic, retain) AVAssetWriterInput* recordAssetWriterInput;
138 @property (nonatomic, retain) AVAssetWriterInputPixelBufferAdaptor* recordPixelBufferAdaptor;
139 @property (nonatomic, retain) AVAssetWriter* recordAssetWriter;
140 
141 - (void)adjustLayoutToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation;
142 - (void)layoutPreviewLayer;
143 - (void)saveVideo;
144 - (NSURL *)videoFileURL;
145 
146 
147 @end
148 
150 
151 @class CvPhotoCamera;
152 
153 @protocol CvPhotoCameraDelegate <NSObject>
155 - (void)photoCamera:(CvPhotoCamera*)photoCamera capturedImage:(UIImage *)image;
156 - (void)photoCameraCancel:(CvPhotoCamera*)photoCamera;
157 
158 @end
159 
160 @interface CvPhotoCamera : CvAbstractCamera
161 {
162  AVCaptureStillImageOutput *stillImageOutput;
163 }
164 
165 @property (nonatomic, assign) id<CvPhotoCameraDelegate> delegate;
167 - (void)takePicture;
168 
169 @end
AVAssetWriterInputPixelBufferAdaptor * recordPixelBufferAdaptor
Definition: cap_ios.h:126
GLuint start
AVCaptureSession * captureSession
Definition: cap_ios.h:41
UIDeviceOrientation currentDeviceOrientation
Definition: cap_ios.h:45
BOOL useAVCaptureVideoPreviewLayer
Definition: cap_ios.h:50
typedef void(CV_CDECL *CvMouseCallback)(int event
Definition: cap_ios.h:39
int defaultFPS
Definition: cap_ios.h:56
int imageWidth
Definition: cap_ios.h:60
BOOL captureSessionLoaded
Definition: cap_ios.h:48
AVCaptureVideoPreviewLayer * captureVideoPreviewLayer
Definition: cap_ios.h:43
BOOL recordVideo
Definition: cap_ios.h:123
AVCaptureDevicePosition defaultAVCaptureDevicePosition
Definition: cap_ios.h:52
The Core Functionality.
UIView * parentView
Definition: cap_ios.h:58
int imageHeight
Definition: cap_ios.h:61
AVCaptureVideoOrientation defaultAVCaptureVideoOrientation
Definition: cap_ios.h:53
Definition: cap_ios.h:104
CALayer * customPreviewLayer
Definition: cap_ios.h:119
AVCaptureConnection * videoCaptureConnection
Definition: cap_ios.h:42
BOOL cameraAvailable
Definition: cap_ios.h:47
AVCaptureVideoDataOutput * videoDataOutput
Definition: cap_ios.h:116
BOOL running
Definition: cap_ios.h:49
dispatch_queue_t videoDataOutputQueue
Definition: cap_ios.h:118
GLuint id
BOOL grayscaleMode
Definition: cap_ios.h:121
AVAssetWriter * recordAssetWriter
Definition: cap_ios.h:127
AVAssetWriterInput * recordAssetWriterInput
Definition: cap_ios.h:125
Definition: cap_ios.h:161
CMTime lastSampleTime
Definition: cap_ios.h:129
Definition: cap_ios.h:113
NSString *const defaultAVCaptureSessionPreset
Definition: cap_ios.h:54
AVCaptureStillImageOutput * stillImageOutput
Definition: cap_ios.h:163
BOOL rotateVideo
Definition: cap_ios.h:124
Definition: cap_ios.h:154