iOS OpenCV學習筆記(一)——矩陣的掩碼操作

首先感謝 AmyLiao 關(guān)于OpenCV的文章

實現(xiàn)效果

Simulator Screen Shot 2017年5月16日 下午5.28.31.png

一、OpenCV在iOS中的安裝與環(huán)境配置

請參考http://www.itdecent.cn/p/5b0600a618e9

二、矩陣掩碼

首先創(chuàng)建兩個UIImageView

@property (weak, nonatomic) IBOutlet UIImageView *imageView; @property (weak, nonatomic) IBOutlet UIImageView *imgview;

然后實現(xiàn)功能

void Sharpen(const Mat& myImage, Mat& Result, int n) { CV_Assert(myImage.depth() == CV_8U); Result.create(myImage.size(),myImage.type()); const int nChannels = myImage.channels(); for(int j = 1 ; j < myImage.rows-1; ++j) { const uchar* previous = myImage.ptr(j - 1); const uchar* current = myImage.ptr(j ); const uchar* next = myImage.ptr(j + 1); uchar* output = Result.ptr(j); for(int i= nChannels; i < nChannels*(myImage.cols-1); ++i) { *output++ = saturate_cast<uchar>(5*current[i] -current[i-nChannels] - current[i+nChannels] - previous[i] - next[i]); } } // 邊界處理 Result.row(0).setTo(Scalar(0)); // 上 Result.row(Result.rows-1).setTo(Scalar(0)); // 下 Result.col(0).setTo(Scalar(0)); // 左 Result.col(Result.cols-1).setTo(Scalar(0)); // 右 }

在viewDidLoad中實現(xiàn)下面代碼

self.imgview.image = [UIImage imageNamed:@"1.jpg"]; Mat myImage, result; UIImage *img = [UIImage imageNamed:@"1.jpg"]; UIImageToMat(img, myImage); Sharpen(myImage, result, 5); self.imageView.image = MatToUIImage(result);

關(guān)于OpenCV的學習可以到http://www.opencv.org.cn/opencvdoc/2.3.2/html/doc/tutorials/core/mat-mask-operations/mat-mask-operations.html#maskoperationsfilter

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容