我遇到同樣的問題。我還沒有找到解決方案,但我建議首先確保您的ios cv :: Mat的色彩空間匹配到計算機上的色彩空間。請記住,默認情況下,openCV使用BGR。我添加了一些代碼來幫助檢查。
cv::Vec4b rgbPixel = m.at<cv::Vec4b>(100,100);
CGImageRef cgimage = image.CGImage;
size_t bpr = CGImageGetBytesPerRow(cgimage);
size_t bpp = CGImageGetBitsPerPixel(cgimage);
size_t bpc = CGImageGetBitsPerComponent(cgimage);
size_t bytes_per_pixel = bpp/bpc;
CGDataProviderRef provider = CGImageGetDataProvider(cgimage);
NSData* data = (id)CFBridgingRelease(CGDataProviderCopyData(provider));
const uint8_t* bytes = (const uint8_t *) [data bytes];
const uint8_t *pixel = &bytes[100 * bpr + 100 * bytes_per_pixel];
NSLog(@"bgr pixel %d %d %d %d rows %d cols %d",rgbPixel[0],rgbPixel[1], rgbPixel[2], rgbPixel[3], m.rows, m.cols);
NSLog(@"rgb bpr %lu bpp %lubpc %lu Bpp %lu rows %f cols %f", bpr, bpp, bpc, bytes_per_pixel, rows,cols);
NSLog(@"rgb piexel %d %d %d %d", pixel[0],pixel[1],pixel[2], pixel[3]);
兩臺計算機上的OpenCV版本相同嗎? – Miki
@Miki,是的!都是3.0 – jaycwb92