Код Java Zxing Datamatrix не сканирует DatamatrixJAVA

Программисты JAVA общаются здесь
Ответить Пред. темаСлед. тема
Anonymous
 Код Java Zxing Datamatrix не сканирует Datamatrix

Сообщение Anonymous »

Следующая матрица данных хорошо считывается с помощью сканера штрих-кода. Однако Java-библиотека zxing не читает то же самое.
У меня есть комментарий к коду преобразования изображений. Даже преобразование изображения или масштабирование не помогают.
Коды ошибок:

Файл: Sample1.jpeg -> DataMatrix: DataMatrix не найден.


DataMatrix не найден: ноль

Ниже вы найдете код, который я использую. для декодирования и образцов штрих-кодов.

Код: Выделить всё

public static void main(String[] args) {
String folderPath = "D:\\Programming\\QR Code Reader"; // Folder path with images
File folder = new File(folderPath);

if (!folder.exists() || !folder.isDirectory()) {
System.out.println("The folder path is invalid: " + folderPath);
return;
}

File[] files = folder.listFiles((dir, name) -> name.toLowerCase().endsWith(".jpeg"));
if (files == null || files.length == 0) {
System.out.println("JPEG couldn't be found in the file.");
return;
}

for (File file : files) {
try {
String decodedText = decodeDataMatrix(file);
System.out.println("File: " + file.getName() + " -> DataMatrix: " + decodedText);
} catch (Exception e) {
System.out.println("File: " + file.getName() + " -> Error: " + e.getMessage());
}
}
}

public static String decodeDataMatrix(File file) throws IOException {
BufferedImage image = ImageIO.read(file);

if (image == null) {
throw new IOException("Image couldn't be read: " + file.getAbsolutePath());
}

// Change the image to Gray
BufferedImage grayImage = new BufferedImage(image.getWidth(), image.getHeight(), BufferedImage.TYPE_BYTE_GRAY);
Graphics g = grayImage.getGraphics();
g.drawImage(image, 0, 0, null);
g.dispose();

// Use ZXing
LuminanceSource source = new BufferedImageLuminanceSource(grayImage);
BinaryBitmap bitmap = new BinaryBitmap(new HybridBinarizer(source));

HashMap hints = new HashMap();
List possibleFormats = new ArrayList();
possibleFormats.add(BarcodeFormat.QR_CODE); // For all QR Types
possibleFormats.add(BarcodeFormat.CODE_128); // For all QR Types

hints.put(DecodeHintType.POSSIBLE_FORMATS, possibleFormats);
hints.put(DecodeHintType.TRY_HARDER, Boolean.TRUE);
hints.put(DecodeHintType.PURE_BARCODE, Boolean.TRUE);

try {
Result result = new MultiFormatReader().decode(bitmap, hints);
return result.getText();
} catch (NotFoundException e) {
System.err.println("No DataMatrix found: " + e.getMessage());
return "No DataMatrix found";
} catch (Exception e) {
System.err.println("Unexpected Error: " + e.getMessage());
return "Error: " + e.getMessage();
}
}
Изображение
Изображение


Подробнее здесь: https://stackoverflow.com/questions/793 ... tamatrixes
Реклама
Ответить Пред. темаСлед. тема

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

  • Похожие темы
    Ответы
    Просмотры
    Последнее сообщение

Вернуться в «JAVA»