【问题标题】:Use of undeclared identifier in ViewController在 ViewController 中使用未声明的标识符
【发布时间】:2013-02-25 13:30:13
【问题描述】:

我知道这是每天都可以问的那种,但事实是每个问题的答案都可能不同,我还没有找到。

我目前是 Objective C 的真正初学者,我正在使用框架 OpenCV 开发一个应用程序。

我一直在关注这个website 学习 然后我遇到了问题。

我复制/粘贴了网站中提供的将 cv::Mat 转换为 UIImage 和 UIImage 转换为 cv::Mat 的 3 种方法,但我无法使用它们:

我的 *.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 文件中的 (void) viewDidLoad 单独的行上,它表示 cvMatFromUIImageUIImageFromCVMat 都没有声明。

这可能是一个愚蠢的问题,我想我错过了什么,但不知道是什么。

请帮帮我:)

【问题讨论】:

    标签: ios objective-c xcode undeclared-identifier


    【解决方案1】:

    我认为你已经在 Objective-C 中定义了你的函数,但是使用 C 标准来调用它们...更改这些:

    cvMatFromUIImage(image)
    UIImageFromCVMat(inputMat)
    

    [self cvMatFromUIImage:image];
    [self UIImageFromCVMat:inputMat];
    

    【讨论】:

    • 好的,非常感谢,现在有其他问题了,但一步一步,会好的^^
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多