Merge pull request #1263 from abidrahmank:pyCLAHE_24
[profile/ivi/opencv.git] / modules / highgui / include / opencv2 / highgui / cap_ios.h
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
35 /////////////////////////////////////// CvAbstractCamera /////////////////////////////////////
36
37 @class CvAbstractCamera;
38
39 @interface CvAbstractCamera : NSObject
40 {
41     AVCaptureSession* captureSession;
42     AVCaptureConnection* videoCaptureConnection;
43     AVCaptureVideoPreviewLayer *captureVideoPreviewLayer;
44
45     UIDeviceOrientation currentDeviceOrientation;
46
47     BOOL cameraAvailable;
48     BOOL captureSessionLoaded;
49     BOOL running;
50     BOOL useAVCaptureVideoPreviewLayer;
51
52     AVCaptureDevicePosition defaultAVCaptureDevicePosition;
53     AVCaptureVideoOrientation defaultAVCaptureVideoOrientation;
54     NSString *const defaultAVCaptureSessionPreset;
55
56     int defaultFPS;
57
58     UIView* parentView;
59
60     int imageWidth;
61     int imageHeight;
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
100 ///////////////////////////////// CvVideoCamera ///////////////////////////////////////////
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;
116
117     dispatch_queue_t videoDataOutputQueue;
118     CALayer *customPreviewLayer;
119
120     BOOL grayscaleMode;
121
122     BOOL recordVideo;
123     BOOL rotateVideo;
124     AVAssetWriterInput* recordAssetWriterInput;
125     AVAssetWriterInputPixelBufferAdaptor* recordPixelBufferAdaptor;
126     AVAssetWriter* recordAssetWriter;
127
128     CMTime lastSampleTime;
129
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
149 ///////////////////////////////// CvPhotoCamera ///////////////////////////////////////////
150
151 @class CvPhotoCamera;
152
153 @protocol CvPhotoCameraDelegate <NSObject>
154
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;
166
167 - (void)takePicture;
168
169 @end