if (gcc.getComponentCount() == 0) {
return false;
}
// get component which is largest than the minimum size and
// closest to a 4/3 ratio of width to height
Rect rReduced;
int nBestDiff = Integer.MAX_VALUE;
this.rDetected = null;
for (int i=0; i<gcc.getComponentCount(); i++) {
rReduced = gcc.getComponent(0);
// we detected the barcode at reduced resolution
// for speed. Stretch the rectangle back to its
// original size
Rect rThisDetected = new Rect(
(rReduced.getLeft() * rgb.getWidth()) / nReducedWidth,
(rReduced.getTop() * rgb.getHeight()) / nReducedHeight,
(rReduced.getWidth() * rgb.getWidth()) / nReducedWidth,
(rReduced.getHeight() * rgb.getHeight()) / nReducedHeight
);
if (rThisDetected.getArea() >= this.nMinArea) {
int nRatio = 3 * rThisDetected.getWidth() / rThisDetected.getHeight();
// the ratio should be close to 4 since in the ideal case
// width = 4x and height = 3x so 3 * width / height = 4
int nDiff = Math.abs(nRatio-4);
if (nDiff < nBestDiff) {
this.rDetected = rThisDetected;