Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
3a9120a
init barcode interface.
Certseeds Nov 19, 2020
2167cc9
barcode: update readme.
Certseeds Nov 19, 2020
55aa90f
now it is just interface, do not need CMakeLists to compiler it.
Certseeds Nov 26, 2020
8914da9
fix-trailing whitespace of docs-build.
Certseeds Nov 26, 2020
ad603e0
Branch: Barcode-Support,replace vector<RotateRect> to vector<vector<P…
Certseeds Dec 9, 2020
23684ec
add implementation details
darkliang Jan 4, 2021
86320bb
fix doc bug
darkliang Jan 4, 2021
de5bd88
not generate python bindings temporarily
darkliang Jan 4, 2021
457e1b4
add barcode group for doxygen
darkliang Jan 4, 2021
b8f0115
generate python bindings and improve performance
darkliang Jan 9, 2021
e81d975
remove win10 build warnings in detect stage
darkliang Jan 12, 2021
2349a10
remove win10 build warnings on decode stage
darkliang Jan 12, 2021
4ae4d1b
add samples and accuracy tests
WangberlinT Jan 26, 2021
accadbb
Update README.md
darkliang Mar 5, 2021
b2eb171
add tutorial, part of content is to be done.
darkliang Mar 23, 2021
21da4a7
add decode and EAN part in tutorial
WangberlinT Mar 24, 2021
1e79b6d
refactor imports
darkliang Mar 29, 2021
ab59fa7
delete decodeDirectly api for simplicity
darkliang Mar 29, 2021
dde14f0
add super resolution and optimize code format
WangberlinT Mar 30, 2021
94d38d5
Use @snippet / @include doxygen statements for embedding code from .c…
darkliang Mar 31, 2021
263070e
improve decoding performance
darkliang Apr 7, 2021
1b1c54d
optimize code and slightly improve the performance
darkliang Apr 8, 2021
fa9fa31
add ean8 support
darkliang Apr 10, 2021
43e6e6f
add references and use uint type for some non-negative variables
darkliang Apr 13, 2021
585ecb5
support java bindings
darkliang Apr 14, 2021
ba8367d
optimize wording in source code and documentation
darkliang Apr 15, 2021
afab937
refine code
darkliang Apr 16, 2021
68f55c3
whitespace
alalek Apr 16, 2021
1fe3ca1
bugfix: forget to clear list
darkliang Apr 16, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions modules/barcode/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
set(the_description "Barcode Detection and Decoding")
ocv_define_module(barcode opencv_core opencv_imgproc opencv_dnn WRAP python java)
9 changes: 9 additions & 0 deletions modules/barcode/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
1D Barcode Detect and Decode
======================

This module is focused on detecting and decoding barcode from image. It is mainly designed for scanning the images, locating barcode, decoding barcode and outputting its decoded result.

1. Support 1-dimension bar code detection of any angle tilting.
2. Support multi-scale detection.
3. Support EAN-13, EAN-8 and UPC-A decode yet.
4. With x86 CPU, it achieves 50FPS averagely.
28 changes: 28 additions & 0 deletions modules/barcode/doc/barcode.bib
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
@mastersthesis{Xiangmin2015research,
title={Research on Barcode Recognition Technology In a Complex Background},
author={Xiangmin, Wang},
year={2015},
school={Huazhong University of Science and Technology}
}

@article{bazen2002systematic,
title={Systematic methods for the computation of the directional fields and singular points of fingerprints},
author={Bazen, Asker M and Gerez, Sabih H},
journal={IEEE transactions on pattern analysis and machine intelligence},
volume={24},
number={7},
pages={905--919},
year={2002},
publisher={IEEE}
}

@article{kass1987analyzing,
title={Analyzing oriented patterns},
author={Kass, Michael and Witkin, Andrew},
journal={Computer vision, graphics, and image processing},
volume={37},
number={3},
pages={362--385},
year={1987},
publisher={Elsevier}
}
101 changes: 101 additions & 0 deletions modules/barcode/include/opencv2/barcode.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
// This file is part of OpenCV project.
// It is subject to the license terms in the LICENSE file found in the top-level directory
// of this distribution and at http://opencv.org/license.html.
// Copyright (c) 2020-2021 darkliang wangberlinT Certseeds

#ifndef __OPENCV_BARCODE_HPP__
#define __OPENCV_BARCODE_HPP__

#include <opencv2/core.hpp>
#include <ostream>

/** @defgroup barcode Barcode detecting and decoding methods
*/

