Skip to content

Barcode detection with EAN8 codes is not working reliably #23889

@Jimbopython

Description

@Jimbopython

System Information

OpenCV version 4.6.0-4.8.x
Operating System / Platform: Ubuntu 23.04
Compiler & compiler version: GCC 12.2.0

Detailed description

We are trying to read and decode several Barcodes with OpenCV. We have great success with EAN13 codes, but EAN8 are not working reliably. We provided an image in the attachments, which is read successfully by Halcon, ZBar and ZXing, but OpenCV does neither detect nor decode the barcode. We have this issue with several similar images.

Steps to reproduce

#include <iostream>
#include <vector>
#include <string>
#include <opencv2/imgcodecs.hpp>

#if CV_MINOR_VERSION >= 8
#include <opencv2/objdetect/barcode.hpp>
#else
#include <opencv2/barcode.hpp>
#endif

std::vector<std::string> read(const cv::Mat &image)
{
    cv::barcode::BarcodeDetector detector;
    std::vector<cv::Point> corners;
#if CV_MINOR_VERSION >= 8
    std::vector<std::string> decode_info;
    std::vector<std::string> decoded_type;
    detector.detectAndDecodeWithType(image, decode_info, decoded_type, corners);
#else
    std::vector<cv::String> decode_info;
    std::vector<cv::barcode::BarcodeType> decoded_type;
    detector.detectAndDecode(image, decode_info, decoded_type, corners);
#endif

    return decode_info;
}

int main() {
    auto img = cv::imread("foo.png", cv::IMREAD_GRAYSCALE);

    for (const auto& res : read(img))
    {
        std::cout << res << std::endl;
    }
    return 0;
}

foo

Issue submission checklist

  • I report the issue, it's not a question
  • I checked the problem with documentation, FAQ, open issues, forum.opencv.org, Stack Overflow, etc and have not found any solution
  • I updated to the latest OpenCV version and the issue is still there
  • There is reproducer code and related data files (videos, images, onnx, etc)

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions