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
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
二维码生成器java代码(补充类包) (111个子文件)
qrcode.class 15KB
QRCodeImageReader.class 14KB
FinderPattern.class 13KB
QRCodeImageReader.class 13KB
FinderPattern.class 12KB
QRCodeSymbol.class 9KB
QRCodeDecoder.class 9KB
QRCodeSymbol.class 9KB
QRCodeDecoder.class 9KB
QRCodeDataBlockReader.class 8KB
QRCodeDataBlockReader.class 7KB
ReedSolomon.class 6KB
AlignmentPattern.class 6KB
AlignmentPattern.class 6KB
ReedSolomon.class 6KB
DwindlePic.class 5KB
BCH15_5.class 5KB
BCH15_5.class 4KB
Line.class 4KB
Line.class 4KB
SamplingGrid.class 4KB
SamplingGrid.class 3KB
QRCodeEncoderTest.class 3KB
ContentConverter.class 3KB
ContentConverter.class 2KB
Point.class 2KB
Point.class 2KB
Axis.class 2KB
LogicalSeed.class 2KB
LogicalSeed.class 2KB
Axis.class 2KB
QRCodeDecoderTest.class 2KB
SamplingGrid$AreaGrid.class 2KB
SamplingGrid$AreaGrid.class 2KB
DebugCanvasAdapter.class 1KB
DebugCanvasAdapter.class 1KB
QRCodeDecoder$DecodeResult.class 994B
QRCodeDecoder$DecodeResult.class 994B
J2SEImage.class 793B
Test.class 660B
QRCodeImageReader$ModulePitch.class 658B
QRCodeImageReader$ModulePitch.class 658B
InvalidVersionInfoException.class 615B
InvalidVersionInfoException.class 615B
AlignmentPatternNotFoundException.class 608B
AlignmentPatternNotFoundException.class 608B
InvalidVersionException.class 594B
InvalidVersionException.class 594B
InvalidDataBlockException.class 584B
FinderPatternNotFoundException.class 584B
InvalidDataBlockException.class 584B
FinderPatternNotFoundException.class 584B
SymbolNotFoundException.class 578B
DecodingFailedException.class 578B
SymbolNotFoundException.class 578B
DecodingFailedException.class 578B
QRCodeUtility.class 578B
QRCodeUtility.class 530B
Color.class 502B
Color.class 502B
DebugCanvas.class 488B
DebugCanvas.class 488B
VersionInformationException.class 388B
VersionInformationException.class 388B
QRCodeEncoder.class 308B
QRCodeEncoder.class 308B
QRCodeImage.class 202B
QRCodeImage.class 202B
.classpath 359B
使用说明.doc 11KB
Qrcodeen.jar 1014KB
QRCodeImageReader.java 30KB
qrcode.java 24KB
FinderPattern.java 19KB
QRCodeSymbol.java 12KB
AlignmentPattern.java 12KB
QRCodeDataBlockReader.java 11KB
QRCodeDecoder.java 10KB
ReedSolomon.java 9KB
BCH15_5.java 7KB
DwindlePic.java 6KB
TestMID.java 5KB
SamplingGrid.java 3KB
Line.java 3KB
Axis.java 3KB
LogicalSeed.java 2KB
ContentConverter.java 2KB
QRCodeEncoderTest.java 2KB
QRCodeDecoderTest.java 2KB
Point.java 1KB
QRCodeUtility.java 1KB
DebugCanvasAdapter.java 741B
HImage.java 710B
DebugCanvas.java 700B
DecodingFailedException.java 554B
Color.java 513B
Test.java 320B
AlignmentPatternNotFoundException.java 290B
InvalidVersionInfoException.java 282B
InvalidDataBlockException.java 273B
共 111 条
- 1
- 2
放羊de码工
- 粉丝: 3
- 资源: 7
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- 基于matlab开发的根据rvm回归模型自己编的matlab程序.rar
- 高效C++学生成绩管理系统:教育技术+C++17编程+数据管理+教务自动化
- 基于matlab开发的Tipping的相关向量机RVM的回归MATLAB程序,有英文注释,可以运行.rar
- 一个点击正反转程序实例,可实现案件电机正反转
- 搜索链接淘特搜索引擎共享版-tot-search-engine.rar
- 第十八届全国大学生智能汽车竞赛 摄像头组/镜头组
- 基于matlab开发的AUV惯性导航系统matlab仿真程序,包括轨迹生成、gps和sins组合、gps和dvl组合.rar
- 基于SSM的“个性化电子相册”的设计与实现.zip
- 如何在撰写科研文献时,使用ai工具辅助去完成科研工作
- 吉林大学计组笔记 自用 基于b站翼云图灵的课.pdf
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
- 1
- 2
前往页