nowmengxin 2021-05-16 13:24 采纳率: 100%
浏览 13
已结题

萌新opeencv遇到了程序运行不下去问题前面附上问题,后面附上代码

#include<opencv2/opencv.hpp>
#include<opencv2/highgui/highgui_c.h>
#include<zbar.h>

using namespace cv;
using namespace std;

int main(int argc,char**argv)
    {
    Mat src, dst,gdst,mdst,xdst,ydst,bidst,pengdst;
        src= imread("F:\\条形码.jpg", IMREAD_ANYCOLOR);
    if (src.empty()) {
                printf("not pitcure");
                return -1;
            }
            imshow("input", src);
            cvtColor(src, dst, CV_BGR2GRAY);//灰度图
            imshow("huidutu", dst);
            GaussianBlur(dst, gdst, Size(3, 3), 0);//高斯滤波
            medianBlur(gdst, mdst, 3);//中值滤波
            imshow("gao+zhong", mdst);
            Scharr(mdst, xdst, -1, 1, 0);//
            Scharr(mdst, ydst, -1, 0, 1);
            imshow("x梯度图", xdst);
            imshow("y梯度图", ydst);
            int width = xdst.cols;
            int height = ydst.rows;
            Mat xydst =Mat (xdst.size(), xdst.type());
            for (int row = 0; row < height; row++) {
                for (int col = 0; col < width; col++) {
                    int xg = xdst.at<char>(row, col);
                    int yg = ydst.at<char>(row, col);
                    int xy = xg + yg;
                    xydst.at<char>(row, col) = xy;
                }
            }
        imshow("final resule", xydst);
        threshold(xydst,xydst,100,255,THRESH_BINARY);//二值化100分割线
        Mat kernel = getStructuringElement(MORPH_RECT,Size(3,3),Point(-1,-1));
        morphologyEx(xydst, bidst, MORPH_CLOSE, kernel);//闭操作
        for (int i = 0; i < 3; i++) {
            dilate(bidst, pengdst, kernel);
        }//膨胀三次
        imshow("膨胀图", pengdst);
        Mat huodst;
        vector<vector<Point>>contours;
        vector<vector<Vec4i>>hierachy;
        findContours(pengdst, contours, hierachy, CV_RETR_EXTERNAL,CHAIN_APPROX_NONE,Point(0,0));//获得轮廓
        huodst = Mat::zeros(pengdst.size(), CV_8UC1);
        RNG rng(12345);
        for (size_t z = 0; z < contours.size(); z++) {
            Scalar color = Scalar(rng.uniform(0, 255), rng.uniform(0, 255), rng.uniform(0, 255));
            drawContours(huodst, contours,z, color, 2,8, hierachy, 0,Point(0,0));//绘制图像
        };
        imshow("二维码",huodst);
        waitKey(0);
        return 0;
    }
 

 

  • 写回答

2条回答 默认 最新

  • 爱晚乏客游 2021-05-16 15:45
    关注

    findcontour上面的那个类型错误了,用vector<Vec4i>hierachy;

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

问题事件

  • 系统已结题 4月8日
  • 已采纳回答 3月31日

悬赏问题

  • ¥15 2020长安杯与连接网探
  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
  • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
  • ¥16 mybatis的代理对象无法通过@Autowired装填
  • ¥15 可见光定位matlab仿真
  • ¥15 arduino 四自由度机械臂
  • ¥15 wordpress 产品图片 GIF 没法显示
  • ¥15 求三国群英传pl国战时间的修改方法
  • ¥15 matlab代码代写,需写出详细代码,代价私
  • ¥15 ROS系统搭建请教(跨境电商用途)