Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- + (cv::Mat)cvMatWithImage:(UIImage *)image
- {
- CGColorSpaceRef colorSpace = CGImageGetColorSpace(image.CGImage);
- CGFloat cols = image.size.width;
- CGFloat rows = image.size.height;
- cv::Mat cvMat(rows, cols, CV_8UC4); // 8 bits per component, 4 channels
- CGContextRef contextRef = CGBitmapContextCreate(cvMat.data, // Pointer to backing data
- cols, // Width of bitmap
- rows, // Height of bitmap
- 8, // Bits per component
- cvMat.step[0], // Bytes per row
- colorSpace, // Colorspace
- kCGImageAlphaNoneSkipLast |
- kCGBitmapByteOrderDefault); // Bitmap info flags
- CGContextDrawImage(contextRef, CGRectMake(0, 0, cols, rows), image.CGImage);
- CGContextRelease(contextRef);
- return cvMat;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement