MMOpenCVHelper
用来转换c++image矩阵和 uiimage变化
代码
- (void)viewDidLoad {
[super viewDidLoad];
UIImage *image1 = [UIImage imageNamed:@"lenda.jpg"];
/// 读入用户提供的图像
Mat image = [MMOpenCVHelper cvMatFromUIImage:image1];
//获得图片的大小和类型
Mat new_image = Mat::zeros( image.size(), image.type() );
/// 初始化
int alpha = 4;
int beta = 2;
/// 执行运算 new_image(i,j) = alpha*image(i,j) + beta
for( int y = 0; y < image.rows; y++ )
{
for( int x = 0; x < image.cols; x++ )
{
//某个点的 3个数据
for( int c = 0; c < 3; c++ )
{
new_image.at<Vec3b>(y,x)[c] = saturate_cast<uchar>( alpha*( image.at<Vec3b>(y,x)[c] ) + beta );
}
}
}
self.imageView2.backgroundColor = [UIColor redColor];
self.imageView2.image = [MMOpenCVHelper UIImageFromCVMat:new_image];
}