iphone - uiimage 到 iplimage

标签 iphone opencv

我尝试将黑白 UIImage 转换为 IplImage,但从控制台提供这些。可以做什么?

CGBitmapContextCreate: unsupported parameter combination: 8 integer bits/component; 16 bits/pixel; 1-component color space; kCGImageAlphaPremultipliedLast; 84 bytes/row.

CGContextDrawImage: invalid context 0x0.


notaImage = [UIImage imageWithCGImage:drawImage];
         //UIImageWriteToSavedPhotosAlbum(notaImage, self, @selector(imageSavedToPhotosAlbum: didFinishSavingWithError: contextInfo:), nil);
         vec_iphone.push_back(notaImage);    
         CGImageRef i_Ref = notaImage.CGImage;

         CGColorSpaceRef color_S = CGColorSpaceCreateDeviceGray();
             // Creating temporal IplImage for drawing
         IplImage *nota_img = cvCreateImage(
                                  cvSize(notaImage.size.width,notaImage.size.height), IPL_DEPTH_8U, 1
                                 );
             // Creating CGContext for temporal IplImage
         CGContextRef c_Ref = CGBitmapContextCreate(
                                        nota_img->imageData, nota_img->width, nota_img->height,
                                        nota_img->depth, nota_img->widthStep,
                                        color_S, kCGImageAlphaPremultipliedLast|kCGBitmapByteOrderDefault
                                      );

             // Drawing CGImage to CGContext
             CGContextDrawImage(
                                c_Ref,
                                CGRectMake(0, 0, notaImage.size.width, notaImage.size.height),
                                i_Ref
                                );

             //


             vec_images.push_back(nota_img);
             CGContextRelease(c_Ref);
             CGColorSpaceRelease(color_S);
             CGImageRelease(i_Ref);

最佳答案

由于您的输入图像是灰色的,因此您的上下文格式不包含任何 alpha channel ,因此使用 kCGImageAlphaPremultipliedLast是不正确的。试试 kCGImageAlphaNone反而。

关于iphone - uiimage 到 iplimage,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5537021/

相关文章:

ios - 我可以合并/修改通知栏中的通知吗?

iphone - 如何使用按钮添加指向网站的链接并返回到应用程序

iphone - 如何从 View 返回一个或多个值?

python - 预测鼠标书写的数字

使用 ios 5 的 iphone 5 NIB

iphone - 获取@interface 的所有变量名或属性

java - openCV 中 BROWN 颜色的 HSV 值范围是多少?

python - 用Python捕捉 Action

c# - 在 emgu cv 中查找 otsu 阈值的功能是什么?

opencv - 如何 “translate”摄像机到图像的运动?