//
// ViewController.m
// InstantOpenCv
//
// Created by Paul Chin on 12/25/14.
// Copyright (c) 2014 Paul Chin. All rights reserved.
//
@implementation ViewController
- (void)viewDidLoad {
//self.imageView.image=[UIImage imageNamed:@"StBernard.jpg"];
UIImage *image = [UIImage imageNamed:@"StBernard.jpg"];
UIImageToMat(image, cvImage);
if(!cvImage.empty()){
using namespace cv;
Mat gray;
cvtColor(cvImage, gray, CV_RGB2GRAY);//convert to single channel
GaussianBlur(gray, gray, cvSize(5, 5),1.2,1.2);//remove small details
Mat edges;
Canny(gray, edges, 0, 50); //detect edges
cvImage.setTo(Scalar::all(255)); //fill image to white
cvImage.setTo(Scalar(0,128,255,255),edges);//add edges
}
- (void)didReceiveMemoryWarning {
}
// ViewController.m
// InstantOpenCv
//
// Created by Paul Chin on 12/25/14.
// Copyright (c) 2014 Paul Chin. All rights reserved.
//
#import "ViewController.h"
@interface ViewController ()
@end
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.//self.imageView.image=[UIImage imageNamed:@"StBernard.jpg"];
UIImageToMat(image, cvImage);
if(!cvImage.empty()){
using namespace cv;
Mat gray;
cvtColor(cvImage, gray, CV_RGB2GRAY);//convert to single channel
GaussianBlur(gray, gray, cvSize(5, 5),1.2,1.2);//remove small details
Canny(gray, edges, 0, 50); //detect edges
cvImage.setTo(Scalar::all(255)); //fill image to white
cvImage.setTo(Scalar(0,128,255,255),edges);//add edges
self.imageView.image=MatToUIImage(cvImage);
}}
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.}
@end
Run the app on iOS simulator:
It's an incomplete code snippet, please provide full code.
ReplyDeleteThe whole project link is there! just hover over 'project' and click for the whole project
DeleteModify the earlier ViewController.m file from this project: