Karim
Karim

Reputation: 5308

OpenCV for iPhone: How to run the following code in an iOS application

I am building an iOS application using OpenCV framework (which is precompiled, integrated and ready to use) that I took from the following project (that I was able to run without any problem on the simulator) : http://aptogo.co.uk/2011/09/opencv-framework-for-ios/

I want to modify this project to include the following function find_obj which is found here and written in C++ : https://code.ros.org/trac/opencv/browser/trunk/opencv/samples/c/find_obj.cpp?rev=2065

The questions I want to ask are :

1- How do I integrate the function find_obj inside my iOS project knowing that in the code I found it is written inside main() and not as a function ?

I want to have in my iOS project something like that :

- (void) find_obj:(UIImage*)image1 with:(UIImage*)image2{
    //code
}

2- Is there a way to keep the code in C++ without converting it to Objective-C ?

I, of course, am not expecting a full answer with code, just some hints that can help me a bit. Thanks !

Upvotes: 1

Views: 1530

Answers (2)

dom
dom

Reputation: 11982

In general: You can just use plain C++ in your iOS application if you change the file-extension from ".m" to ".mm". I'm doing this with OpenCV and it's working great.

The sample you refer to is using OpenCVs old C-interface … If you want to use SURF in your application you should give this sample a shot: https://code.ros.org/trac/opencv/browser/trunk/opencv/samples/cpp/matching_to_many_images.cpp Also take a look at OpenCVs documentation: http://opencv.willowgarage.com/documentation/cpp/features2d__feature_detection_and_descriptor_extraction.html

If SIFT is interesting too: http://blogs.oregonstate.edu/hess/code/sift/

Upvotes: 0

Zhao Xiang
Zhao Xiang

Reputation: 1643

I don't know about OpenCV, but if u want to use C++ code mixed with Objective C, just change the file name to someFile.mm

Upvotes: 1

Related Questions