CV :: MAT Preview image in debug mode

If the image is UIImage, we can view the image in debug mode in xcode, but I can’t for cv :: mat images, and this is normal, anyway, or any additional tool that we can add to xcode to show (or view) the image in debug mode for cv :: mat image?

+6
source share
2 answers

I don't know if I understood your question, but if you just want to show a preview of cv :: Mat, you can convert cv :: Mat to UIImage. I can show you how to do this 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 questions in StackOveflow:

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

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

0
source

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

0
source

Source: https://habr.com/ru/post/984641/


All Articles