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 关于#java#的问题:找一份能快速看完mooc视频的代码
  • ¥15 这种微信登录授权 谁可以做啊
  • ¥15 请问我该如何添加自己的数据去运行蚁群算法代码
  • ¥20 用HslCommunication 连接欧姆龙 plc有时会连接失败。报异常为“未知错误”
  • ¥15 网络设备配置与管理这个该怎么弄
  • ¥20 机器学习能否像多层线性模型一样处理嵌套数据
  • ¥20 西门子S7-Graph,S7-300,梯形图
  • ¥50 用易语言http 访问不了网页
  • ¥50 safari浏览器fetch提交数据后数据丢失问题
  • ¥15 matlab不知道怎么改,求解答!!