zbar IOS screen freezes - iphone

I am integrating zbar in my iphone application and below is the code for scanning the barcode.
ZBarReaderViewController *reader = [ZBarReaderViewController new];
reader.readerDelegate = self;
reader.supportedOrientationsMask = ZBarOrientationMaskAll;
ZBarImageScanner *scanner = reader.scanner;
[scanner setSymbology: ZBAR_I25
config: ZBAR_CFG_ENABLE
to: 0];
[self presentModalViewController: reader
animated: YES];
On completion, i will do the following.
- (void) imagePickerController: (UIImagePickerController*) reader
didFinishPickingMediaWithInfo: (NSDictionary*) info
{
id<NSFastEnumeration> results =
[info objectForKey: ZBarReaderControllerResults];
ZBarSymbol *symbol = nil;
for(symbol in results)
break;
// Do what ever u want
[reader dismissModalViewControllerAnimated: YES];
}
The problem with this is, i am using IOS7 and its scanning perfectly in the first instance, however, for the second instance, after it scans, it wont proceed further, even the cancel button wont work and the screen remains in camera mode. I read its an issue with cpu and memory for IOS7 but could not figure out how it can be rectified in my case. Kindly give your valuable inputs.

Okay, first, please ignore the comment I made about subclassing ZBarReaderView. It was a while ago that I was having problems, and even though I remember trying that, that was not the solution I settled for. I have a couple of suggestions for you.
In the bit of code on top after presentViewController:animated: try setting the pointer to the reader to nil. I do the following:
[self presentViewController:reader animated:YES completion:nil];
reader = nil;
The view controller you're presenting will be holding onto the reader, so don't worry about losing the reference. I think this actually helps with memory. (And, when you're having a problem where things work at first and then fail after doing them more than once, that's often a memory issue.)
Apart from that, in the top bit, I turn off all the symbols, and then enable only the ones I'm interested in. For example, I might do something like this:
// Enable only ISBN-13 & ISBN-10 barcodes
[scanner setSymbology:0 config:ZBAR_CFG_ENABLE to:0];
[scanner setSymbology:ZBAR_EAN13 config:ZBAR_CFG_ENABLE to:1];
[scanner setSymbology:ZBAR_ISBN10 config:ZBAR_CFG_ENABLE to:1];
Give these two suggestions a try, especially the first one about setting the reference to nil. That may help.

Related

Zbar SDK and ios7/xcode 5 - App is reaching 100% cpu use and memory more than 100MB

