最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

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

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

一、概述

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

二、類參考

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 編碼的字符串輸出向量或字符串的空向量(如果代碼無(wú)法解碼)。
decoded_typeBarcodeType 的向量,指定這些條形碼的類型
points找到的條形碼矩形的頂點(diǎn)的可選輸出向量。 如果找不到,則為空。

支持的條形碼類型如下。

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版本的需要打開(kāi)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);

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

 

最后一個(gè)沒(méi)有識(shí)別出來(lái)

把最后一個(gè)單獨(dú)裁剪出來(lái)在測(cè)試下也沒(méi)有識(shí)別出來(lái),不過(guò)UPCE類型的應(yīng)該支持才對(duì),暫時(shí)不進(jìn)行深究。

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

相關(guān)文章

  • Python讀取nc文件的多種方式總結(jié)

    Python讀取nc文件的多種方式總結(jié)

    Python中讀取NetCDF文件有多種方法,包括使用netCDF4、xarray、h5py、SciPy和Pseudonetcdf等庫(kù),文中通過(guò)代碼介紹的非常詳細(xì),需要的朋友可以參考下
    2024-09-09
  • Django的models中on_delete參數(shù)詳解

    Django的models中on_delete參數(shù)詳解

    這篇文章主要介紹了Django的models中on_delete參數(shù)詳解,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧
    2019-07-07
  • 簡(jiǎn)單談?wù)刾ython中的多進(jìn)程

    簡(jiǎn)單談?wù)刾ython中的多進(jìn)程

    multiprocessing模塊是python庫(kù)中最高級(jí)和功能最強(qiáng)大的模塊之一。本文就來(lái)給大家簡(jiǎn)單講講multiprocessing一般性技巧
    2016-11-11
  • Python爬蟲(chóng)scrapy框架Cookie池(微博Cookie池)的使用

    Python爬蟲(chóng)scrapy框架Cookie池(微博Cookie池)的使用

    這篇文章主要介紹了Python爬蟲(chóng)scrapy框架Cookie池(微博Cookie池)的使用,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧
    2021-01-01
  • 在Django的form中使用CSS進(jìn)行設(shè)計(jì)的方法

    在Django的form中使用CSS進(jìn)行設(shè)計(jì)的方法

    這篇文章主要介紹了在Django的form中使用CSS進(jìn)行設(shè)計(jì)的方法,Django是Python重多人氣開(kāi)發(fā)框架中最為著名的一個(gè),需要的朋友可以參考下
    2015-07-07
  • pyqt5-tools安裝失敗的詳細(xì)處理方法

    pyqt5-tools安裝失敗的詳細(xì)處理方法

    最近在工作中遇到一個(gè)問(wèn)題,python?pyqt5在安裝的時(shí)候居然提示失敗了,無(wú)奈只能找解決的辦法,這篇文章主要給大家介紹了關(guān)于pyqt5-tools安裝失敗的詳細(xì)處理方法,需要的朋友可以參考下
    2022-05-05
  • Python實(shí)現(xiàn)購(gòu)物車功能的方法分析

    Python實(shí)現(xiàn)購(gòu)物車功能的方法分析

    這篇文章主要介紹了Python實(shí)現(xiàn)購(gòu)物車功能的方法,結(jié)合實(shí)例形式分析了Python實(shí)現(xiàn)購(gòu)物車功能的具體步驟、相關(guān)操作技巧與注意事項(xiàng),需要的朋友可以參考下
    2017-11-11
  • Python速成篇之像selenium一樣操作電腦詳解

    Python速成篇之像selenium一樣操作電腦詳解

    這篇文章為大家介紹了在Python中如何像selenium一樣操作電腦,本文主要使用的是pyautogui庫(kù),文中的示例代碼講解詳細(xì),感興趣的可以了解一下
    2022-08-08
  • Python中endswith()函數(shù)的基本使用

    Python中endswith()函數(shù)的基本使用

    這篇文章主要介紹了Python中endswith()函數(shù)的基本使用,是Python學(xué)習(xí)當(dāng)中的基礎(chǔ)知識(shí),該函數(shù)可以用來(lái)檢測(cè)文件類型,需要的朋友可以參考下
    2015-04-04
  • Python與Matlab混合編程的實(shí)現(xiàn)案例

    Python與Matlab混合編程的實(shí)現(xiàn)案例

    本文主要介紹了Python與Matlab混合編程的實(shí)現(xiàn)案例,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧
    2023-01-01

最新評(píng)論

利辛县| 喀喇沁旗| 中西区| 德令哈市| 犍为县| 垦利县| 福贡县| 永安市| 鸡西市| 义马市| 额济纳旗| 沙洋县| 乐至县| 凤凰县| 台南县| 天台县| 会昌县| 和田市| 遂昌县| 沾化县| 云南省| 商水县| 体育| 肇东市| 会宁县| 甘孜县| 呼玛县| 萍乡市| 论坛| 健康| 长子县| 方正县| 弥勒县| 清徐县| 繁峙县| 望谟县| 星子县| 香港| 仲巴县| 叙永县| 景东|