欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

OpenCV每日函數(shù)之BarcodeDetector類條碼檢測器

 更新時間:2022年06月16日 11:24:13   作者:坐望云起  
OpenCV在V4.5.3版本的contrib包中提供了一個barcode::BarcodeDetector類,用于條形碼的識別,這篇文章主要介紹了OpenCV每日函數(shù)?BarcodeDetector條碼檢測器,需要的朋友可以參考下

一、概述

OpenCV在V4.5.3版本的contrib包中提供了一個barcode::BarcodeDetector類,用于條形碼的識別。

二、類參考

1、函數(shù)原型

構(gòu)造方法

cv::barcode::BarcodeDetector::BarcodeDetector	(	const std::string & 	prototxt_path = "",
const std::string & 	model_path = "" 
)	

decode方法

bool cv::barcode::BarcodeDetector::decode	(	InputArray 	img,
InputArray 	points,
std::vector< std::string > & 	decoded_info,
std::vector< BarcodeType > & 	decoded_type 
)	

detect方法

bool cv::barcode::BarcodeDetector::detect	(	InputArray 	img,
OutputArray 	points 
)	

detectAndDecode方法

bool cv::barcode::BarcodeDetector::detectAndDecode	(	InputArray 	img,
std::vector< std::string > & 	decoded_info,
std::vector< BarcodeType > & 	decoded_type,
OutputArray 	points = noArray() 
)

2、參數(shù)詳解

img包含條形碼的灰度或彩色 (BGR) 圖像。
decoded_infoUTF8 編碼的字符串輸出向量或字符串的空向量(如果代碼無法解碼)。
decoded_typeBarcodeType 的向量,指定這些條形碼的類型
points找到的條形碼矩形的頂點的可選輸出向量。 如果找不到,則為空。

支持的條形碼類型如下。

enum  	cv::barcode::BarcodeType {
  cv::barcode::NONE,
  cv::barcode::EAN_8,
  cv::barcode::EAN_13,
  cv::barcode::UPC_A,
  cv::barcode::UPC_E,
  cv::barcode::UPC_EAN_EXTENSION
}

三、OpenCV源碼

1、源碼路徑

opencv_contrib\modules\barcode\src\barcode.cpp

2、源碼代碼

bool BarcodeDetector::detect(InputArray img, OutputArray points) const
{
    Mat inarr;
    if (!checkBarInputImage(img, inarr))
    {
        points.release();
        return false;
    }
 
    Detect bardet;
    bardet.init(inarr);
    bardet.localization();
    if (!bardet.computeTransformationPoints())
    { return false; }
    vector<vector<Point2f>> pnts2f = bardet.getTransformationPoints();
    vector<Point2f> trans_points;
    for (auto &i : pnts2f)
    {
        for (const auto &j : i)
        {
            trans_points.push_back(j);
        }
    }
 
    updatePointsResult(points, trans_points);
    return true;
}
 
bool BarcodeDetector::decode(InputArray img, InputArray points, vector<std::string> &decoded_info,
                             vector<BarcodeType> &decoded_type) const
{
    Mat inarr;
    if (!checkBarInputImage(img, inarr))
    {
        return false;
    }
    CV_Assert(points.size().width > 0);
    CV_Assert((points.size().width % 4) == 0);
    vector<vector<Point2f>> src_points;
    Mat bar_points = points.getMat();
    bar_points = bar_points.reshape(2, 1);
    for (int i = 0; i < bar_points.size().width; i += 4)
    {
        vector<Point2f> tempMat = bar_points.colRange(i, i + 4);
        if (contourArea(tempMat) > 0.0)
        {
            src_points.push_back(tempMat);
        }
    }
    CV_Assert(!src_points.empty());
    vector<Mat> bar_imgs = p->initDecode(inarr, src_points);
    BarDecode bardec;
    bardec.init(bar_imgs);
    bardec.decodeMultiplyProcess();
    const vector<Result> info = bardec.getDecodeInformation();
    decoded_info.clear();
    decoded_type.clear();
    bool ok = false;
    for (const auto &res : info)
    {
        if (res.format != NONE)
        {
            ok = true;
        }
 
        decoded_info.emplace_back(res.result);
        decoded_type.emplace_back(res.format);
    }
    return ok;
}
 
bool
BarcodeDetector::detectAndDecode(InputArray img, vector<std::string> &decoded_info, vector<BarcodeType> &decoded_type,
                                 OutputArray points_) const
{
    Mat inarr;
    if (!checkBarInputImage(img, inarr))
    {
        points_.release();
        return false;
    }
    vector<Point2f> points;
    bool ok = this->detect(img, points);
    if (!ok)
    {
        points_.release();
        return false;
    }
    updatePointsResult(points_, points);
    decoded_info.clear();
    decoded_type.clear();
    ok = this->decode(inarr, points, decoded_info, decoded_type);
    return ok;
}

