* This object extends LuminanceSource around an arrayof YUV data returned from the camera driver, * with the optionto crop to a rectangle within the full data. This can be used toexclude * superfluous pixels around the perimeter and speed up decoding. * * It works forany pixel formatwhere the Y channel is planar and appears first, including * YCbCr_420_SP and YCbCr_422_SP.
封装YUV数据,分离Y通道 //因为是108条码识别,本质上只需要截取任意一行,根据点的分布即可 @Override public byte[] getRow(int y, byte[] row) { if (y < 0 || y >= getHeight()) { throw new IllegalArgumentException("Requested row is outside the image: " + y); } int width = getWidth(); if (row == null || row.length < width) { row = new byte[width]; } intoffset = (y + top) * dataWidth + left; System.arraycopy(yuvData, offset, row, 0, width); returnrow; }
@Override public BitArray getBlackRow(inty, BitArray row) throws NotFoundException { LuminanceSource source = getLuminanceSource(); int width = source.getWidth(); if (row == null || row.getSize() < width) { row = newBitArray(width); } else { row.clear(); } initArrays(width);//初始化BitArray byte[] localLuminances = source.getRow(y, luminances); savelocalLuminances(localLuminances);//此处为自己添加 int[] localBuckets = buckets; for (int x = 0; x < width; x++) {//锐化后构建颜色直方图 localBuckets[(localLuminances[x] & 0xff) >> LUMINANCE_SHIFT]++; } //获取直方图中第一高点,第二高点 以及2点之间的波谷 int blackPoint = estimateBlackPoint(localBuckets);
if (width < 3) { // Special case for very small images for (int x = 0; x < width; x++) { if ((localLuminances[x] & 0xff) < blackPoint) { row.set(x); } } } else {//使用一个-1 4 -1 过滤对数据进行锐化 int left = localLuminances[0] & 0xff; int center = localLuminances[1] & 0xff; for (int x = 1; x < width - 1; x++) { int right = localLuminances[x + 1] & 0xff; // A simple -1 4 -1 box filter with a weight of 2. if (((center * 4) - left - right) / 2 < blackPoint) { row.set(x); } left = center; center = right; } } return row; }