Incorporating setVideoScaleAndCropFactor into iOS!

372 views
Skip to first unread message

Nathan Kellert

unread,
May 22, 2013, 8:32:35 AM5/22/13
to zx...@googlegroups.com
Hey guys! I have been searching high and low on how to zoom in and maintain proper readability when it comes to using zxing. 

I have been working for about a month on getting this app to scan tiny barcodes. Setting it to higher resolution helped a lot. However, with the iPhone not wanting to focus close objects and ZXing by default resetting any preset resolution to the bounds of the frame its been very difficult. 

I found this


which focuses on face detection(which I dont care about haha) but amazingly it shows how to use the AVFramework with setVideoScaleAndCropFactor.

I was wondering if anyone would know how to properly incorporate this with ZXing. I tested the app out and zooming into the frame it did an amazing job of getting in close and then refocusing once zoomed in. I was very impressed. 

Since zxing is not tied to a xib or a view in a storyboard but delegates itself I couldnt figure out how to add a gesture and a IBAction. So I managed to do it in the view did load. I then added - (BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer *)gestureRecognizer

{

if ( [gestureRecognizer isKindOfClass:[UIPinchGestureRecognizer class]] ) {

beginGestureScale = effectiveScale;

}

NSLog(@"we did should begin");

    return YES;

    

}



- (IBAction)handlePinchGesture:(UIPinchGestureRecognizer *)recognizer

{

BOOL allTouchesAreOnThePreviewLayer = YES;

NSUInteger numTouches = [recognizer numberOfTouches], i;

for ( i = 0; i < numTouches; ++i ) {

         NSLog(@"%lu",(unsigned long)i);

CGPoint location = [recognizer locationOfTouch:i inView: overlayView];

CGPoint convertedLocation = [prevLayer convertPoint:location fromLayer:prevLayer.superlayer];

if ( ! [prevLayer containsPoint:convertedLocation] ) {

allTouchesAreOnThePreviewLayer = NO;

            NSLog(@"we broke");

break;

}

}

if ( allTouchesAreOnThePreviewLayer ) {

effectiveScale = beginGestureScale * recognizer.scale;

if (effectiveScale < 1.0)

effectiveScale = 1.0;

CGFloat maxScaleAndCropFactor = [[output connectionWithMediaType:AVMediaTypeVideo] videoMaxScaleAndCropFactor];

if (effectiveScale > maxScaleAndCropFactor)

effectiveScale = maxScaleAndCropFactor;

[CATransaction begin];

        NSLog(@"transition started");

[CATransaction setAnimationDuration:.025];

[prevLayer setAffineTransform:CGAffineTransformMakeScale(effectiveScale, effectiveScale)];

[CATransaction commit];

        NSLog(@"commit");

}

}


from there I got it to recognize gestures but the whole screen turns black when touched. I get NSLogs that its recognizing and executing the code. Just isnt resizing the view. 


Any help would be insanely appreciated. Ive been digging around for a while. Many people have been trying to safely do this as well and I think this will finally be the answer people are waiting for I hope. 


Love your guys work and support more than you could ever know! 


-Nathan



Message has been deleted

Nathan Kellert

unread,
May 23, 2013, 3:58:16 AM5/23/13
to zx...@googlegroups.com
I figured it out and it looks amazing! Where would be the best place to add my code in the event that someone else wants it?

Nathan Kellert

unread,
May 24, 2013, 8:58:51 PM5/24/13
to zx...@googlegroups.com
Nevermind It seems that I havent set the stillImageOutput to use the stillImageConnection....

Is anyone even watching this thread? 

Steven Parkes

unread,
Jun 1, 2013, 2:39:04 PM6/1/13
to Nathan Kellert, zx...@googlegroups.com
Push it to github.

On May 23, 2013, at 12:56 AM, Nathan Kellert <na...@yoursitedesign.net> wrote:

> I figured it out and it looks amazing! Where would be a good place to add the code in the event that someone else would want it?
> --
>
> ---
> You received this message because you are subscribed to the Google Groups "zxing" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to zxing+un...@googlegroups.com.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>

James Hough

unread,
Nov 13, 2013, 9:36:24 AM11/13/13
to zx...@googlegroups.com
Hi Nathan.

Have you posted your code for this anywhere i would be interested.
Thanks

James
Reply all
Reply to author
Forward
0 new messages