Advertisement
Guest User

OpenCVStitch

a guest
Sep 17th, 2012
200
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.19 KB | None | 0 0
  1. + (cv::Mat)cvMatWithImage:(UIImage *)image
  2. {
  3.     CGColorSpaceRef colorSpace = CGImageGetColorSpace(image.CGImage);
  4.     CGFloat cols = image.size.width;
  5.     CGFloat rows = image.size.height;
  6.    
  7.     cv::Mat cvMat(rows, cols, CV_8UC4); // 8 bits per component, 4 channels
  8.    
  9.     CGContextRef contextRef = CGBitmapContextCreate(cvMat.data,                 // Pointer to backing data
  10.                                                     cols,                       // Width of bitmap
  11.                                                     rows,                       // Height of bitmap
  12.                                                     8,                          // Bits per component
  13.                                                     cvMat.step[0],              // Bytes per row
  14.                                                     colorSpace,                 // Colorspace
  15.                                                     kCGImageAlphaNoneSkipLast |
  16.                                                     kCGBitmapByteOrderDefault); // Bitmap info flags
  17.    
  18.     CGContextDrawImage(contextRef, CGRectMake(0, 0, cols, rows), image.CGImage);
  19.     CGContextRelease(contextRef);
  20.    
  21.     return cvMat;
  22. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement