Created
October 25, 2013 11:57
-
-
Save nevyn/7153525 to your computer and use it in GitHub Desktop.
Subdividing camera image into smaller regions and time multiplexing them so that I can read more than 4 markers simultaneously. Works badly. SO: http://stackoverflow.com/questions/19431661/avcapturemetadataoutput-detect-more-than-four-4-qr-codes
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- (id)init | |
{ | |
... | |
static const float w = 1. / subdivisionColumns, h = 1. / subdivisionRows; | |
int i = 0; | |
for(int y = 0; y < subdivisionRows; y++) { | |
for(int x = 0; x < subdivisionColumns; x++, i++) { | |
_regions[i] = CGRectMake(x*w, y*h, w*1.5, h*1.5); | |
} | |
} | |
[NSTimer scheduledTimerWithTimeInterval:0.2 target:self selector:@selector(changeRectOfInterest) userInfo:nil repeats:YES]; | |
return self; | |
} | |
- (void)changeRectOfInterest | |
{ | |
_currentRegionIndex = (_currentRegionIndex + 1) % (subdivisionRows*subdivisionColumns); | |
_overlay.drawThis = _metadataOutput.rectOfInterest = _regions[_currentRegionIndex]; | |
[_overlay setNeedsDisplay]; | |
} | |
- (void)captureOutput:(AVCaptureOutput *)captureOutput didOutputMetadataObjects:(NSArray *)metadataObjects fromConnection:(AVCaptureConnection *)connection | |
{ | |
_objectsInRegion[@(_currentRegionIndex)] = metadataObjects; | |
NSMutableArray *allObjects = [NSMutableArray new]; | |
NSMutableSet *allIdentifiers = [NSMutableSet new]; | |
for(NSArray *regionObjects in _objectsInRegion.allValues) { | |
for(id object in regionObjects) { | |
if(![allIdentifiers containsObject:[object stringValue]]) { | |
[allObjects addObject:object]; | |
[allIdentifiers addObject:[object stringValue]]; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment