OpenCV error when loading Fisher face recognizer in Xcode 8 - c++

I've imported opencv and opencv_contrib frameworks in an Xcode project, and in my Objective-C++ file, I load a face classifier and then a Fisher face recognizer:
// set up classifier, recognizer, and webcam
-(void) setupAnalyzer:(NSString *)faceCascadeName :(NSString *)fisherDatasetName
{
// load face classifier
cout << "loading face classifier..." << endl;
String faceCascadeNameString = string([faceCascadeName UTF8String]);
faceCascade.load(faceCascadeNameString);
// load face recognizer
cout << "loading face recognizer..." << endl;
fishface = createFisherFaceRecognizer();
String fisherDatasetNameString = string([fisherDatasetName UTF8String]);
fishface->load(fisherDatasetNameString);
}
When I call this function from Swift, it seems the face classifier loads just fine with an xml file I have in my project. But when I try to load the Fisher face recognizer using another xml file in my project, Xcode shows this error:
OpenCV Error: Unspecified error (File can’t be opened for reading!) in load, file ~/opencv/modules/face/src/facerec.cpp, line 61
libc++abi.dylib: terminating with uncaught exception of type cv::Exception: ~/opencv/modules/face/src/facerec.cpp:61: error: (-2) File can’t be opened for reading! in function load
I've tried rebuilding the OpenCV frameworks in different ways and I keep getting the same error!
First of all, I'm confused why the program is looking to source code that isn't contained in the project (it's looking for facerec.cpp in another directory on my computer). Also, why does the cascade classifier load just fine? This makes me think it's an issue with the way I built the opencv_contrib modules, because the face classifier comes from opencv_contrib. But I tried rebuilding opencv_contrib, and I still get this OpenCV error.
Any help would be greatly appreciated!
[UPDATE]
It is not an issue with building the contrib module. I manually included the module in Xcode, so it's now looking within the project for the facerec.cpp, but it still can't open the xml file for reading.

First of all, I'm confused why the program is looking to source code that isn't contained in the project (it's looking for facerec.cpp in another directory on my computer).
It doesn't search for file. It shows you where error was happen. Since your library was build on your machine and has debug information it can point you source file and line number where error happen.
libc++abi.dylib: terminating with uncaught exception of type cv::Exception: ~/opencv/modules/face/src/facerec.cpp:61: error: (-2) File can’t be opened for reading! in function load
This message means that exception was generated at line 61 in file facerec.cpp. You need to check if your data is available for reading.

Figured it out! This answer helped me realize that I needed to get the app bundle's path to the xml files: OpenCV Cascade Classifier load error iOS

Related

Failing to load a png image in SDL2

I am trying to load PNG image, but it always ends in an error. I was first trying to use SDL's SDL_LoadBMP, but since that dind't work, I downloaded SDL2_image.h, did all the setup, but it still isn't working. The image is in the same directory as the cpp file. When I run my program, it runs, but prints error. Here is the function to load the image:
void loadImage()
{
image = IMG_Load("Untitled.png");
if (image == NULL)
std::cout << "error: " << SDL_GetError();
}
The error message from SDL_GetError is Failed loading libpng16-16.dll: The specified module could not be found. I tried passing the full path, but it gives an error and I don't know how to get around that problem since I am a beginner. Thanks.
Edit: After reading through the article linked in the answer to the tagged-duplicate question and making some changes(particularly installing the missing dll file and putting it in the same directory as the main cpp flie), I am getting this error message in a pop-up window: The procedure entry point inflateValidate could not be located in the dynamic link library, and the path to libpng16-16.dll is given after that.

loadFromFile() not loading in sfml

I'm using sfml 2.1 in xcode4. ballSpriteSheet.png is in the project folder. It loads using a full file path. Why won't the file load as written? If not possible as written, can you at least set a relative path?
if(!tBall.loadFromFile("ballSpriteSheet.png"))
std::cout << "ERROR: Could not load ball sprite sheet!" << std::endl;
In output...
Failed to load image "ballSpriteSheet.png". Reason : Unable to open file
ERROR: Could not load ball sprite sheet!
Thanks in advance!
The error reffer to the image that cannot be found. Please check the image to be in the project or to be next to your '.exe' and to be named correctly.

NITE2::UserTracker crashes when reading from oni files

I have recorded an oni file using a kinect and OpenNI NIViewer.
I want to track skeletons in that record file so I am using OpenNI2 and NITE2
I can create an openi device with the oni file but when I try to create a nite2 user tracker using that device it crashes and I get the following error:
0xC0000005: Access violation reading location 0x000000000000004c
On the cmd window I got the following message:
Couldn't getXN_STREAM_PROPERTY_PARAM_COEFF
Here is my code:
openni::Status rc = openni::OpenNI::initialize();
openni::Device device ;
rc = device.open("file.oni");
nite::UserTracker userTracker;
nite::NiTE::initialize();
niteRc = userTracker.create(&device);
Any Help is largely appreciated.
Could you please also advise if there are any other ways to track selections in recorded oni files?
Regards
I also experienced your same problem.
I recorded the oni files with the OpenNI2 sample NiViewer. The recorded file can be loaded using NiViewer itself (therefore the file is not corrupt), but if I try to open the saved file with the Nite2 sample UserViewer, I experience your same error.
The only way I've found to solve the problem id downgrading from Nite 2.2 to Nite 2.0 (as suggested in Creating a UserTracker crashes in NITE2 python bindings)
The strange thing is that I tested this saving/loading procedure with both Kinect and Asus Xtion, but I had this problem only with Kinect savings.

OpenCV Fisher face error

i tried to run the fisher algorithm provided by openCV community.
http://docs.opencv.org/modules/contrib/doc/facerec/facerec_tutorial.html#tp91
But it produces the following error.
OpenCV Error: Image step is wrong (The matrix is not continuous, thus its number
of rows can not be changed) in unknown function, file
......\src\opencv\modules\core\src\matrix.cpp, line 802"
And found out that error is caused by,
Ptr<FaceRecognizer> model = createFisherFaceRecognizer();
model->train(images, labels); //Error occurs when i cal this method
Images i am feeding are the same size. following links say it could be due to release libraries.
OpenCV 2.0 C++ API using imshow: returns unhandled exception and "bad-flag"
Getting OpenCV Error "Image step is wrong" in Fisherfaces.train() method
But i removed all the release libraries from the project and using the debug mode in visual studio 2010. I am using OpenCV 2.4.5
But i could not go pass the error.
please help.
Thank you.

IImebra code in C++ app with Qt gives malloc: *** error for object xxxxxx: pointer being freed was not allocated

I'm trying to convert dicom .dcm file to .jpeg using Imebra in C++ app using Qt Creator as dev environment.
I've downloaded Imebra and was able to run Qt project example for Dicom2Jpeg conversion successfully. But when I tried to copy same code to my C++ app it failed to run with following error msg:
malloc: *** error for object xxxxxx: pointer being freed was not allocated
*** set a breakpoint in malloc_error_break to debug
I have followed steps on adding Imebra files to my project as it was shown on Imebra site. Also used their qt project as example. My main.cpp open dicom file, then loads it to dataset, then calls my dialog window. It crashes on loading dataset.
#include "QApplication.h"
#include "QHBoxLayout.h"
#include "mydialog.h"
#include "iostream.h"
include "library/imebra/include/imebra.h"
int main( int argc, char ** argv ){
using namespace puntoexe;
ptr<stream> readStream(new stream);
readStream->openFile("/pathToDcmFile/test.dcm",std::ios_base::in);
ptr<streamReader> reader(new streamReader(readStream));
ptr<imebra::codecs::codecFactory>
cFactory(imebra::codecs::codecFactory::getCodecFactory());
ptr<imebra::dataSet> tdataSet;
tdataSet=cFactory->load(reader,2048);
Q_INIT_RESOURCE(images);
QApplication a( argc, argv );
MyDialog md;
md.show();
return a.exec();
}
Deeper debugging showed that source of error is in JpegCodec.cpp file readStream() function when checking JpegSignature to see if it's in wrong format with resulting internal PUNTOEXE error "detected a wrong format".
Interesting thing is that while running same test dcm file using given dicom2jpeg example (which has exact same code of opening file and loading it) gives no errors and converts to jpeg successfully. So I know it's not the file issue, but the way imebra code is integrated into my C++ app.
My dev environment: macbook pro with Lion OS, Qt Creator, Qt project, C++ code, ITK library added, Imebra files are completely integrated as part of the Qt project.
So, my question is how do I work/link/reference/call Imebra functionality in Qt project? Am I forgetting to link something, or some object is not instantiated/deleted on time?
Any ideas are highly appreciated,
Evushka
Solution: As it was suggested I have changed codec factory to dicm factory and it fixed the problem. My new code is given below.
imebra::codecs::dicomCodec* pTmp = new imebra::codecs::dicomCodec();
ptr<stream> readStream(new stream);
readStream->openFile(argv[0],std::ios_base::in);
ptr<streamReader> reader(new streamReader(readStream));
ptr<imebra::dataSet> tdataSet;
tdataSet=pTmp->read(reader,2048);
delete pTmp;
The error "detected a wrong format" is thrown because the library checks the file against all the file formats, and since you are reading a Dicom file then the Jpeg code throws an exception, but this should be recovered by the codec factory. You may be a victim of this bug: https://bitbucket.org/puntoexe/imebra/issue/89/ which prevents the Dicom codec from registering statically at startup, causing the factory codec to skip the Dicom codec entirely. The bug report also contains a workaround.