I know that its the kind that can be asked everyday, but the fact is that the answer can be different for every questions, and I didn't find any yet.
I am currently a real beginner in Objective C, and I am developing an app using the framework OpenCV
.
I have been following this website for learning and then I got my problem.
I copied/pasted the 3 methods that are given in the website to convert cv::Mat to UIImage and UIImage to cv::Mat, but I can't use them :
My *.pch file :
#import <Availability.h>
#ifndef __IPHONE_5_0
#warning "This project uses features only available in iOS SDK 5.0 and later."
#endif
#ifdef __cplusplus
#import <opencv2/opencv.hpp>
#endif
#ifdef __OBJC__
#import <UIKit/UIKit.h>
#import <Foundation/Foundation.h>
#endif
My ViewController.hh file
#import <UIKit/UIKit.h>
@interface ViewController : UIViewController
- (cv::Mat)cvMatFromUIImage:(UIImage *)image;
- (cv::Mat)cvMatGrayFromUIImage:(UIImage *)image;
- (UIImage *)UIImageFromCVMat:(cv::Mat)cvMat;
@end
and my ViewController.mm file
#import "ViewController.hh"
@interface ViewController ()
@end
@implementation ViewController
- (cv::Mat)cvMatFromUIImage:(UIImage *)image
{
@@@//what is given in the linked website
return cvMat;
}
- (cv::Mat)cvMatGrayFromUIImage:(UIImage *)image
{
@@@//what is given in the linked website
return cvMat;
}
-(UIImage *)UIImageFromCVMat:(cv::Mat)cvMat
{
@@@//what is given in the linked website
return finalImage;
}
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
NSString* filename = [[NSBundle mainBundle] pathForResource:@"openCV" ofType:@"jpg"];
UIImage *image = [UIImage imageWithContentsOfFile:filename];
cv::Mat inputMat = cvMatFromUIImage(image);
UIImage *newImage = UIImageFromCVMat(inputMat);
self.view.backgroundColor = [UIColor colorWithPatternImage:newImage];
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"HelloWorld !" message:@"Welcome to OpenCV !" delegate:self cancelButtonTitle:@"Continue" otherButtonTitles:nil, nil];
[alert show];
}
- (void)viewDidUnload
{
[super viewDidUnload];
// Release any retained subviews of the main view.
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);
}
@end
The 2 errors are on the lines that are alone in (void) viewDidLoad
in the .mm
file, it says that both cvMatFromUIImage
and UIImageFromCVMat
aren't declared.
It might be a stupid question, I guess that I missed something, but don't know what.
Please help me :)
I think you've defined your functions in Objective-C but are using the C standard for calling them... Change these:
cvMatFromUIImage(image)
UIImageFromCVMat(inputMat)
to
[self cvMatFromUIImage:image];
[self UIImageFromCVMat:inputMat];