Skip to content

Instantly share code, notes, and snippets.

@WhiteTeeth
WhiteTeeth / AVCamPreviewView.h
Created June 29, 2017 09:10
相机预览 View
#import <UIKit/UIKit.h>
#import <AVFoundation/AVCaptureSession.h>
@interface AVCamPreviewView : UIView
@property (nonatomic, readonly) AVCaptureVideoPreviewLayer *videoPreviewLayer;
@property (nonatomic) AVCaptureSession *session;
@end
@WhiteTeeth
WhiteTeeth / UIImage+Convert.h
Last active June 29, 2017 08:39
UIImage 转为 CVImageBufferRef、cv::Mat 的方法,CVImageBufferRef 和 cv::Mat 的转换方法见 https://gist.github.com/WhiteTeeth/479850ecbf748c109d20c279f147e5ed
#import <UIKit/UIKit.h>
#import <opencv2/opencv.hpp>
@interface UIImage (Convert)
// CVImageBufferBuf 转为 UIImage
+ (UIImage*)imageWithImageBuffer:(CVImageBufferRef)imageBuffer;
// UIImage 转为 cv::Mat
- (cv::Mat)cvMat;
@WhiteTeeth
WhiteTeeth / UIImage+Orientation.h
Created June 29, 2017 08:23
根据UIImage的方向信息旋转图片
#import <UIKit/UIKit.h>
@interface UIImage (Orientation)
- (UIImage *)fixOrientation;
@end
@WhiteTeeth
WhiteTeeth / CVPixelBufferUtils.h
Last active May 27, 2020 10:01
CVPixelBufferRef 相关工具类,包括 旋转、转为cv::Mat等
#import <Foundation/Foundation.h>
#import <AVFoundation/AVFoundation.h>
#import <Accelerate/Accelerate.h>
#import <opencv2/opencv.hpp>
@interface CVPixelBufferUtils : NSObject
// 将CVPixelBufferRef 转化为cv::Mat,传参的buffer格式为BGRA,不过其他四通道格式应该也适用
+ (cv::Mat)matFromPixelBuffer:(CVPixelBufferRef)buffer;