5

if the image is UIImage we can view the image in the debug mode in xcode, but I can't for cv::mat images and it's normal, so is there anyway or any add-on tool we can add to xcode to show (or view) the image in the debug mode for cv::mat image?

Hazem Abdullah
  • 1,837
  • 4
  • 23
  • 41

3 Answers3

1

If you can use CLion instead Xcode you can utilize the OpenCV Image Viewer plugin, which displays matrices while debugging just on click.

https://plugins.jetbrains.com/plugin/14371-opencv-image-viewer

enter image description here

Disclaimer: I'm an author of this plugin

dragon7
  • 1,057
  • 9
  • 23
0

You should create an ios project which installs opencv2.framework in it, and drag your cpp code to that project, make an new entry to run then you should be able to use the above convert code to view a mat as UIImage...

  • Welcome to StackOverflow! I would recommend you to write properly formatted sentences with no proper grammatical structure. – BusyProgrammer Feb 17 '17 at 02:42
-1

I don't know if I understood your question, but if you wanna simply display a cv::Mat preview, you can convert the cv::Mat to UIImage. I can show you how to do that in Objective-C:

-(UIImage *)UIImageFromCVMat:(cv::Mat)cvMat
{
    NSData *data = [NSData dataWithBytes:cvMat.data length:cvMat.elemSize()*cvMat.total()];
    CGColorSpaceRef colorSpace;

    if (cvMat.elemSize() == 1) {
        colorSpace = CGColorSpaceCreateDeviceGray();
    } else {
        colorSpace = CGColorSpaceCreateDeviceRGB();
    }

    CGDataProviderRef provider = CGDataProviderCreateWithCFData((__bridge CFDataRef)data);

    // Creating CGImage from cv::Mat
    CGImageRef imageRef = CGImageCreate(cvMat.cols,                                    //width
                                    cvMat.rows,                                 //height
                                    8,                                          //bits per component
                                    8 * cvMat.elemSize(),                       //bits per pixel
                                    cvMat.step[0],                            //bytesPerRow
                                    colorSpace,                                 //colorspace
                                    kCGImageAlphaNone|kCGBitmapByteOrderDefault,// bitmap info
                                    provider,                                   //CGDataProviderRef
                                    NULL,                                       //decode
                                    false,                                      //should interpolate
                                    kCGRenderingIntentDefault                   //intent
                                    );


    // Getting UIImage from CGImage
    UIImage *finalImage = [UIImage imageWithCGImage:imageRef];
    CGImageRelease(imageRef);
    CGDataProviderRelease(provider);
    CGColorSpaceRelease(colorSpace);
    return finalImage;
}

If this is what you asked, there are a lot of similar question on StackOveflow:

how to convert from cvMat to UIImage in objective-c?

how to convert from cvMat to UIImage in objective-c?

Community
  • 1
  • 1
Adda_25
  • 498
  • 7
  • 12