cap_ios.h 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  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. #import <UIKit/UIKit.h>
  29. #import <Accelerate/Accelerate.h>
  30. #import <AVFoundation/AVFoundation.h>
  31. #import <ImageIO/ImageIO.h>
  32. #include "opencv2/core.hpp"
  33. //! @addtogroup videoio_ios
  34. //! @{
  35. /////////////////////////////////////// CvAbstractCamera /////////////////////////////////////
  36. @class CvAbstractCamera;
  37. CV_EXPORTS @interface CvAbstractCamera : NSObject
  38. {
  39. UIDeviceOrientation currentDeviceOrientation;
  40. BOOL cameraAvailable;
  41. }
  42. @property (nonatomic, strong) AVCaptureSession* captureSession;
  43. @property (nonatomic, strong) AVCaptureConnection* videoCaptureConnection;
  44. @property (nonatomic, readonly) BOOL running;
  45. @property (nonatomic, readonly) BOOL captureSessionLoaded;
  46. @property (nonatomic, assign) int defaultFPS;
  47. @property (nonatomic, readonly) AVCaptureVideoPreviewLayer *captureVideoPreviewLayer;
  48. @property (nonatomic, assign) AVCaptureDevicePosition defaultAVCaptureDevicePosition;
  49. @property (nonatomic, assign) AVCaptureVideoOrientation defaultAVCaptureVideoOrientation;
  50. @property (nonatomic, assign) BOOL useAVCaptureVideoPreviewLayer;
  51. @property (nonatomic, strong) NSString *const defaultAVCaptureSessionPreset;
  52. @property (nonatomic, assign) int imageWidth;
  53. @property (nonatomic, assign) int imageHeight;
  54. @property (nonatomic, strong) UIView* parentView;
  55. - CV_UNUSED(start);
  56. - CV_UNUSED(stop);
  57. - CV_UNUSED(switchCameras);
  58. - (id)initWithParentView:(UIView*)parent;
  59. - CV_UNUSED(createCaptureOutput);
  60. - CV_UNUSED(createVideoPreviewLayer);
  61. - CV_UNUSED(updateOrientation);
  62. - CV_UNUSED(lockFocus);
  63. - CV_UNUSED(unlockFocus);
  64. - CV_UNUSED(lockExposure);
  65. - CV_UNUSED(unlockExposure);
  66. - CV_UNUSED(lockBalance);
  67. - CV_UNUSED(unlockBalance);
  68. @end
  69. ///////////////////////////////// CvVideoCamera ///////////////////////////////////////////
  70. @class CvVideoCamera;
  71. CV_EXPORTS @protocol CvVideoCameraDelegate <NSObject>
  72. #ifdef __cplusplus
  73. // delegate method for processing image frames
  74. - (void)processImage:(cv::Mat&)image;
  75. #endif
  76. @end
  77. CV_EXPORTS @interface CvVideoCamera : CvAbstractCamera<AVCaptureVideoDataOutputSampleBufferDelegate>
  78. {
  79. AVCaptureVideoDataOutput *videoDataOutput;
  80. dispatch_queue_t videoDataOutputQueue;
  81. CALayer *customPreviewLayer;
  82. CMTime lastSampleTime;
  83. }
  84. @property (nonatomic, weak) id<CvVideoCameraDelegate> delegate;
  85. @property (nonatomic, assign) BOOL grayscaleMode;
  86. @property (nonatomic, assign) BOOL recordVideo;
  87. @property (nonatomic, assign) BOOL rotateVideo;
  88. @property (nonatomic, strong) AVAssetWriterInput* recordAssetWriterInput;
  89. @property (nonatomic, strong) AVAssetWriterInputPixelBufferAdaptor* recordPixelBufferAdaptor;
  90. @property (nonatomic, strong) AVAssetWriter* recordAssetWriter;
  91. - (void)adjustLayoutToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation;
  92. - CV_UNUSED(layoutPreviewLayer);
  93. - CV_UNUSED(saveVideo);
  94. - (NSURL *)videoFileURL;
  95. - (NSString *)videoFileString;
  96. @end
  97. ///////////////////////////////// CvPhotoCamera ///////////////////////////////////////////
  98. @class CvPhotoCamera;
  99. CV_EXPORTS @protocol CvPhotoCameraDelegate <NSObject>
  100. - (void)photoCamera:(CvPhotoCamera*)photoCamera capturedImage:(UIImage *)image;
  101. - (void)photoCameraCancel:(CvPhotoCamera*)photoCamera;
  102. @end
  103. CV_EXPORTS @interface CvPhotoCamera : CvAbstractCamera
  104. {
  105. AVCaptureStillImageOutput *stillImageOutput;
  106. }
  107. @property (nonatomic, weak) id<CvPhotoCameraDelegate> delegate;
  108. - CV_UNUSED(takePicture);
  109. @end
  110. //! @} videoio_ios