Search code examples
iosobjective-cxcodeopencvappcelerator

Appcelerator VS iOS OpenCV Module


I use Appcelerator Titanium and I am developing a module for an iOS App.

This module needs to use OpenCV, since I need some things to be done with the camera's image. The App takes a picture of a certain tool and count red rectangles of it. Pretty straight forward.

The things is, I don't know if OpenCV (iOS) and Appcelerator are fully compatible. For Android, OpenCV did a great job, but I am facing several issues dealing with it in iOS. My module compiles correctly on XCode and I build it with no error via appc run -p ios --build-only. I add the module to the Appcelerator's App, but, when I try to Run it on my device, it crashes with the following error:

The following build commands failed: Ld /Users.......(somethings) normal armv7

I made sure the architectures are correctly configured in XCode.

What I noticed so far is: when I comment certain parts of my code, the module/app runs and installs on the device with no problem. But, when these lines are active, the error when building to the device, appears. Bellow is the code I use. (The commented lines are the ones that gives the error if they are not commented).

- (void)photoCamera:(CvPhotoCamera *)photoCamera capturedImage:(UIImage *)image {

[photoCam stop];

// resultView = [[UIImageView alloc] initWithFrame:imageView.bounds];
[resultView setImage:image];
resultView.center = imageView.center;
// [self.view addSubview:resultView];

NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *filePath = [[paths objectAtIndex:0] stringByAppendingPathComponent:@"image.png"];
[UIImagePNGRepresentation(image) writeToFile:filePath atomically:YES];

UIImage* resImage = [UIImage imageWithContentsOfFile:filePath];
Mat3b bgr;
// UIImageToMat(resImage, bgr);

Mat3b hsv;
// cvtColor(bgr, hsv, COLOR_BGR2HSV);

Mat1b mask1, mask2;
// inRange(hsv, Scalar(0, 70, 50), Scalar(10, 255, 255), mask1);
// inRange(hsv, Scalar(170, 70, 50), Scalar(180, 255, 255), mask2);

Mat1b mask = mask1 | mask2;

// namedWindow("Mask", CV_WINDOW_AUTOSIZE);
// imshow("Mask", mask);
// waitKey();
}

As you can see, I can't seem to call any method that depends on the OpenCV framework, but it does create variables like Mat. Which made me think: is really possible to create an Appcelerator module for iOS that uses OpenCV?

Please someone enlighten me on that. I will provide any further information needed. Thanks in advance.


Solution

  • After a long time struggling, I got help and found the solution for this.

    First, I had to move the opencv2.framework file to the /ios/platform folder of the module.

    I also had to add -lz to Other Linker Flags.

    And finally, I had to install the 9.2.0 Titanium Mobile SDK.

    So, to answer my question, it is possible to have an Appcelerator iOS Module with OpenCV working, the thing is, I needed specific help for this (thanks guys from TiSlack), since there are practically nothing useful on the internet regarding Appcelerator and OpenCV.