Ask Your Question
0

iOS: Trouble initializing BOWImgDescriptorExtractor as top level variable

asked 2017-03-23 21:17:30 -0600

hjiang1 gravatar image

Hi, I have a function generateBOW that returns a working BOWImgDescriptorExtractor. I want to set this as a top level variable in my ViewController.mm so that I can use it in another method (not viewDidLoad), but when I try, I am getting this error message: No matching constructor for cv::BOWImgDescriptorExtractor.

I tried just calling the function at the top level (outside of viewDidLoad), but it gave me this runtime error: Thread 1: EXC_BAD_ACCESS (code=1, address=0x0)

How should I initialize bowDE so can I create the object with my function? Here is my code:

#import "ViewController.h"

@interface ViewController ()

@end

@implementation ViewController

ImageProc *imgProc = [[ImageProc alloc] init];
BOWImgDescriptorExtractor bowDE; //Error here
Ptr<SVM> svm;

#pragma mark - System methods
- (void)viewDidLoad {
    [super viewDidLoad];

    bowDE = [imgProc generateBOW];
    svm = [imgProc generateSVM2: bowDE];
}

- (void)processImage:(Mat&)image {
    // I want to use bowDE here
}
edit retag flag offensive close merge delete

Comments

I tried making bowDE a pointer, and I get no compile errors, but I still run into the same runtime error: Thread 1: EXC_BAD_ACCESS (code=1, address=0x40

hjiang1 gravatar imagehjiang1 ( 2017-03-23 21:38:19 -0600 )edit

1 answer

Sort by ยป oldest newest most voted
0

answered 2017-03-27 12:45:13 -0600

hjiang1 gravatar image

I was able to solve the issue. I initialized the BOWImgDescriptorExtractor as a pointer and used the OpenCV function makePtr in my viewDidLoad. Here's the code, hopefully it can help someone in the future.

#import "ViewController.h"

@interface ViewController ()

@end

@implementation ViewController

ImageProc *imgProc = [[ImageProc alloc] init];
Ptr<BOWImgDescriptorExtractor> bowDE;
Ptr<SVM> svm;

#pragma mark - System methods
- (void)viewDidLoad {
    [super viewDidLoad];

    bowDE = makePtr<BOWImgDescriptorExtractor>([imgProc generateBOW]);

    svm = [imgProc generateSVM2: bowDE];
}

- (void)processImage:(Mat&)image {
    // I want to use bowDE here
}
edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2017-03-23 21:17:30 -0600

Seen: 241 times

Last updated: Mar 27 '17