qr_decoder_test_src.rar

  • PUDN用户
    了解作者
  • Java
    开发工具
  • 39KB
    文件大小
  • rar
    文件格式
  • 0
    收藏次数
  • 1 积分
    下载积分
  • 2
    下载次数
  • 2009-11-23 17:02
    上传日期
souceforge上down的qrcode貌似不能直接运行,所以,这里上传一个测试例子
qr_decoder_test_src.rar
内容介绍
package jp.sourceforge.qrcode.reader; import java.util.Vector; import jp.sourceforge.qrcode.QRCodeDecoder; import jp.sourceforge.qrcode.data.*; import jp.sourceforge.qrcode.exception.AlignmentPatternNotFoundException; import jp.sourceforge.qrcode.exception.FinderPatternNotFoundException; import jp.sourceforge.qrcode.exception.SymbolNotFoundException; import jp.sourceforge.qrcode.exception.InvalidVersionException; import jp.sourceforge.qrcode.exception.VersionInformationException; import jp.sourceforge.qrcode.geom.*; import jp.sourceforge.qrcode.pattern.*; import jp.sourceforge.qrcode.util.*; public class QRCodeImageReader { DebugCanvas canvas; //boolean[][] image; //DP = //23 ...side pixels of image will be limited maximum 255 (8 bits) //22 .. side pixels of image will be limited maximum 511 (9 bits) //21 .. side pixels of image will be limited maximum 1023 (10 bits) //I think it's good idea to use DECIMAL_POINT with type "long" too. public static int DECIMAL_POINT = 21; public static final boolean POINT_DARK = true; public static final boolean POINT_LIGHT = false; SamplingGrid samplingGrid; boolean[][] bitmap; //int numModuleAtSide; //デコード対象のシンボルにおける一辺のモジュールの数 public QRCodeImageReader() { this.canvas = QRCodeDecoder.getCanvas(); } // local class for module pitch protected class ModulePitch { public int top; public int left; public int bottom; public int right; }; boolean[][] applyMedianFilter(boolean[][] image, int threshold) { boolean[][] filteredMatrix = new boolean[image.length][image[0].length]; //filtering noise in image with median filter int numPointDark; for (int y = 1; y < image[0].length - 1; y++) { for (int x = 1; x < image.length - 1; x++) { //if (image[x][y] == true) { numPointDark = 0; for (int fy = -1; fy < 2; fy++) { for (int fx = -1; fx < 2; fx++) { if (image[x + fx][y + fy] == true) { numPointDark++; } } } if (numPointDark > threshold) filteredMatrix[x][y] = POINT_DARK; } } return filteredMatrix; } boolean[][] applyCrossMaskingMedianFilter(boolean[][] image, int threshold) { boolean[][] filteredMatrix = new boolean[image.length][image[0].length]; //filtering noise in image with median filter int numPointDark; for (int y = 2; y < image[0].length - 2; y++) { for (int x = 2; x < image.length - 2; x++) { //if (image[x][y] == true) { numPointDark = 0; for (int f = -2; f < 3; f++) { if (image[x+f][y] == true) numPointDark++; if (image[x][y+f] == true) numPointDark++; } if (numPointDark > threshold) filteredMatrix[x][y] = POINT_DARK; } } return filteredMatrix; } boolean[][] filterImage(int[][] image) { imageToGrayScale(image); boolean[][] bitmap = grayScaleToBitmap(image); return bitmap; } void imageToGrayScale(int[][] image) { for (int y = 0; y < image[0].length; y++) { for (int x = 0; x < image.length; x++) { int r = image[x][y] >> 16 & 0xFF; int g = image[x][y] >> 8 & 0xFF; int b = image[x][y] & 0xFF; int m = (r * 30 + g * 59 + b * 11) / 100; image[x][y] = m; } } } boolean[][] grayScaleToBitmap(int[][] grayScale) { int[][] middle = getMiddleBrightnessPerArea(grayScale); int sqrtNumArea = middle.length; int areaWidth = grayScale.length / sqrtNumArea; int areaHeight = grayScale[0].length / sqrtNumArea; boolean[][] bitmap = new boolean[grayScale.length][grayScale[0].length]; for (int ay = 0; ay < sqrtNumArea; ay++) { for (int ax = 0; ax < sqrtNumArea; ax++) { for (int dy = 0; dy < areaHeight; dy++) { for (int dx = 0; dx < areaWidth; dx++) { bitmap[areaWidth * ax + dx][areaHeight * ay + dy] = (grayScale[areaWidth * ax + dx][areaHeight * ay + dy] < middle[ax][ay]) ? true : false; } } } } return bitmap; } int[][] getMiddleBrightnessPerArea(int[][] image) { final int numSqrtArea = 4; //obtain middle brightness((min + max) / 2) per area int areaWidth = image.length / numSqrtArea; int areaHeight = image[0].length / numSqrtArea; int[][][] minmax = new int[numSqrtArea][numSqrtArea][2]; for (int ay = 0; ay < numSqrtArea; ay++) { for (int ax = 0; ax < numSqrtArea; ax++) { minmax[ax][ay][0] = 0xFF; for (int dy = 0; dy < areaHeight; dy++) { for (int dx = 0; dx < areaWidth; dx++) { int target = image[areaWidth * ax + dx][areaHeight * ay + dy]; if (target < minmax[ax][ay][0]) minmax[ax][ay][0] = target; if (target > minmax[ax][ay][1]) minmax[ax][ay][1] = target; } } //minmax[ax][ay][0] = (minmax[ax][ay][0] + minmax[ax][ay][1]) / 2; } } int[][] middle = new int[numSqrtArea][numSqrtArea]; for (int ay = 0; ay < numSqrtArea; ay++) { for (int ax = 0; ax < numSqrtArea; ax++) { middle[ax][ay] = (minmax[ax][ay][0] + minmax[ax][ay][1]) / 2; //System.out.print(middle[ax][ay] + ","); } //System.out.println(""); } //System.out.println(""); return middle; } public QRCodeSymbol getQRCodeSymbol(int[][] image) throws SymbolNotFoundException { int longSide = (image.length < image[0].length) ? image[0].length : image.length; QRCodeImageReader.DECIMAL_POINT = 23 - QRCodeUtility.sqrt(longSide / 256); bitmap = filterImage(image); canvas.println("Drawing matrix."); canvas.drawMatrix(bitmap); canvas.println("Scanning Finder Pattern."); FinderPattern finderPattern = null; try { finderPattern = FinderPattern.findFinderPattern(bitmap); } catch (FinderPatternNotFoundException e) { canvas.println("Not found, now retrying..."); bitmap = applyCrossMaskingMedianFilter(bitmap, 5); canvas.drawMatrix(bitmap); try { finderPattern = FinderPattern.findFinderPattern(bitmap); } catch (FinderPatternNotFoundException e2) { throw new SymbolNotFoundException(e2.getMessage()); } catch (VersionInformationException e2) { throw new SymbolNotFoundException(e2.getMessage()); } } catch (VersionInformationException e) { throw new SymbolNotFoundException(e.getMessage()); } canvas.println("FinderPattern at"); String finderPatternCoordinates = finderPattern.getCenter(FinderPattern.UL).toString() + finderPattern.getCenter(FinderPattern.UR).toString() + finderPattern.getCenter(FinderPattern.DL).toString(); canvas.println(finderPatternCoordinates); int[] sincos = finderPattern.getAngle(); canvas.println("Angle*4098: Sin " + Integer.toString(sincos[0]) + " " + "Cos " + Integer.toString(sincos[1])); int version = finderPattern.getVersion(); canvas.println("Version: " + Integer.toString(version)); if (version < 1 || version > 40) throw new InvalidVersionException("Invalid version: " + version); AlignmentPattern alignmentPattern = null; try { alignmentPattern = AlignmentPattern.findAlignmentPattern(bitmap, finderPattern); } catch (AlignmentPatternNotFoundException e) { throw new SymbolNotFoundException(e.getMessage()); } int matrixLength = alignmentPattern.getCenter().length; canvas.println("AlignmentPatterns at"); for (int y = 0; y < matrixLength; y++) { String alignmentPatternCoordinates = ""; for (int x = 0; x < matrixLength; x++) { alignmentPatternCoordinates += alignmentPattern.getCenter()[x][y].toString(); } canvas.println(alignmentPatternCoordinates); } //for(int i = 0; i < 500000; i++) System.out.println(""); canvas.println("Creating sampling grid."); //[TODO] need all-purpose method //samplingGrid = getSamplingGrid2_6(finderPattern, alignmentPattern); samplingGrid = getSamplingGrid(finderPattern, alignmentPattern); canvas.println("Reading grid."); boolean[][] qRCodeMatrix = null; try { qRCodeMatrix = getQRCodeMatrix(bitmap, samplingGrid); } catch (ArrayIndexOutOfBoundsException e) { throw new SymbolNotFoundException("Sampling grid exceeded image boundary"); } //canvas.drawMatrix(qRCodeMatrix); return new QRCode
评论
    相关推荐
    • 数据库课程设计
      一个数据库课程设计,access管理工具实现,用的是窗体!
    • 数据库课程设计
      数据库课程设计十分完整有需要的请下载啊谢谢
    • 数据库课程设计
      广东工业大学数据库课程设计,可视化界面连接数据库,delphi7
    • 数据库课程设计
      数据库课程设计实验及其描述 数据库课程设计实验及其描述 数据库课程设计实验及其描述 数据库课程设计实验及其描述 数据库课程设计实验及其描述 数据库课程设计实验及其描述
    • 数据库课程设计
      数据库课程设计》由周爱武、汪海威、肖云编著,遵循数据库课程设计的具体要求,独立于具体的数据库教材,从实际应用系统的需求着手,引导读者逐步完成数据库设计全过程,重点讲解数据库系统的需求分析、概念设计、...
    • 数据库课程设计
      数据库课程设计人事管理系统 数据库课程设计人事管理系统数据库课程设计人事管理系统数据库课程设计人事管理系统数据库课程设计人事管理系统数据库课程设计人事管理系统数据库课程设计人事管理系统数据库课程设计...
    • 数据库课程设计
      数据库课程设计,基于visual basic自助银行管理系统,界面很清爽,实用。同学都说好,所以就上传了!!!
    • 数据库课程设计
      数据库课程设计 里面有详细的文档资料 包含数据库一切的图 以及生成的数据库表文件 期末得分为优秀
    • 数据库课程设计
      可以作为数据库课程设计,也可以作为Java的课程设计,内容全面。本资源转载的,非本人原创。用于交流学习,特此申明!
    • 数据库课程设计
      数据库课程设计蓝天大学学生管理系统 2.商店信息管理系统 3.实验室机房收费管理系统 4.图书馆资料检索系统 5.企业库存管理系统 6.仓库管理系统 7.工程项目管理系统 8.教材管理系统 9.企业人事管理系统 10.企业财务...