Take the 2-minute tour ×

My iOS app is supposed to perform the following two tasks at the same time:

  1. scan for QR tags using the ZBar SDK,
  2. scan for augmented reality markers using the QCAR SDK.

Or in other words: I'm looking for QR tags surrounded by AR marker.

Both tasks should run in "real time". My first naive approach showed that combining both SDKs in one app will cause the SDK which was initialized first to stop working when the second SDK is initialized.

Does anybody have suggestions? Thanks.

share|improve this question
add comment

2 Answers

up vote 6 down vote accepted

I managed to get that done. In case someone likes to know:

QCAR only works with full camera access. Therefore, it has to be initialized and started as shown in its documentation. Luckily, it provides access to the processed camera image as raw RGB data. I used this code to convert the raw data into an UIImage:

QCAR::setFrameFormat(QCAR::GRAYSCALE, true);
const QCAR::Image *image = state.getFrame().getImage(1); // 0: YUV, 1: Grayscale image
const char *data = (const char *)image->getPixels();
int width = image->getWidth(); int height = image->getHeight();

CGColorSpace *colorSpace = CGColorSpaceCreateDeviceGray();
CGBitmapInfo bitmapInfo = kCGBitmapByteOrderDefault;
CGDataProvider *provider = CGDataProviderCreateWithData(NULL, data, width*height, NULL);
CGColorRenderingIntent intent = kCGRenderingIntentDefault;
CGImageRef imageRef = CGImageCreate(width, height, 8, 8, width * 1, colorSpace, bitmapInfo, provider, NULL, NO, intent);
myUIImage = [UIImage imageWithCGImage:imageRef];

Now, you can use ZBar's ZBarImageScanner class like this:

ZBarImageScanner *imageScanner = [[ZBarImageScanner alloc] init];
ZBarImage *image = [[ZBarImage alloc] initWithCGImage:myUIImage.CGImage];
int result = [imageScanner scanImage:image];

if (result > 0) {
 ZBarSymbolSet *symbols = imageScanner.results;
 for(ZBarSymbol *symbol in symbols) {
  NSLog(@"%@", symbol.data);
share|improve this answer
Awesome glad to see that this can be done. –  Randall Dec 5 '11 at 14:50
add comment

You can only have one camera session running at a time so you'll need to figure out how to get ZBar and QCar to use the same one.

share|improve this answer
Alright, thank you. I guess I have to dig quite deep in the SDKs then. –  Morin Nov 30 '11 at 8:15
add comment

Your Answer


