lib/quagga.js
/**
	     * Creates a bounding box which encloses all the given patches
	     * @returns {Array} The minimal bounding box
	     */
Creates a bounding box which encloses all the given patches
@returns {Array} The minimal bounding box
Creates a bounding box which encloses all the given patches @returns { Array } The minimal bounding box
function boxFromPatches(patches) {
	        var overAvg,
	            i,
	            j,
	            patch,
	            transMat,
	            minx = _binaryImageWrapper.size.x,
	            miny = _binaryImageWrapper.size.y,
	            maxx = -_binaryImageWrapper.size.x,
	            maxy = -_binaryImageWrapper.size.y,
	            box,
	            scale;
	        overAvg = 0;
	        for (i = 0; i < patches.length; i++) {
	            patch = patches[i];
	            overAvg += patch.rad;
	            if (false) {
	                _image_debug2.default.drawRect(patch.pos, _subImageWrapper.size, _canvasContainer.ctx.binary, { color: "red" });
	            }
	        }
	        overAvg /= patches.length;
	        overAvg = (overAvg * 180 / Math.PI + 90) % 180 - 90;
	        if (overAvg < 0) {
	            overAvg += 180;
	        }
	        overAvg = (180 - overAvg) * Math.PI / 180;
	        transMat = mat2.copy(mat2.create(), [Math.cos(overAvg), Math.sin(overAvg), -Math.sin(overAvg), Math.cos(overAvg)]);
	        for (i = 0; i < patches.length; i++) {
	            patch = patches[i];
	            for (j = 0; j < 4; j++) {
	                vec2.transformMat2(patch.box[j], patch.box[j], transMat);
	            }
	            if (false) {
	                _image_debug2.default.drawPath(patch.box, { x: 0, y: 1 }, _canvasContainer.ctx.binary, { color: '#99ff00', lineWidth: 2 });
	            }
	        }
	        for (i = 0; i < patches.length; i++) {
	            patch = patches[i];
	            for (j = 0; j < 4; j++) {
	                if (patch.box[j][0] < minx) {
	                    minx = patch.box[j][0];
	                }
	                if (patch.box[j][0] > maxx) {
	                    maxx = patch.box[j][0];
	                }
	                if (patch.box[j][1] < miny) {
	                    miny = patch.box[j][1];
	                }
	                if (patch.box[j][1] > maxy) {
	                    maxy = patch.box[j][1];
	                }
	            }
	        }
	        box = [[minx, miny], [maxx, miny], [maxx, maxy], [minx, maxy]];
	        if (false) {
	            _image_debug2.default.drawPath(box, { x: 0, y: 1 }, _canvasContainer.ctx.binary, { color: '#ff0000', lineWidth: 2 });
	        }
	        scale = _config.halfSample ? 2 : 1;
	        transMat = mat2.invert(transMat, transMat);
	        for (j = 0; j < 4; j++) {
	            vec2.transformMat2(box[j], box[j], transMat);
	        }
	        if (false) {
	            _image_debug2.default.drawPath(box, { x: 0, y: 1 }, _canvasContainer.ctx.binary, { color: '#ff0000', lineWidth: 2 });
	        }
	        for (j = 0; j < 4; j++) {
	            vec2.scale(box[j], box[j], scale);
	        }
	        return box;
	    }
function boxFromPatches ( patches ) { var overAvg , i , j , patch , transMat , minx = _binaryImageWrapper . size . x , miny = _binaryImageWrapper . size . y , maxx = - _binaryImageWrapper . size . x , maxy = - _binaryImageWrapper . size . y , box , scale ; overAvg = 0 ; for ( i = 0 ; i < patches . length ; i ++ ) { patch = patches [ i ] ; overAvg += patch . rad ; if ( false ) { _image_debug2 . default . drawRect ( patch . pos , _subImageWrapper . size , _canvasContainer . ctx . binary , { color : "red" } ) ; } } overAvg /= patches . length ; overAvg = ( overAvg * 180 / Math . PI + 90 ) % 180 - 90 ; if ( overAvg < 0 ) { overAvg += 180 ; } overAvg = ( 180 - overAvg ) * Math . PI / 180 ; transMat = mat2 . copy ( mat2 . create ( ) , [ Math . cos ( overAvg ) , Math . sin ( overAvg ) , - Math . sin ( overAvg ) , Math . cos ( overAvg ) ] ) ; for ( i = 0 ; i < patches . length ; i ++ ) { patch = patches [ i ] ; for ( j = 0 ; j < 4 ; j ++ ) { vec2 . transformMat2 ( patch . box [ j ] , patch . box [ j ] , transMat ) ; } if ( false ) { _image_debug2 . default . drawPath ( patch . box , { x : 0 , y : 1 } , _canvasContainer . ctx . binary , { color : '#99ff00' , lineWidth : 2 } ) ; } } for ( i = 0 ; i < patches . length ; i ++ ) { patch = patches [ i ] ; for ( j = 0 ; j < 4 ; j ++ ) { if ( patch . box [ j ] [ 0 ] < minx ) { minx = patch . box [ j ] [ 0 ] ; } if ( patch . box [ j ] [ 0 ] > maxx ) { maxx = patch . box [ j ] [ 0 ] ; } if ( patch . box [ j ] [ 1 ] < miny ) { miny = patch . box [ j ] [ 1 ] ; } if ( patch . box [ j ] [ 1 ] > maxy ) { maxy = patch . box [ j ] [ 1 ] ; } } } box = [ [ minx , miny ] , [ maxx , miny ] , [ maxx , maxy ] , [ minx , maxy ] ] ; if ( false ) { _image_debug2 . default . drawPath ( box , { x : 0 , y : 1 } , _canvasContainer . ctx . binary , { color : '#ff0000' , lineWidth : 2 } ) ; } scale = _config . halfSample ? 2 : 1 ; transMat = mat2 . invert ( transMat , transMat ) ; for ( j = 0 ; j < 4 ; j ++ ) { vec2 . transformMat2 ( box [ j ] , box [ j ] , transMat ) ; } if ( false ) { _image_debug2 . default . drawPath ( box , { x : 0 , y : 1 } , _canvasContainer . ctx . binary , { color : '#ff0000' , lineWidth : 2 } ) ; } for ( j = 0 ; j < 4 ; j ++ ) { vec2 . scale ( box [ j ] , box [ j ] , scale ) ; } return box ; }
Creates a bounding box which encloses all the given patches
 @returns {Array} The minimal bounding box
Creates a bounding box which encloses all the given patches @returns { Array } The minimal bounding box
// draw all patches which are to be taken into consideration // iterate over patches and rotate by angle // find bounding box // reverse rotation;