How to add SURF?

asked 2014-09-25 23:20:37 -0500

madLokesh gravatar image

updated 2014-09-25 23:31:26 -0500

I am trying to fecth the feature descriptors and keypoints of the video frame.

I have created a new XCode project using openCV2 framework. I am getting error while importing nonfree module. I tried initializing the same bt with no luck.

Is there any SURF.cpp which I have to import and call its reference to my native code.

Following is the code

.h

#import <UIKit/UIKit.h>
#import <opencv2/highgui/highgui_c.h>
#import <opencv2/videoio/cap_ios.h>

#include <opencv2/nonfree/features2d.hpp>
#include <opencv2/nonfree/nonfree.hpp>


using namespace cv;

@interface CVdemoViewController : UIViewController<CvVideoCameraDelegate>{
   UIButton *videoStart;
   UIImageView *previewImage;
   CvVideoCamera *videoCamera;
}

@property (nonatomic, retain) UIImageView *previewImage;
@property (nonatomic, retain) UIButton *videoStart;
@property (nonatomic, retain) CvVideoCamera *videoCamera;

@end

.mm

#import "CVdemoViewController.h"

@implementation CVdemoViewController
@synthesize  videoStart, videoCamera, previewImage;

- (void)viewDidLoad
 {

   [super viewDidLoad];
   // Do any additional setup after loading the view, typically from a nib.
   [self initialiseUIObjects];

   videoCamera = [[CvVideoCamera alloc]initWithParentView:previewImage];
   videoCamera.delegate = self;
   videoCamera.defaultAVCaptureDevicePosition = AVCaptureDevicePositionBack;
   videoCamera.defaultAVCaptureSessionPreset = AVCaptureSessionPreset352x288;
   videoCamera.defaultAVCaptureVideoOrientation = AVCaptureVideoOrientationPortrait;
   videoCamera.defaultFPS = 30;
   videoCamera.grayscaleMode = NO;

}

-(void)initialiseUIObjects{
   previewImage = [[UIImageView alloc]initWithFrame:CGRectMake(50,50,self.view.frame.size.width-100, self.view.frame.size.height-150)];
   previewImage.backgroundColor = [UIColor blackColor];
   [self.view addSubview:previewImage];

   videoStart = [[UIButton alloc]initWithFrame:CGRectMake((self.view.frame.size.width/2)-50, self.view.frame.size.height-80, 100, 50)];
  [videoStart setTitle:@"Start" forState:UIControlStateNormal];
  [videoStart setBackgroundColor:[UIColor blackColor]];
  [videoStart addTarget:self action:@selector(startOpenCV) forControlEvents:UIControlEventTouchUpInside];
  [self.view addSubview:videoStart];
}

#ifdef __cplusplus
-(void)processImage:(cv::Mat&)image{

    cv::initModule_nonfree();

    //Do I need to add SURF here ? If yes, HOW?
}
#endif

-(void)startOpenCV{

    if([videoStart.titleLabel.text isEqualToString:@"Start"]){
        [videoCamera start];
        [videoStart setTitle:@"Stop" forState:UIControlStateNormal];
    }else{
        [videoCamera stop];
        [videoStart setTitle:@"Start" forState:UIControlStateNormal];
    }
}

@end

.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
edit retag flag offensive close merge delete