zxing for iphone

Anyone worked with zxing (or any other QR code library) successfully in an OF iphone app? I’d be curious to hear of any glitches, hitches. The demo looks pretty straightforward (http://code.google.com/p/zxing/source/b-…-k%2Fiphone) and getting the libraries built was easy, but I’m curious if there are any pre-existing projects out there that have already used it.

I have used it in native iPhone apps and a desktop OF app.

The Desktop app is what I called “really expensive barcode scanner” as it was used with the Canon SDK/Canon 7D to scan barcodes

Here is a snippet from the main function that captured the barcode/QR code in hopes it helps


#ifndef _TEST_APP  
#define _TEST_APP  
#include "ofMain.h"  
#include "CanonCameraWrapper.h"  
#include "ofxSimpleGuiToo.h"  
#include "MultiFormatReader.h"  
#include "Result.h"  
using namespace zxing;  
class testApp : public ofBaseApp{  
		void setup();  
		void update();  
		void draw();  
		void exit();  
		void keyPressed  (int key);  
		void keyReleased(int key);  
		void mouseMoved(int x, int y );  
		void mouseDragged(int x, int y, int button);  
		void mousePressed(int x, int y, int button);  
		void mouseReleased(int x, int y, int button);  
		void windowResized(int w, int h);  
		CanonCameraWrapper *canonWrapper;  
		ofxSimpleGuiToo gui;  
		ofImage liveViewPixels;  
		MultiFormatReader *reader;  
		Ref<Result> result;  

in testApp::setup

void testApp::setup(){  
	reader = new MultiFormatReader();  

in testApp::update

			doTakePicture = false;  
			ofImage image;  
			image.setFromPixels(liveViewPixels.getPixels(), liveViewWidth, liveViewHeight, OF_IMAGE_COLOR, true);  
			unsigned char grayPixels[image.width * image.height];  
			unsigned char *imagePixels = image.getPixels();  
			for( int h=0; h<image.width; h++ )  
				for( int j=0; j<image.height; j++ )  
					int p = j * image.width + h;  
					grayPixels[ p ] = imagePixels[ p ];  
			imagesAllocated = true;  
			doUpdateLiveView = true;  
			GreyscaleLuminanceSource *source = new GreyscaleLuminanceSource(grayPixels, image.width, image.height, 0, 0, image.width, image.height);  
			HybridBinarizer *binarizer = new HybridBinarizer((Ref<LuminanceSource>) source);  
			BinaryBitmap bitmap = BinaryBitmap((Ref<Binarizer>)binarizer);  
			//Now you're ready to decode:  
			try {  
				result = reader->decode((Ref<BinaryBitmap>)bitmap);  
				String *output = result->getText();  
				upcCode = output->getText();  
				cout << "made it" << output->getText() << endl;  
			catch (ReaderException e) {  

That’s really awesome, thanks for the code snippet!

Ooooh I may resurrect a long dormant project for this, thanks

here’s an addon that runs on osx right now https://github.com/kylemcdonald/ofxZxing

specialized to read qrcodes, though it might serve as a reference for developing a more generic version.

i’d really, really like to see a version of ofxZxing for iphone, but i don’t have much experience with iOS dev…


You mean a version that runs in Objective-C?

i’m not sure about the details required for getting it to run on iphone, i was under the impression compiling a c++ lib is fine you just need to eventually call it from obj-c? i haven’t done any ios dev yet so don’t listen to me.

regardless, i was just talking to josh and he’s got it running already apparently. he’s going to clean some things up and then i’ll pull his changes.

Forked at https://github.com/joshuajnoble/ofxZxing. At the moment iphone is pretty much strictly OF0062, so that’s separated out and an arm7 lib is built (I’ll add other phone libs shortly but can’t test as I only have 1 phone). Thanks Kyle!

This is awesome, just saved me a lot of time trying to do a mashup of 062/07 iphone code and then ZXing hookup…thanks Kyle and Josh!

Hi there. What is the correct way to import the library for iOS into an existing OF project? The ofxZxing doesn’t help that much. Thank you for any help.

hi there
i cant compile ofxZxing on iPhone. there are no errors on simulator, but if i try to compile on my phone (ios 5.1.1) i always get this errors from libzing.a:

“_iconv_close”, referenced from:
__ZN5zxing6qrcode22DecodedBitStreamParser6appendERSsPKhmPKc in libzxing.a(DecodedBitStreamParser.o)
“_iconv”, referenced from:
__ZN5zxing6qrcode22DecodedBitStreamParser6appendERSsPKhmPKc in libzxing.a(DecodedBitStreamParser.o)
“_iconv_open”, referenced from:
__ZN5zxing6qrcode22DecodedBitStreamParser6appendERSsPKhmPKc in libzxing.a(DecodedBitStreamParser.o)
ld: symbol(s) not found for architecture armv7
clang: error: linker command failed with exit code 1 (use -v to see invocation)

what am i doing wrong? any hints?