本文整理汇总了Java中com.google.zxing.common.GlobalHistogramBinarizer类的典型用法代码示例。如果您正苦于以下问题:Java GlobalHistogramBinarizer类的具体用法?Java GlobalHistogramBinarizer怎么用?Java GlobalHistogramBinarizer使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
GlobalHistogramBinarizer类属于com.google.zxing.common包,在下文中一共展示了GlobalHistogramBinarizer类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: assertCorrectImage2binary
import com.google.zxing.common.GlobalHistogramBinarizer; //导入依赖的package包/类
private static void assertCorrectImage2binary(String fileName, String expected)
throws IOException, NotFoundException {
Path path = AbstractBlackBoxTestCase.buildTestBase("src/test/resources/blackbox/rssexpanded-1/").resolve(fileName);
BufferedImage image = ImageIO.read(path.toFile());
BinaryBitmap binaryMap = new BinaryBitmap(new GlobalHistogramBinarizer(new BufferedImageLuminanceSource(image)));
int rowNumber = binaryMap.getHeight() / 2;
BitArray row = binaryMap.getBlackRow(rowNumber, null);
List<ExpandedPair> pairs;
try {
RSSExpandedReader rssExpandedReader = new RSSExpandedReader();
pairs = rssExpandedReader.decodeRow2pairs(rowNumber, row);
} catch (ReaderException re) {
fail(re.toString());
return;
}
BitArray binary = BitArrayBuilder.buildBitArray(pairs);
assertEquals(expected, binary.toString());
}
示例2: testRetrieveNextPairPatterns
import com.google.zxing.common.GlobalHistogramBinarizer; //导入依赖的package包/类
@Test
public void testRetrieveNextPairPatterns() throws Exception {
BufferedImage image = readImage("3.png");
BinaryBitmap binaryMap = new BinaryBitmap(new GlobalHistogramBinarizer(new BufferedImageLuminanceSource(image)));
int rowNumber = binaryMap.getHeight() / 2;
BitArray row = binaryMap.getBlackRow(rowNumber, null);
List<ExpandedPair> previousPairs = new ArrayList<>();
RSSExpandedReader rssExpandedReader = new RSSExpandedReader();
ExpandedPair pair1 = rssExpandedReader.retrieveNextPair(row, previousPairs, rowNumber);
previousPairs.add(pair1);
FinderPattern finderPattern = pair1.getFinderPattern();
assertNotNull(finderPattern);
assertEquals(0, finderPattern.getValue());
ExpandedPair pair2 = rssExpandedReader.retrieveNextPair(row, previousPairs, rowNumber);
previousPairs.add(pair2);
finderPattern = pair2.getFinderPattern();
assertNotNull(finderPattern);
assertEquals(0, finderPattern.getValue());
}
示例3: testDecodeDataCharacter
import com.google.zxing.common.GlobalHistogramBinarizer; //导入依赖的package包/类
@Test
public void testDecodeDataCharacter() throws Exception {
BufferedImage image = readImage("3.png");
BinaryBitmap binaryMap = new BinaryBitmap(new GlobalHistogramBinarizer(new BufferedImageLuminanceSource(image)));
BitArray row = binaryMap.getBlackRow(binaryMap.getHeight() / 2, null);
int[] startEnd = {145, 243};//image pixels where the A1 pattern starts (at 124) and ends (at 214)
int value = 0; // A
FinderPattern finderPatternA1 = new FinderPattern(value, startEnd, startEnd[0], startEnd[1], image.getHeight() / 2);
//{1, 8, 4, 1, 1};
RSSExpandedReader rssExpandedReader = new RSSExpandedReader();
DataCharacter dataCharacter = rssExpandedReader.decodeDataCharacter(row, finderPatternA1, true, false);
assertEquals(19, dataCharacter.getValue());
assertEquals(1007, dataCharacter.getChecksumPortion());
}
示例4: assertCorrectImage2string
import com.google.zxing.common.GlobalHistogramBinarizer; //导入依赖的package包/类
private static void assertCorrectImage2string(String fileName, String expected)
throws IOException, NotFoundException {
Path path = AbstractBlackBoxTestCase.buildTestBase("src/test/resources/blackbox/rssexpanded-1/").resolve(fileName);
BufferedImage image = ImageIO.read(path.toFile());
BinaryBitmap binaryMap =
new BinaryBitmap(new GlobalHistogramBinarizer(new BufferedImageLuminanceSource(image)));
int rowNumber = binaryMap.getHeight() / 2;
BitArray row = binaryMap.getBlackRow(rowNumber, null);
Result result;
try {
RSSExpandedReader rssExpandedReader = new RSSExpandedReader();
result = rssExpandedReader.decodeRow(rowNumber, row, null);
} catch (ReaderException re) {
fail(re.toString());
return;
}
assertSame(BarcodeFormat.RSS_EXPANDED, result.getBarcodeFormat());
assertEquals(expected, result.getText());
}
示例5: assertCorrectImage2result
import com.google.zxing.common.GlobalHistogramBinarizer; //导入依赖的package包/类
private static void assertCorrectImage2result(String fileName, ExpandedProductParsedResult expected)
throws IOException, NotFoundException {
Path path = AbstractBlackBoxTestCase.buildTestBase("src/test/resources/blackbox/rssexpanded-1/").resolve(fileName);
BufferedImage image = ImageIO.read(path.toFile());
BinaryBitmap binaryMap = new BinaryBitmap(new GlobalHistogramBinarizer(new BufferedImageLuminanceSource(image)));
int rowNumber = binaryMap.getHeight() / 2;
BitArray row = binaryMap.getBlackRow(rowNumber, null);
Result theResult;
try {
RSSExpandedReader rssExpandedReader = new RSSExpandedReader();
theResult = rssExpandedReader.decodeRow(rowNumber, row, null);
} catch (ReaderException re) {
fail(re.toString());
return;
}
assertSame(BarcodeFormat.RSS_EXPANDED, theResult.getBarcodeFormat());
ParsedResult result = ResultParser.parseResult(theResult);
assertEquals(expected, result);
}
示例6: assertCorrectImage2binary
import com.google.zxing.common.GlobalHistogramBinarizer; //导入依赖的package包/类
private static void assertCorrectImage2binary(String path, String expected) throws IOException, NotFoundException {
RSSExpandedReader rssExpandedReader = new RSSExpandedReader();
File file = new File(path);
if (!file.exists()) {
// Support running from project root too
file = new File("core", path);
}
BufferedImage image = ImageIO.read(file);
BinaryBitmap binaryMap = new BinaryBitmap(new GlobalHistogramBinarizer(new BufferedImageLuminanceSource(image)));
int rowNumber = binaryMap.getHeight() / 2;
BitArray row = binaryMap.getBlackRow(rowNumber, null);
List<ExpandedPair> pairs = rssExpandedReader.decodeRow2pairs(rowNumber, row);
BitArray binary = BitArrayBuilder.buildBitArray(pairs);
assertEquals(expected, binary.toString());
}
示例7: testDecodeCheckCharacter
import com.google.zxing.common.GlobalHistogramBinarizer; //导入依赖的package包/类
@Test
public void testDecodeCheckCharacter() throws Exception {
RSSExpandedReader rssExpandedReader = new RSSExpandedReader();
String path = "test/data/blackbox/rssexpanded-1/3.jpg";
File file = new File(path);
if (!file.exists()) {
// Support running from project root too
file = new File("core", path);
}
BufferedImage image = ImageIO.read(file);
BinaryBitmap binaryMap = new BinaryBitmap(new GlobalHistogramBinarizer(new BufferedImageLuminanceSource(image)));
BitArray row = binaryMap.getBlackRow(binaryMap.getHeight() / 2, null);
int[] startEnd = {145, 243};//image pixels where the A1 pattern starts (at 124) and ends (at 214)
int value = 0;// A
FinderPattern finderPatternA1 = new FinderPattern(value, startEnd, startEnd[0], startEnd[1], image.getHeight() / 2);
//{1, 8, 4, 1, 1};
DataCharacter dataCharacter = rssExpandedReader.decodeDataCharacter(row, finderPatternA1, true, true);
assertEquals(98, dataCharacter.getValue());
}
示例8: testDecodeDataCharacter
import com.google.zxing.common.GlobalHistogramBinarizer; //导入依赖的package包/类
@Test
public void testDecodeDataCharacter() throws Exception {
RSSExpandedReader rssExpandedReader = new RSSExpandedReader();
String path = "test/data/blackbox/rssexpanded-1/3.jpg";
File file = new File(path);
if (!file.exists()) {
// Support running from project root too
file = new File("core", path);
}
BufferedImage image = ImageIO.read(file);
BinaryBitmap binaryMap = new BinaryBitmap(new GlobalHistogramBinarizer(new BufferedImageLuminanceSource(image)));
BitArray row = binaryMap.getBlackRow(binaryMap.getHeight() / 2, null);
int[] startEnd = {145, 243};//image pixels where the A1 pattern starts (at 124) and ends (at 214)
int value = 0; // A
FinderPattern finderPatternA1 = new FinderPattern(value, startEnd, startEnd[0], startEnd[1], image.getHeight() / 2);
//{1, 8, 4, 1, 1};
DataCharacter dataCharacter = rssExpandedReader.decodeDataCharacter(row, finderPatternA1, true, false);
assertEquals(19, dataCharacter.getValue());
assertEquals(1007, dataCharacter.getChecksumPortion());
}
示例9: assertCorrectImage2string
import com.google.zxing.common.GlobalHistogramBinarizer; //导入依赖的package包/类
private static void assertCorrectImage2string(String path, String expected) throws IOException, NotFoundException {
RSSExpandedReader rssExpandedReader = new RSSExpandedReader();
File file = new File(path);
if (!file.exists()) {
// Support running from project root too
file = new File("core", path);
}
BufferedImage image = ImageIO.read(file);
BinaryBitmap binaryMap = new BinaryBitmap(new GlobalHistogramBinarizer(new BufferedImageLuminanceSource(image)));
int rowNumber = binaryMap.getHeight() / 2;
BitArray row = binaryMap.getBlackRow(rowNumber, null);
Result result = rssExpandedReader.decodeRow(rowNumber, row, null);
assertSame(BarcodeFormat.RSS_EXPANDED, result.getBarcodeFormat());
assertEquals(expected, result.getText());
}
示例10: assertCorrectImage2result
import com.google.zxing.common.GlobalHistogramBinarizer; //导入依赖的package包/类
private static void assertCorrectImage2result(String path, ExpandedProductParsedResult expected)
throws IOException, NotFoundException {
RSSExpandedReader rssExpandedReader = new RSSExpandedReader();
File file = new File(path);
if (!file.exists()) {
// Support running from project root too
file = new File("core", path);
}
BufferedImage image = ImageIO.read(file);
BinaryBitmap binaryMap = new BinaryBitmap(new GlobalHistogramBinarizer(new BufferedImageLuminanceSource(image)));
int rowNumber = binaryMap.getHeight() / 2;
BitArray row = binaryMap.getBlackRow(rowNumber, null);
Result theResult = rssExpandedReader.decodeRow(rowNumber, row, null);
assertSame(BarcodeFormat.RSS_EXPANDED, theResult.getBarcodeFormat());
ParsedResult result = ResultParser.parseResult(theResult);
assertEquals(expected, result);
}
示例11: assertCorrectImage2binary
import com.google.zxing.common.GlobalHistogramBinarizer; //导入依赖的package包/类
private static void assertCorrectImage2binary(String path, String expected) throws IOException, NotFoundException {
File file = new File(path);
if (!file.exists()) {
// Support running from project root too
file = new File("core", path);
}
BufferedImage image = ImageIO.read(file);
BinaryBitmap binaryMap = new BinaryBitmap(new GlobalHistogramBinarizer(new BufferedImageLuminanceSource(image)));
int rowNumber = binaryMap.getHeight() / 2;
BitArray row = binaryMap.getBlackRow(rowNumber, null);
List<ExpandedPair> pairs;
try {
RSSExpandedReader rssExpandedReader = new RSSExpandedReader();
pairs = rssExpandedReader.decodeRow2pairs(rowNumber, row);
} catch (ReaderException re) {
fail(re.toString());
return;
}
BitArray binary = BitArrayBuilder.buildBitArray(pairs);
assertEquals(expected, binary.toString());
}
示例12: testDecodeCheckCharacter
import com.google.zxing.common.GlobalHistogramBinarizer; //导入依赖的package包/类
@Test
public void testDecodeCheckCharacter() throws Exception {
String path = "test/data/blackbox/rssexpanded-1/3.png";
File file = new File(path);
if (!file.exists()) {
// Support running from project root too
file = new File("core", path);
}
BufferedImage image = ImageIO.read(file);
BinaryBitmap binaryMap = new BinaryBitmap(new GlobalHistogramBinarizer(new BufferedImageLuminanceSource(image)));
BitArray row = binaryMap.getBlackRow(binaryMap.getHeight() / 2, null);
int[] startEnd = {145, 243};//image pixels where the A1 pattern starts (at 124) and ends (at 214)
int value = 0;// A
FinderPattern finderPatternA1 = new FinderPattern(value, startEnd, startEnd[0], startEnd[1], image.getHeight() / 2);
//{1, 8, 4, 1, 1};
RSSExpandedReader rssExpandedReader = new RSSExpandedReader();
DataCharacter dataCharacter = rssExpandedReader.decodeDataCharacter(row, finderPatternA1, true, true);
assertEquals(98, dataCharacter.getValue());
}
示例13: testDecodeDataCharacter
import com.google.zxing.common.GlobalHistogramBinarizer; //导入依赖的package包/类
@Test
public void testDecodeDataCharacter() throws Exception {
String path = "test/data/blackbox/rssexpanded-1/3.png";
File file = new File(path);
if (!file.exists()) {
// Support running from project root too
file = new File("core", path);
}
BufferedImage image = ImageIO.read(file);
BinaryBitmap binaryMap = new BinaryBitmap(new GlobalHistogramBinarizer(new BufferedImageLuminanceSource(image)));
BitArray row = binaryMap.getBlackRow(binaryMap.getHeight() / 2, null);
int[] startEnd = {145, 243};//image pixels where the A1 pattern starts (at 124) and ends (at 214)
int value = 0; // A
FinderPattern finderPatternA1 = new FinderPattern(value, startEnd, startEnd[0], startEnd[1], image.getHeight() / 2);
//{1, 8, 4, 1, 1};
RSSExpandedReader rssExpandedReader = new RSSExpandedReader();
DataCharacter dataCharacter = rssExpandedReader.decodeDataCharacter(row, finderPatternA1, true, false);
assertEquals(19, dataCharacter.getValue());
assertEquals(1007, dataCharacter.getChecksumPortion());
}
示例14: assertCorrectImage2string
import com.google.zxing.common.GlobalHistogramBinarizer; //导入依赖的package包/类
private static void assertCorrectImage2string(String path, String expected) throws IOException, NotFoundException {
File file = new File(path);
if (!file.exists()) {
// Support running from project root too
file = new File("core", path);
}
BufferedImage image = ImageIO.read(file);
BinaryBitmap binaryMap = new BinaryBitmap(new GlobalHistogramBinarizer(new BufferedImageLuminanceSource(image)));
int rowNumber = binaryMap.getHeight() / 2;
BitArray row = binaryMap.getBlackRow(rowNumber, null);
Result result;
try {
RSSExpandedReader rssExpandedReader = new RSSExpandedReader();
result = rssExpandedReader.decodeRow(rowNumber, row, null);
} catch (ReaderException re) {
fail(re.toString());
return;
}
assertSame(BarcodeFormat.RSS_EXPANDED, result.getBarcodeFormat());
assertEquals(expected, result.getText());
}
示例15: decodeImage
import com.google.zxing.common.GlobalHistogramBinarizer; //导入依赖的package包/类
/**
* Decode the data within the viewfinder rectangle, and time how long it took. For efficiency, reuse the same reader
* objects from one decode to the next.
*/
public static Result decodeImage(byte[] data, int width, int height) {
// 处理
Result result = null;
try {
Hashtable<DecodeHintType, Object> hints = new Hashtable<DecodeHintType, Object>();
hints.put(DecodeHintType.CHARACTER_SET, "utf-8");
hints.put(DecodeHintType.TRY_HARDER, Boolean.TRUE);
hints.put(DecodeHintType.POSSIBLE_FORMATS, BarcodeFormat.QR_CODE);
PlanarYUVLuminanceSource source =
new PlanarYUVLuminanceSource(data, width, height, 0, 0, width, height, false);
/**
* HybridBinarizer算法使用了更高级的算法,但使用GlobalHistogramBinarizer识别效率确实比HybridBinarizer要高一些。
*
* GlobalHistogram算法:(http://kuangjianwei.blog.163.com/blog/static/190088953201361015055110/)
*
* 二值化的关键就是定义出黑白的界限,我们的图像已经转化为了灰度图像,每个点都是由一个灰度值来表示,就需要定义出一个灰度值,大于这个值就为白(0),低于这个值就为黑(1)。
* 在GlobalHistogramBinarizer中,是从图像中均匀取5行(覆盖整个图像高度),每行取中间五分之四作为样本;以灰度值为X轴,每个灰度值的像素个数为Y轴建立一个直方图,
* 从直方图中取点数最多的一个灰度值,然后再去给其他的灰度值进行分数计算,按照点数乘以与最多点数灰度值的距离的平方来进行打分,选分数最高的一个灰度值。接下来在这两个灰度值中间选取一个区分界限,
* 取的原则是尽量靠近中间并且要点数越少越好。界限有了以后就容易了,与整幅图像的每个点进行比较,如果灰度值比界限小的就是黑,在新的矩阵中将该点置1,其余的就是白,为0。
*/
BinaryBitmap bitmap1 = new BinaryBitmap(new GlobalHistogramBinarizer(source));
// BinaryBitmap bitmap1 = new BinaryBitmap(new HybridBinarizer(source));
QRCodeReader reader2 = new QRCodeReader();
result = reader2.decode(bitmap1, hints);
} catch (ReaderException e) {
}
return result;
}