Ask Your Question

thomket's profile - activity

2018-09-13 01:20:50 -0500 received badge  Popular Question (source)
2013-05-15 04:32:30 -0500 answered a question imread in iOS
2013-04-10 08:43:56 -0500 received badge  Scholar (source)
2013-04-04 05:50:25 -0500 answered a question How to convert CMSampleBufferRef to IplImage (iOS)
2012-09-26 04:40:43 -0500 received badge  Supporter (source)
2012-09-06 23:46:24 -0500 received badge  Teacher (source)
2012-08-22 02:43:18 -0500 answered a question Building OpenCV for iOS on Mountain Lion

I just used the pre-built framework from the website. I took it from the website, added it to my project and it worked perfectly for me.

2012-08-06 03:48:02 -0500 answered a question Converting a Buffer to a Bitmap

I found something! And I must say I was very blind.

CVImageBufferRef imageBuffer = CMSampleBufferGetImageBuffer(sampleBuffer);

size_t width = CVPixelBufferGetWidth(imageBuffer);
size_t height = CVPixelBufferGetHeight(imageBuffer);
void *baseAddress = CVPixelBufferGetBaseAddress(imageBuffer);

cv::Mat frame(height, width, CV_8UC4, (void*)baseAddress);

CVPixelBufferUnlockBaseAddress(imageBuffer, 0);

cv::cvtColor(frame, frame, CV_BGRA2RGB);

NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *filePath = [documentsDirectory stringByAppendingPathComponent:[NSString stringWithFormat:@"ocv%d.BMP", picNum]];
const char* cPath = [filePath cStringUsingEncoding:NSMacOSRomanStringEncoding];

const cv::string newPaths = (const cv::string)cPath;

cv::imwrite(newPaths, frame);

I just have to use the imwrite function from opencv. This way I get BMP-files around 24 MB directly after the bayer-filter!

2012-07-31 15:52:13 -0500 received badge  Student (source)
2012-07-31 04:11:47 -0500 received badge  Editor (source)
2012-07-31 04:11:21 -0500 asked a question Converting a Buffer to a Bitmap

Hello together, I am relatively new to opencv and trying to use it in an iOs app. OpenCV will be used for other things, too, but the first thing I'm trying to do is to create a Bitmap-Image from a CVImageBufferRef. I'm doing it that way because I need image data without any compression if possible.

The data I'm getting should be uncompressed BGRA bytes so I'm using this function

cv::cvtColor(frame, frame, CV_BGRA2GRAY);

because I only need gray values and then I turn it into a NSData-Object and save it like this:

NSData *dataForRawBytes = [NSData length:frame.elemSize()*];

[dataForRawBytes writeToFile:imageName atomically:YES];

The problem is that the data I'm getting out of this is not an image I can see, it's just symbols and stuff.

I would like to know if there are better ways to use openCV for this and is there a really good documentation for openCV especially in connection with iOs?

I'm grateful for every hint and help. Thanks!