四、效果圖像示例

示例圖像

參考代碼,opencvsharp版本的需要打開barcode并重新編譯,所以使用c++代碼進(jìn)行示例。

cv::Mat mata = cv::imread("barcode.png");
cv::barcode::BarcodeDetector barcode;
std::vector<string> info;
std::vector<cv::barcode::BarcodeType> type;
Mat points;
barcode.detectAndDecode(mata, info, type, points);

識別結(jié)果,可以看到第一個和第三個識別結(jié)果正確,不知道是否是放在一起的原因,下面把另外兩個裁剪出來識別看看。

 

最后一個沒有識別出來

把最后一個單獨裁剪出來在測試下也沒有識別出來,不過UPCE類型的應(yīng)該支持才對,暫時不進(jìn)行深究。

到此這篇關(guān)于OpenCV每日函數(shù)BarcodeDetector條碼檢測器的文章就介紹到這了,更多相關(guān)OpenCV條碼檢測器內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

  • GitHub上值得推薦的8個python 項目

    GitHub上值得推薦的8個python 項目

    GitHub 無疑是代碼托管領(lǐng)域的先行者,Python 作為一種通用編程語言,已經(jīng)被千千萬萬的開發(fā)人員用來構(gòu)建各種有意思或有用的項目。以下我們會介紹一些使用 Python 構(gòu)建的GitHub上優(yōu)秀的項目。
    2020-10-10
  • Python常見庫matplotlib學(xué)習(xí)筆記之畫圖文字的中文顯示

    Python常見庫matplotlib學(xué)習(xí)筆記之畫圖文字的中文顯示

    在Python中使用matplotlib或者plotnine模塊繪圖時,常常出現(xiàn)圖表中無法正常顯示中文的問題,下面這篇文章主要給大家介紹了關(guān)于Python常見庫matplotlib學(xué)習(xí)筆記之畫圖文字的中文顯示的相關(guān)資料,需要的朋友可以參考下
    2023-05-05
  • 安裝Python的教程-Windows

    安裝Python的教程-Windows

    下面小編就為大家?guī)硪黄惭bPython的教程-Windows。小編覺得挺不錯的,現(xiàn)在就分享給大家,也給大家做個參考。一起跟隨小編過來看看吧
    2017-07-07
  • Python單元測試框架unittest使用方法講解

    Python單元測試框架unittest使用方法講解

    這篇文章主要介紹了Python單元測試框架unittest使用方法講解,本文講解了unittest概述、命令行接口、測試案例自動搜索、創(chuàng)建測試代碼、構(gòu)建測試套件方法等內(nèi)容,需要的朋友可以參考下
    2015-04-04
  • 使用Django Form解決表單數(shù)據(jù)無法動態(tài)刷新的兩種方法

    使用Django Form解決表單數(shù)據(jù)無法動態(tài)刷新的兩種方法

    這篇文章主要介紹了使用Django Form解決表單數(shù)據(jù)無法動態(tài)刷新的兩種方法,需要的朋友可以參考下
    2017-07-07
  • Python中__init__.py文件的作用

    Python中__init__.py文件的作用

    這篇文章主要介紹了Python中__init__.py文件的作用,在PyCharm中,帶有__init__.py這個文件的目錄被認(rèn)為是Python的包目錄,與普通目錄的圖標(biāo)有不一樣的顯示
    2022-09-09
  • 將字典轉(zhuǎn)換為DataFrame并進(jìn)行頻次統(tǒng)計的方法

    將字典轉(zhuǎn)換為DataFrame并進(jìn)行頻次統(tǒng)計的方法

    下面小編就為大家分享一篇將字典轉(zhuǎn)換為DataFrame并進(jìn)行頻次統(tǒng)計的方法,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2018-04-04
  • 詳解C++編程中一元運算符的重載

    詳解C++編程中一元運算符的重載

    這篇文章主要介紹了C++編程中一元運算符的重載,特別對遞增和遞減運算符重載作了著重講解,需要的朋友可以參考下
    2016-01-01
  • Python實現(xiàn)的最近最少使用算法

    Python實現(xiàn)的最近最少使用算法

    這篇文章主要介紹了Python實現(xiàn)的最近最少使用算法,涉及節(jié)點、時間、流程控制等相關(guān)技巧,需要的朋友可以參考下
    2015-07-07
  • 對PyQt5中的菜單欄和工具欄實例詳解

    對PyQt5中的菜單欄和工具欄實例詳解

    今天小編就為大家分享一篇對PyQt5中的菜單欄和工具欄實例詳解,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2019-06-06

最新評論