lib/quagga.js
/**
	     * finds patches which are connected and share the same orientation
	     * @param {Object} patchesFound
	     */
finds patches which are connected and share the same orientation
@param {Object} patchesFound
finds patches which are connected and share the same orientation @param { Object } patchesFound
function rasterizeAngularSimilarity(patchesFound) {
	        var label = 0,
	            threshold = 0.95,
	            currIdx = 0,
	            j,
	            patch,
	            hsv = [0, 1, 1],
	            rgb = [0, 0, 0];
	        function notYetProcessed() {
	            var i;
	            for (i = 0; i < _patchLabelGrid.data.length; i++) {
	                if (_patchLabelGrid.data[i] === 0 && _patchGrid.data[i] === 1) {
	                    return i;
	                }
	            }
	            return _patchLabelGrid.length;
	        }
	        function trace(currentIdx) {
	            var x,
	                y,
	                currentPatch,
	                idx,
	                dir,
	                current = {
	                x: currentIdx % _patchLabelGrid.size.x,
	                y: currentIdx / _patchLabelGrid.size.x | 0
	            },
	                similarity;
	            if (currentIdx < _patchLabelGrid.data.length) {
	                currentPatch = _imageToPatchGrid.data[currentIdx];
	                _patchLabelGrid.data[currentIdx] = label;
	                for (dir = 0; dir < _tracer2.default.searchDirections.length; dir++) {
	                    y = current.y + _tracer2.default.searchDirections[dir][0];
	                    x = current.x + _tracer2.default.searchDirections[dir][1];
	                    idx = y * _patchLabelGrid.size.x + x;
	                    if (_patchGrid.data[idx] === 0) {
	                        _patchLabelGrid.data[idx] = Number.MAX_VALUE;
	                        continue;
	                    }
	                    if (_patchLabelGrid.data[idx] === 0) {
	                        similarity = Math.abs(vec2.dot(_imageToPatchGrid.data[idx].vec, currentPatch.vec));
	                        if (similarity > threshold) {
	                            trace(idx);
	                        }
	                    }
	                }
	            }
	        }
	        _array_helper2.default.init(_patchGrid.data, 0);
	        _array_helper2.default.init(_patchLabelGrid.data, 0);
	        _array_helper2.default.init(_imageToPatchGrid.data, null);
	        for (j = 0; j < patchesFound.length; j++) {
	            patch = patchesFound[j];
	            _imageToPatchGrid.data[patch.index] = patch;
	            _patchGrid.data[patch.index] = 1;
	        }
	        _patchGrid.zeroBorder();
	        while ((currIdx = notYetProcessed()) < _patchLabelGrid.data.length) {
	            label++;
	            trace(currIdx);
	        }
	        if (false) {
	            for (j = 0; j < _patchLabelGrid.data.length; j++) {
	                if (_patchLabelGrid.data[j] > 0 && _patchLabelGrid.data[j] <= label) {
	                    patch = _imageToPatchGrid.data[j];
	                    hsv[0] = _patchLabelGrid.data[j] / (label + 1) * 360;
	                    (0, _cv_utils.hsv2rgb)(hsv, rgb);
	                    _image_debug2.default.drawRect(patch.pos, _subImageWrapper.size, _canvasContainer.ctx.binary, { color: "rgb(" + rgb.join(",") + ")", lineWidth: 2 });
	                }
	            }
	        }
	        return label;
	    }
function rasterizeAngularSimilarity ( patchesFound ) { var label = 0 , threshold = 0.95 , currIdx = 0 , j , patch , hsv = [ 0 , 1 , 1 ] , rgb = [ 0 , 0 , 0 ] ; function notYetProcessed ( ) { var i ; for ( i = 0 ; i < _patchLabelGrid . data . length ; i ++ ) { if ( _patchLabelGrid . data [ i ] === 0 && _patchGrid . data [ i ] === 1 ) { return i ; } } return _patchLabelGrid . length ; } function trace ( currentIdx ) { var x , y , currentPatch , idx , dir , current = { x : currentIdx % _patchLabelGrid . size . x , y : currentIdx / _patchLabelGrid . size . x | 0 } , similarity ; if ( currentIdx < _patchLabelGrid . data . length ) { currentPatch = _imageToPatchGrid . data [ currentIdx ] ; _patchLabelGrid . data [ currentIdx ] = label ; for ( dir = 0 ; dir < _tracer2 . default . searchDirections . length ; dir ++ ) { y = current . y + _tracer2 . default . searchDirections [ dir ] [ 0 ] ; x = current . x + _tracer2 . default . searchDirections [ dir ] [ 1 ] ; idx = y * _patchLabelGrid . size . x + x ; if ( _patchGrid . data [ idx ] === 0 ) { _patchLabelGrid . data [ idx ] = Number . MAX_VALUE ; continue ; } if ( _patchLabelGrid . data [ idx ] === 0 ) { similarity = Math . abs ( vec2 . dot ( _imageToPatchGrid . data [ idx ] . vec , currentPatch . vec ) ) ; if ( similarity > threshold ) { trace ( idx ) ; } } } } } _array_helper2 . default . init ( _patchGrid . data , 0 ) ; _array_helper2 . default . init ( _patchLabelGrid . data , 0 ) ; _array_helper2 . default . init ( _imageToPatchGrid . data , null ) ; for ( j = 0 ; j < patchesFound . length ; j ++ ) { patch = patchesFound [ j ] ; _imageToPatchGrid . data [ patch . index ] = patch ; _patchGrid . data [ patch . index ] = 1 ; } _patchGrid . zeroBorder ( ) ; while ( ( currIdx = notYetProcessed ( ) ) < _patchLabelGrid . data . length ) { label ++ ; trace ( currIdx ) ; } if ( false ) { for ( j = 0 ; j < _patchLabelGrid . data . length ; j ++ ) { if ( _patchLabelGrid . data [ j ] > 0 && _patchLabelGrid . data [ j ] <= label ) { patch = _imageToPatchGrid . data [ j ] ; hsv [ 0 ] = _patchLabelGrid . data [ j ] / ( label + 1 ) * 360 ; ( 0 , _cv_utils . hsv2rgb ) ( hsv , rgb ) ; _image_debug2 . default . drawRect ( patch . pos , _subImageWrapper . size , _canvasContainer . ctx . binary , { color : "rgb(" + rgb . join ( "," ) + ")" , lineWidth : 2 } ) ; } } } return label ; }
finds patches which are connected and share the same orientation
 @param {Object} patchesFound
finds patches which are connected and share the same orientation @param { Object } patchesFound
// assign label // continue if patch empty // prepare for finding the right patches // rasterize the patches found to determine area // draw patch-labels if requested