Monday, July 9, 2012

opencv ios file/device i/o

I found that imread is not working under ios. At least for png/jpg in the simulator. Maybe it is all about the license issue. Video capture is not working either according to some tutorials, which I did not test.

I have to use ios native api such as UIImage and then convert it to cv::Mat.

ios texture from UIImage

CGContextRef spriteContext = CGBitmapContextCreate(spriteData, width, height, 8, width*4, CGImageGetColorSpace(spriteImage), kCGImageAlphaPremultipliedLast);

This function is employed in many tutorials. There is trick with alpha channel. It seems to fill no zero alpha pixels only. spriteData here has to be set to zero first. Otherwise, the background will be random.