Exemplo n.º 1
0
void
ImageSearch::search(PNG& srchImg) {
    const PNGHelper subImageHelper(srchImg);
    const int maxRow = mainImage.getHeight() - srchImg.getHeight();
    const int maxCol = mainImage.getWidth()  - srchImg.getWidth();
    const int pixMatchNeeded = srchImg.getBufferSize() * matchPercent / 400;
    for(int col = 0; (col <= maxCol); col++) {
	for(int row = 0; (row <= maxRow); row++) {
	    const MatchedRect srchRegion(row, col, srchImg.getWidth(),
					 srchImg.getHeight());
	    if (mrl.isMatched(srchRegion)) {
		// Current search rgion is already part of a region
		// matched earlier in this method (same as thread).
		continue;
	    }
	    // Search for a match between sub-images.
	    PNGHelper mainImgHelper(mainImage, row, col);
	    int pixMatch = getMatchingPixelCount(isMask, mainImgHelper, subImageHelper,
						 srchImg.getHeight(),
						 srchImg.getWidth(), tolerance);
	    if (pixMatch > pixMatchNeeded) {
		// Found a matching region.
		mrl += srchRegion;
	    }
	}
    }
}