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