0

I am trying to figure out issue with my code. I am trying to process image using OpenCV in my iOS application. i have written method and did bridge-header as its here.

Here is my .h file:

#ifndef OpenCVWrapper_h
#define OpenCVWrapper_h

#endif

#import<UIKit/UIKit.h>
#import<Foundation/Foundation.h>

@interface OpenCVWrapper: NSObject
+(NSSTring*) processImageWithOpenCV:(UIImage*)inputImage;
@end

my .mm file is

#import <Foundation/Foundation.h>
#include "OpenCVWrapper.h"
#import "UIImage+OpenCV.h"
#import "UIKit/UIKit.h"
#include <opencv2/opencv.hpp>

using namespace std;
using namespace cv;

@implementation OpenCVWrapper : NSObject
+(NSString*) processImageWithOpenCV:(UIImage*)inputImage{
    Mat mat = [inputImage CVMat];
    /////////////Image processing etc

    char *cstr = new char[Reading.length() + 1];
    strcpy(cstr, Reading.c_str());
    reverse(cstr, cstr + strlen(cstr));
    const char* str = reinterpret_cast<const char*>(cstr);
    NSString* string = [NSString stringWithUTF8String:str];

    return string;
}      /////// I get error here
@end
    return "Success"

Here is how i am calling this method:

let reading = OpenCVWrapper.processImageWithOpenCV(Image)

I get error as mentioned in above code. First error is

`thread 1 signal sigabrt`

and when i try to continue. i get:

`Thread1: EXC_BAD_INSTRUCTION (code=EXC_i386_INVOP, subcode=0x0)`

I am stuck here for 2 days and unable to find right direction. There is no stack trace. just output of what i am printing in log.

Please point me to right direction.

Regards.

Community
  • 1
  • 1
Saghir A. Khatri
  • 3,429
  • 6
  • 45
  • 76
  • A couple of thoughts - the `Image` you pass in, is it a class or an instance of an images (asking because its capitalized)? Also, have you tried setting a breakpoint for "All Exceptions" and seeing where that ends up? – dokun1 Mar 07 '16 at 11:11
  • 1
    plz show us where str comes from - I have the suspicion that it doesn't belong to you and the app crashes when that is deallocated. You could just remove the NSString call as a test. just return @"" – Daij-Djan Mar 07 '16 at 11:14
  • its an instance of UIImage – Saghir A. Khatri Mar 07 '16 at 11:14
  • well i am updating my code. on returning @"". i get same issue – Saghir A. Khatri Mar 07 '16 at 11:16
  • @Daij-Djan i have updated the code. please check. it is printing the str value. but same issue at `{` – Saghir A. Khatri Mar 07 '16 at 11:25
  • loose the cast. and don't use str but cstr – Daij-Djan Mar 07 '16 at 13:15
  • I'd try to identify exactly which line is crashing using log statements. Maybe use `strrev` instead of `reverse` - if it's doing a literal reverse maybe it's putting the null termination on the front, thus messing up the string – Rich Tolley Mar 07 '16 at 13:16
  • @Daij-Djan i removed the str, and used cstr. no NSString conversion. but still same issue – Saghir A. Khatri Mar 08 '16 at 08:50
  • @RichTolley i also removed reverse and instead i wrote a loop to reverse the char series. but issue is same.... I am wondering why it isn't shwing any log in output window. :( – Saghir A. Khatri Mar 08 '16 at 08:51

0 Answers0