We are using Zbar bar code reader from last 2 years. With iOS 7 and Xcode 5, after scanning 5 bar codes the app is reaching 100 % cpu use for iOS 7 device(I can see that in Xcode debug mode) and app become less responsive. We never had issue in earlier iOS versions, everything worked fine.
Is thing changed in iOS 7 related to camera launching and ZBar SDK is not updated? Is anyone else facing same issue with iOS 7?
Solved doing this:
in the viewdidload
readerqr = [ZBarReaderViewController new];
readerqr.readerDelegate = self;
readerqr.showsHelpOnFail = NO;
ZBarImageScanner *scanner = readerqr.scanner;
[scanner setSymbology: 0
config: ZBAR_CFG_ENABLE
to: 0];
[scanner setSymbology: ZBAR_QRCODE
config: ZBAR_CFG_ENABLE
to: 1];
// you can use this to support the simulator
if(TARGET_IPHONE_SIMULATOR) {
cameraSim = [[ZBarCameraSimulator alloc]
initWithViewController: self];
cameraSim.readerView = readerView;
}
create ZBarReaderViewController *readerqr; as a property of your viewcontroller.
to use it:
-(void) showqr:(id)sender
{
[self presentViewController:readerqr animated:YES completion:nil];
return;
}
This way works, no leak, no cpu 100%
After seeing the same issue,
I moved from
ZBarReaderViewController
to
ZBarReaderView
The disappointing part of this, though, is if you are using features like Overlay in the ZBarReaderViewController, you have to recode how that all works and you have to implement things like starting and stopping the scanner, manually.
But essentially, you need something like this in your IBAction:
ZBarReaderView *reader = [ZBarReaderView new];
[self.view addSubview:reader];
reader.readerDelegate = self;
reader.tracksSymbols=YES;
ZBarImageScanner *scanner = reader.scanner;
reader.tag = 99999999;
// the important part here is to START the scanning
[reader start];
Also, remember to change your delegate in your header to ZBarReaderViewDelegate
Also, the delegate "method" that gets called, at least in my code, is now (versus the imagePickerController)
-(void) readerView: (ZBarReaderView*) view
didReadSymbols: (ZBarSymbolSet*) syms
fromImage: (UIImage*) img
{
for(ZBarSymbol *sym in syms) {
[view stop];
[self closeCameraScanner];
// I am also setting reader to NIL but I don't really know if this is necessary or not.
reader=nil;
}
}
-(void)closeCameraScanner{
UIView * v = [self.view viewWithTag:99999999];
if (nil != v) {
[v removeFromSuperview];
}
[self.view endEditing:YES];
}
So, that's a quick and dirty way to do this. I have some additional code for manually creating the overlay and for limiting the scan crop but as far as simply getting it running, this did the trick for me.
I solved the problem that Barry Mc G had.
I had the same issues even after patched zBar SDK with iOS7 from http://nerdvision.net/app-development/ios/zbar-sdk.
( 5th - 6th time opening the page it freezes at 100% CPU.)
Whether you subclass ZBarViewController or use it directly, you present the view controller and dismiss it later when you're done with the scanner. I found the reason why this happens and the reason was I didn't stop the video streaming. In ZBarReaderView, there's a function - (void)stop; and if you run this function after you are done with the scanner, you won't see the problem ( 5th - 6th time opening the page it freezes at 100% CPU.). At least in my case it worked and hope it works for you as well.
i fixed the issue now with implementing the Diff from the source.
If someone of you need it, you can download the compiled zBar SDK with iOS7 Support here.
You can just replace the libzbar.a - this should work. But i uploaded the complete SDK as someone may need it too with headers etc.
http://nerdvision.net/app-development/ios/zbar-sdk
I was same issue and easily fixed.
Do not remember about below code.
You must put this code when out of reader view.
[readerview stop];
cpu over load issue was cause by duplicated camera stream.
had same Problems, Scanner seems to be freeze ..
I fixed it like joaquin ...
Make a Property for the reader and when you call it multiple times you can check, if a Object of the reader where initialize ...
Here is what i´m doing:
- (IBAction)ShowZBarReader
{
// ADD: present a barcode reader that scans from the camera feed
if (!self.reader) {
self.reader = [[ZBarReaderViewController alloc]init];
}
self.reader.readerDelegate = self;
self.reader.supportedOrientationsMask = ZBarOrientationMaskAll;
ZBarImageScanner *scanner = self.reader.scanner;
// zusätliche Configurationen ...
[scanner setSymbology: ZBAR_I25
config: ZBAR_CFG_ENABLE
to: 0];
// stellt Bild zur verfügung
[self presentViewController:self.reader animated:YES completion:nil];
}
Worked perfectly for me ! Hope it helps :)

ZBarCode reader some times showing wrong scanning data in iOS