namespace cv {
namespace barcode {

//! @addtogroup barcode
//! @{

enum BarcodeType
{
NONE, EAN_8, EAN_13, UPC_A, UPC_E, UPC_EAN_EXTENSION
};

static inline std::ostream &operator<<(std::ostream &out, const BarcodeType &barcode_type)
{
switch (barcode_type)
{
case BarcodeType::EAN_8:
out << "EAN_8";
break;
case BarcodeType::EAN_13:
out << "EAN_13";
break;
case BarcodeType::UPC_E:
out << "UPC_E";
break;
case BarcodeType::UPC_A:
out << "UPC_A";
break;
case BarcodeType::UPC_EAN_EXTENSION:
out << "UPC_EAN_EXTENSION";
break;
default:
out << "NONE";
}
return out;
}

class CV_EXPORTS_W BarcodeDetector
{
public:
/**
* @brief Initialize the BarcodeDetector.
* @param prototxt_path prototxt file path for the super resolution model
* @param model_path model file path for the super resolution model
*/
CV_WRAP BarcodeDetector(const std::string &prototxt_path = "", const std::string &model_path = "");

~BarcodeDetector();

/** @brief Detects Barcode in image and returns the rectangle(s) containing the code.
*
* @param img grayscale or color (BGR) image containing (or not) Barcode.
* @param points Output vector of vector of vertices of the minimum-area rotated rectangle containing the codes.
* For N detected barcodes, the dimensions of this array should be [N][4].
* Order of four points in vector< Point2f> is bottomLeft, topLeft, topRight, bottomRight.
*/
CV_WRAP bool detect(InputArray img, OutputArray points) const;

/** @brief Decodes barcode in image once it's found by the detect() method.
*
* @param img grayscale or color (BGR) image containing bar code.
* @param points vector of rotated rectangle vertices found by detect() method (or some other algorithm).
* For N detected barcodes, the dimensions of this array should be [N][4].
* Order of four points in vector<Point2f> is bottomLeft, topLeft, topRight, bottomRight.
* @param decoded_info UTF8-encoded output vector of string or empty vector of string if the codes cannot be decoded.
* @param decoded_type vector of BarcodeType, specifies the type of these barcodes
*/
CV_WRAP bool decode(InputArray img, InputArray points, CV_OUT std::vector<std::string> &decoded_info, CV_OUT
std::vector<BarcodeType> &decoded_type) const;

/** @brief Both detects and decodes barcode

* @param img grayscale or color (BGR) image containing barcode.
* @param decoded_info UTF8-encoded output vector of string(s) or empty vector of string if the codes cannot be decoded.
* @param decoded_type vector of BarcodeType, specifies the type of these barcodes
* @param points optional output vector of vertices of the found barcode rectangle. Will be empty if not found.
*/
CV_WRAP bool detectAndDecode(InputArray img, CV_OUT std::vector<std::string> &decoded_info, CV_OUT
std::vector<BarcodeType> &decoded_type, OutputArray points = noArray()) const;

protected:
struct Impl;
Ptr<Impl> p;
};
//! @}
}
} // cv::barcode::
#endif //__OPENCV_BARCODE_HPP__
1 change: 1 addition & 0 deletions modules/barcode/misc/java/filelist_common
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
misc/java/src/cpp/barcode_converters.hpp
12 changes: 12 additions & 0 deletions modules/barcode/misc/java/gen_dict.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"type_dict": {
"vector_BarcodeType": {
"j_type": "List<Integer>",
"jn_type": "List<Integer>",
"jni_type": "jobject",
"jni_var": "std::vector< cv::barcode::BarcodeType > %(n)s",
"suffix": "Ljava_util_List",
"v_type": "vector_BarcodeType"
}
}
}
28 changes: 28 additions & 0 deletions modules/barcode/misc/java/src/cpp/barcode_converters.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// This file is part of OpenCV project.
// It is subject to the license terms in the LICENSE file found in the top-level directory
// of this distribution and at http://opencv.org/license.html

// Author: darkliang

#include "barcode_converters.hpp"

#define LOG_TAG "org.opencv.barcode"


void Copy_vector_BarcodeType_to_List(JNIEnv* env, std::vector<cv::barcode::BarcodeType>& vs, jobject list)
{
static jclass juArrayList = ARRAYLIST(env);
jmethodID m_add = LIST_ADD(env, juArrayList);
jmethodID m_clear = LIST_CLEAR(env, juArrayList);
env->CallVoidMethod(list, m_clear);

static jclass jInteger = env->FindClass("java/lang/Integer");
static jmethodID m_create_Integer = env->GetMethodID(jInteger, "<init>", "(I)V");

for (size_t i = 0; i < vs.size(); ++i)
{
jobject element = env->NewObject(jInteger, m_create_Integer, vs[i]);
env->CallBooleanMethod(list, m_add, element);
env->DeleteLocalRef(element);
}
}
20 changes: 20 additions & 0 deletions modules/barcode/misc/java/src/cpp/barcode_converters.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// This file is part of OpenCV project.
// It is subject to the license terms in the LICENSE file found in the top-level directory
// of this distribution and at http://opencv.org/license.html

// Author: darkliang

#ifndef BARCODE_CONVERTERS_HPP
#define BARCODE_CONVERTERS_HPP

#include <jni.h>
#include "opencv_java.hpp"
#include "opencv2/core.hpp"
#include "opencv2/barcode.hpp"


using namespace cv::barcode;

void Copy_vector_BarcodeType_to_List(JNIEnv* env, std::vector<cv::barcode::BarcodeType>& vs, jobject list);

#endif /* BARCODE_CONVERTERS_HPP */
22 changes: 22 additions & 0 deletions modules/barcode/misc/python/pyopencv_barcode.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#ifdef HAVE_OPENCV_BARCODE
typedef std::vector<cv::barcode::BarcodeType> vector_BarcodeType;

template<> struct pyopencvVecConverter<cv::barcode::BarcodeType>
{
static bool to(PyObject* obj, std::vector<cv::barcode::BarcodeType>& value, const ArgInfo& info)
{
return pyopencv_to_generic_vec(obj, value, info);
}
static PyObject* from(const std::vector<cv::barcode::BarcodeType>& value)
{

return pyopencv_from_generic_vec(value);
}
};

template<>
bool pyopencv_to(PyObject *o, std::vector<cv::barcode::BarcodeType>& types, const ArgInfo& info)
{
return pyopencvVecConverter<cv::barcode::BarcodeType>::to(o, types, info);
}
#endif // HAVE_OPENCV_BARCODE
Loading