opencv条形码识别(已经实现)

在做别的东西的同时,用opencv写了一份简单粗暴的条形码的检测识别,
还需要做更加多的逻辑识别处理

#include <iostream>
#include<opencv2/opencv.hpp>
#include<opencv2/highgui/highgui.hpp>
#include<opencv2/core/core.hpp>

using namespace cv;
using namespace std;

Mat Image_process(Mat &src1)
{
    resize(src1,src1,Size(640,480));
    Mat dst;
    cvtColor(src1,dst,COLOR_BGR2GRAY);
    threshold(dst,dst,0,255,THRESH_BINARY_INV);
    Mat element=getStructuringElement(MORPH_ELLIPSE,Size(17,17));
    dilate(dst,dst,element);
    return dst;
}
int main()
{
    Mat src=imread("/home/sms/tu/download.png");

    Mat get_out=Image_process(src);
    imshow("原图",src);
    imshow("dst",get_out);
    vector<vector<Point>> contours;
    findContours(get_out,contours,RETR_TREE,CHAIN_APPROX_SIMPLE);
    vector<Rect> bounding(contours.size());
    vector<Rect> Rect_temp;
    for (size_t i=0;i<contours.size();i++)
    {
        bounding[i]=boundingRect(Mat(contours[i]));
        cout<<"第i"<<i<<"个轮廓的面积是"<<bounding[i].area()<<endl;
        if(bounding[i].area()>5000)
        {
            Rect_temp.push_back(bounding[i]);
        }
    }
    cout<<"大于500的轮廓面积是"<<Rect_temp.at(0).area()<<endl;
    for (size_t i=0;i<Rect_temp.size();++i)
    {
           rectangle(src,Rect_temp[i].tl(),Rect_temp[i].br(),Scalar(0,0,255),10,8);
    }
    imshow("drawing",src);
    waitKey(0);
}
![检测后的图](https://img-blog.csdnimg.cn/2020112117582331.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L01zeXVzaGVuZw==,size_16,color_FFFFFF,t_70#pic_center)

  • 0
    点赞
  • 18
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值