我知道这是每天都可以问的那种,但事实是每个问题的答案都可能不同,我还没有找到。
我目前是 Objective C 的真正初学者,我正在使用该框架开发一个应用程序OpenCV
。
我一直在关注这个网站进行学习,然后我遇到了问题。
我复制/粘贴了网站中提供的 3 种方法,将 cv::Mat 转换为 UIImage,将 UIImage 转换为 cv::Mat,但我不能使用它们:
我的 *.pch 文件:
#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
我的 ViewController.hh 文件
#import <UIKit/UIKit.h>
@interface ViewController : UIViewController
- (cv::Mat)cvMatFromUIImage:(UIImage *)image;
- (cv::Mat)cvMatGrayFromUIImage:(UIImage *)image;
- (UIImage *)UIImageFromCVMat:(cv::Mat)cvMat;
@end
和我的 ViewController.mm 文件
#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
(void) viewDidLoad
2个错误在文件中单独的行上.mm
,它表示两者cvMatFromUIImage
都UIImageFromCVMat
没有声明。
It might be a stupid question, I guess that I missed something, but don't know what.
Please help me :)