CV::MAT preview the image in debug mode CV::MAT preview the image in debug mode xcode xcode

CV::MAT preview the image in debug mode


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


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?


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...