OpenCV 3.1 iOS can't load classifier from .xml - ios

I'm trying to run this example on iOS:
https://github.com/egeorgiou/openCViOSFaceTrackingTutorial
Everything works except this function:
faceCascade.detectMultiScale(grayscaleFrame, faces, 1.1, 2, HaarOptions, cv::Size(60, 60));
I get an error like this:
error: (-215) !empty() in function detectMultiScale
I read a bit about it and everyone is saying that the problem is that the faceCascade is not being loaded.
At the moment I load it like this:
NSString* faceCascadePath = [[NSBundle mainBundle] pathForResource:#"haarcascade_frontalface_alt2" ofType:#"xml"];
self.faceCascade.load([faceCascadePath UTF8String]);
How should I load the .xml file so it works correctly? Or maybe should I put the haarcascade_frontalface_alt2.xml file somewhere else in XCode?
I'm using Xcode 8.

Related

GLKTextureLoader with texture not in mainBundle

I'm making an iPhone application with OpenGL ES 2.0 using the GLKit. I'm using GLKTextureLoader to load textures. When my texture sits inside a mainBundle - EVERYTHING IS FINE. I get its name with command [[NSBundle mainBundle] pathForResource:#"brushRose.png" ofType:nil] and the texture has a following path:
/var/mobile/Containers/Bundle/Application/D79492CB-D03C-464D-B06E-00D0DE4389DF/Texture Test.app/brushRose.png
When I try to download an absolutely same texture from Internet and store it inside Application's Documents folder. Path is like follow:
/var/mobile/Containers/Data/Application/CD3FBAAB-B8AE-47F5-9C6E-51C854FC1620/Documents/brushes/ps_roses.png
I get a TERRIBLE END RESULT which can be observed on the picture below:
First row - texture from mainBundle, second row - from Documents
Any ideas how to fix the second case are welcome.
Test project can be found here
When you build an app containing PNGs, Xcode runs pngcrush on them which, among other things, pre-multiplies the alpha.
The "non main-Bundle" files you are using do not have pre-multiplied alpha. This explains the difference in appearance.
Your options are to run pngcrush on your url textures, or stop pngcrush running in your project, or conditionally apply the GLKTextureLoaderApplyPremultiplication when you load non-crushed PNGs:
NSMutableDictionary *options = [#{ GLKTextureLoaderOriginBottomLeft : #NO} mutableCopy];
if ( /** png is uncrushed **/ ) {
options[GLKTextureLoaderApplyPremultiplication] = #YES;
}
NSError* error;
GLKTextureInfo* texture = [GLKTextureLoader textureWithContentsOfFile:brushPath options:options error:&error];

OpenCV 3.0 CascadeClassifier.load() Assertion Fail (!empty)

I've just updated my iOS project to version OpenCV 3.0 and whenever I try and load the haarcascade file I get an Assertion Fail.
Previous version of OpenCV works fine and there is no change to how I get the path and load the file (see below), it's just seems not to work with version 3.0
NSString *faceCascadePath = [[NSBundle mainBundle] pathForResource:kFaceCascadeFilename ofType:#"xml"];
_faceCascade.load([faceCascadePath UTF8String])
I've also attempted to amend the way I read the file (another example I found below).
const CFIndex CASCADE_NAME_LEN = 2048;
char *CASCADE_NAME = (char *) malloc(CASCADE_NAME_LEN);
CFStringGetFileSystemRepresentation( (CFStringRef)faceCascadePath, CASCADE_NAME, CASCADE_NAME_LEN);
But again to no avail...
Any suggestions would be much appreciated.
C.
Okay figured it out, I was running the "detectMultiScale" in a seperate thread and trying to load the haarcascade file in the main ViewDidLoad.
Moved the load within the thread doing the actual detection and it seemed to fix it.
Still not sure why previous versions were not effected though.

How to get file in a library iOS

I am trying to construct a library in IOS.
In my library ,I use a method -(void)loadNewData to load some data EX:test.csv.
But when I export my library and let the other app use my library to excute the loadNewData method.
I found it can not be load correctly. It seems that because there is not such a file test.csv in the app.
How should I revise my code? Or where should I notice when I export the library?
Thank you for watch my question.
And sorry for my poor English.
Here is the a part of code of the loadNewData:
NSString *resourcePath = [[NSBundle mainBundle] resourcePath];
NSString *Rawsurveys=[resourcePath stringByAppendingPathComponent:#"test.csv"];
NSString *RawsurveyResults;
if([[NSFileManager defaultManager]fileExistsAtPath:Rawsurveys])
{
NSLog(#"find file");
NSFileHandle *RawfileHandle=[NSFileHandle fileHandleForReadingAtPath:Rawsurveys];
RawsurveyResults=[[NSString alloc]initWithData:[RawfileHandle availableData] encoding:NSUTF8StringEncoding];
[RawfileHandle closeFile];
}
You could probably create a bundle within your library and add you test.csv there.
Then you can access your test.csv from your own bundle.
Example of how I use images from my bundle. [UIImage imageNamed:#"myBundle.bundle/myImage"]. You could use the somewhat same for your file

How to add/use kiwiviewer in ios app to view .ply file (3d model) or any other way

I am building an ios app on xcode that at some point i have to display a 3d model to the user , I have read and search until i found something called kiwiviewer , the 3d model is (.ply) files so i want a help how to add kiwiviewer to xcode or use it inside the app, or if there is other way to view the 3d models in iphone app .
I searched and watched a youtube video that have no sound and did not get the way , please help.
I am using ios 5.1 .
thank you.
kiwi viewer does not support the PLY files so the above answer is not right you can use a VTP files in order to view it in 3D via kiwi viewer so try to convert your file to VTP and use the same function mentioned above.
std::string dataset = [[[NSBundle mainBundle] pathForResource:#"skull" ofType:#"vtp"] UTF8String];
You can use this code in KiwiSimple (lite version of KiwiViewer) to load PLY files:
-(void) initializeKiwiApp
{
[EAGLContext setCurrentContext:self.context];
std::string dataset = [[[NSBundle mainBundle] pathForResource:#"skull" ofType:#"ply"] UTF8String];
self->mKiwiApp = vesKiwiViewerApp::Ptr(new vesKiwiViewerApp);
self->mKiwiApp->initGL();
[self resizeView];
self->mKiwiApp->loadDataset(dataset);
self->mKiwiApp->resetView();
}

Can a plist file be too big?

I'm working on a reference app that loads a plist file that can be searched.
The plist file is about 6kb with about 600 entries.
I have been working with the simulator and all works ok, however when I load it onto a device none of the data is there. Just an empty table.
I think the file may be too big because I can load a plist with 20 entries and it loads fine on the device.
If the file was too large wouldn't the whole app just crash?
Does anyone have any suggestions?
This is how I load my plist file
NSString* myFile = [[NSBundle mainBundle] pathForResource:#"myPlistFile" ofType:#"plist"];
array = [[NSMutableArray alloc] initWithContentsOfFile:myFile];
What it sounds like to me is that either your plist isn't even getting copied at all onto the device, or you're using case-sensitive file naming.
First see if the file exists at all:
NSString *myFilePath = [[NSBundle mainBundle] pathForResource:#"myPlistFile" ofType:#"plist"];
BOOL exists = [[NSFileManager defaultManager] fileExistsAtPath:myFilePath];
Check that boolean (using the debugger or by logging, either way). If the file exists, then I suspect that you're using a wrong case when trying to access the filename. Filenames are case-sensitive on iOS devices, unlike the Simulator. For example, lets say your plist was named myAwesomeStuff.plist. If you tried to access myawesomestuff.plist on the Simulator, it would work just fine. Not so on the device. Make sure you are using the correct case on your file names.

Resources