Ask Your Question
0

CGBitmapContextCreate: invalid data bytes/row error

asked 2013-04-24 05:26:33 -0500

iOSDev gravatar image

updated 2013-04-24 05:33:03 -0500

I am new to OpenCV, I tried this image processing code

I am changing color image to grayscale on click of button using below code :

- (IBAction)grayScaleBtnClicked:(id)sender
 {
    cv::Mat tempMat = [self cvMatGrayFromUIImage:image];
    _imageView.image = [self UIImageFromCVMat:tempMat];
}

But getting error as

<Error>: CGBitmapContextCreate: invalid data bytes/row: should be at least 2000 for 8 integer bits/component, 3 components, kCGImageAlphaNoneSkipLast. 
<Error>: CGContextDrawImage: invalid context 0x0

Any idea?

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
0

answered 2016-10-17 04:20:58 -0500

Replace the line

cv::Mat cvMat(rows, cols, CV_8UC1); // 8 bits per component, 1 channels

                              with

cv::Mat rgba(rows, cols, CV_8UC4, Scalar(1,2,3,4)); // 8 bits per component, 4 channels

in the following link : http://docs.opencv.org/trunk/d3/def/t...

  • (cv::Mat)cvMatGrayFromUIImage:(UIImage *)image { .... ... ... }
edit flag offensive delete link more
Login/Signup to Answer

Question Tools

Stats

Asked: 2013-04-24 05:26:33 -0500

Seen: 1,413 times

Last updated: Apr 24 '13