I am facing one little issue using ZBarCode reader in iPhone, i have implemented ZBarCode and it is working successfully, however some times it usually add an integer value 0 at the beginning after scanning bar code and due to this some times result are not coming accurately, please let me know if i am doing some thing wrong.
For Bar Code and QR code scanning i have created full detailed tutorial and posted sample code. and it gives me every time perfect info.
How to use Barcode Scanner (BR and QR) in iPhone Tutorial (using ZBar)
Here is the core logic.
startScanning method body this way
- (IBAction)startScanning:(id)sender {
NSLog(#"Scanning..");
resultTextView.text = #"Scanning..";
ZBarReaderViewController *codeReader = [ZBarReaderViewController new];
codeReader.readerDelegate=self;
codeReader.supportedOrientationsMask = ZBarOrientationMaskAll;
ZBarImageScanner *scanner = codeReader.scanner;
[scanner setSymbology: ZBAR_I25 config: ZBAR_CFG_ENABLE to: 0];
[self presentViewController:codeReader animated:YES completion:nil];
}
Implement ZBar's Delegate method
- (void) imagePickerController: (UIImagePickerController*) reader didFinishPickingMediaWithInfo: (NSDictionary*) info
{
// get the decode results
id<NSFastEnumeration> results = [info objectForKey: ZBarReaderControllerResults];
ZBarSymbol *symbol = nil;
for(symbol in results)
// just grab the first barcode
break;
// showing the result on textview
resultTextView.text = symbol.data;
resultImageView.image = [info objectForKey: UIImagePickerControllerOriginalImage];
// dismiss the controller
[reader dismissViewControllerAnimated:YES completion:nil];
}
Could you post code you are using? Maybe you are using old referecne? Make sure all references are pointing nil value before parsing new scanned data.

ZBarReader QR Code detection time

In my app i'm using ZBarReader, and i can able to detect the QRCode and BarCode using the code
ZBarReaderViewController *reader = [ZBarReaderViewController new];
reader.readerDelegate = self;
reader.supportedOrientationsMask = ZBarOrientationMaskAll;
ZBarImageScanner *scanner = reader.scanner;
// TODO: (optional) additional reader configuration here
// EXAMPLE: disable rarely used I2/5 to improve performance
[scanner setSymbology:0 config:ZBAR_CFG_ENABLE to:0];
[scanner setSymbology: ZBAR_QRCODE
config: ZBAR_CFG_ENABLE
to: 1];
reader.tracksSymbols=YES;
reader.readerView.zoom=1.0;
// present and release the controller
[self presentModalViewController: reader
animated: YES];
[reader release];
But it detects the code only when i make my camera much closer to the barcode, it's not detecting when i keep my camera little far from barcode Is there any property to scan the code very Quickly even when i have camera far from barcode..
Basically Zbar reader depends on the camera resolution of the device but still try using
reader.readerView.session.sessionPreset = AVCaptureSessionPreset1280x720;
adjust AVCaptureSessionPreset1280x720 .May this helps.

ZBar API Embedded Scanner Blur issue

I am using ZBar iPhone SDK in one of my projects (iOS SDK 5.1 ,XCode 4.4.1 and device running iOS 5.5.1). I am using the embedded scanner from the examples provided in the SDk itself.
Now the issue which I am facing is that I successfully scan a bar code and move to another view controller ( using navigation controller). When I come back (pop the second view controller) the scanner i.e the ZBarReaderView doesn't scan the subsequent bar codes , infact the overlay shows a blur image of the scanned barcode and is never able to scan it properly.
This is what all I have implemented . In BarScannerViewController.h I have declared
ZBarReaderView* readerView;
with property
#property (nonatomic , retain) IBOutlet UIImageView* imgvScannedBarCode;
Now this is connected to one of the views in xib.
Finally I use set up the required methods as follows -
- (void)viewDidLoad {
[super viewDidLoad];
// the delegate receives decode results
readerView.readerDelegate = self;
[readerView start];
}
- (void) viewDidAppear: (BOOL) animated {
// run the reader when the view is visible
[activityIndicatorScanning startAnimating];
[readerView start];
}
- (void) viewWillDisappear: (BOOL) animated {
[activityIndicatorScanning stopAnimating];
[readerView stop];
}
With all this set up when I scan any bar code say EAN123 for the first time I get the call back in
- (void) readerView: (ZBarReaderView*) view
didReadSymbols: (ZBarSymbolSet*) syms
fromImage: (UIImage*) img
{
// do something useful with results
ZBarSymbol *symbol = nil;
for(symbol in syms) {
barCodeFound = YES;
break;
}
// EXAMPLE: do something useful with the barcode data
NSLog(#"%#",symbol.data);
}
but on subsequent runs (After I push a view and come back on this screen again) I get blurred view.
Am I missing something here ? Any help/Suggestion/Comments would be helpful.
Here's the code that I use to start (and endlessly restart) the scanner. Interestingly, I note that I never stop the scan, but it works very reliably.
- (void) startScan
{
ZBarReaderViewController *reader = [ZBarReaderViewController new];
reader.readerDelegate = self;
ZBarImageScanner *scanner = reader.scanner;
[scanner setSymbology: ZBAR_I25
config: ZBAR_CFG_ENABLE
to: 0];
// present and release the controller
[self presentViewController:reader animated:YES completion:nil]; // Modal
[reader release];
}
I could solve the Blur issue by reconfiguring the SDK in my project. I followed the embedded scanner example as provided on ZBarSDk. I guess I might have missed some essential settings while configuring it earlier.

ZBarReaderView with custom size from storyboard moving after start is called

i've got a ZBarReaderView created from storyboard with 216x20 px which is shown as roughly 230x50 px because ZBarReaderView doesn't take it's size too serious...
It all works very well, however it behaves really strange when I call start on that readerView. It starts the cam but then in maybe half a second the readerView zooms a bit and the camera picture inside the readerView moves down and then up again.
It's not terrible but it look kinda bad. Anyone got any ideas what might be causing this and how to solve it? Maybe the sdk has some sort of hidden callback for the readiness of the scanner, i could hide it until the scanner says it's ready and then show the scanner like .5 seconds later...
barcodeReader is the iboutlet to the ZBarReaderView and scannerLoading is an iboutlet to a uiactivityindicatorview which is animating until the scanner is loaded.
These are the only settings which are changed from default, except the frame which is set in the storyboard of course.
[barcodeReader setReaderDelegate:self];
[barcodeReader setAllowsPinchZoom:false];
[barcodeReader start];
/* this works because [barcodeReader start] blocks ui updates until the scanner
is running, i know it's not a good solution but since there doesn't seem to
be a callback or delegate method like scannerDidStart or something it seems
to be the only way... */
[scannerLoading stopAnimating];
Thanks for your help!
I just posted an answer to a retaliated question:
ZBarReadview with custom size from StoryBoard,but when it's called,it's size is not I set
Maybe the answer also solves your problem.
In short:
When using Interface Builder or Storyboard to create a view and assign the ZBarReaderView to it, you have to check "Clip Subviews" in the properties for the camera image to keep the size of the view.
Just add another view to make it as cameraoverlayview with an image view having the image which is having required part of it as transparent.then in the button action `
// ADD: present a barcode reader that scans from the camera feed
ZBarReaderViewController *reader = [ZBarReaderViewController new];
reader.readerDelegate = self;
reader.supportedOrientationsMask = ZBarOrientationMaskAll;
reader.sourceType=UIImagePickerControllerSourceTypeCamera;
//reader.cameraDevice = UIImagePickerControllerCameraDeviceFront;
reader.cameraOverlayView=cameraOverlay;
if( [UIImagePickerController isCameraDeviceAvailable: UIImagePickerControllerCameraDeviceFront ])
{
reader.cameraDevice = UIImagePickerControllerCameraDeviceFront;
}
ZBarImageScanner *scanner = reader.scanner;
reader.wantsFullScreenLayout = YES;
// TODO: (optional) additional reader configuration here
// EXAMPLE: disable rarely used I2/5 to improve performance
[scanner setSymbology: ZBAR_I25
config: ZBAR_CFG_ENABLE
to: 0];
reader.showsZBarControls = NO;
// present and release the controller
[self presentModalViewController:reader animated:YES];
//[appdel.navigationController pushViewController:reader animated:YES];
//[reader.view addSubview:collect];
[reader release];add this and then also add
`- (void) imagePickerController: (UIImagePickerController*) reader
didFinishPickingMediaWithInfo: (NSDictionary*) info
{
// ADD: get the decode results
id results =
[info objectForKey: ZBarReaderControllerResults];
ZBarSymbol *symbol = nil;
for(symbol in results)
// EXAMPLE: just grab the first barcode
break;
[self rewards:symbol.data];
}
`
as a method .hope this will solve your issue