zoukankan      html  css  js  c++  java
  • 飞龙绣球2.0

      简化了识别的过程,但是基本的原理没有改变,加入了轨迹条,更加方便的调节参数

    Mat img;
    //灰度值归一化
    Mat bgr;
    //HSV图像
    Mat hsv;
    //输出图像
    Mat mask;
    Mat picture;
    
    
    int Hm = 0, Sm = 43, Vm = 46;
    int Hx = 10, Sx = 255, Vx = 255;
    void CALL_BACK(int,void*)
    {
        inRange(hsv, Scalar(Hm, Sm, Vm), Scalar(Hx, Sx,Vx), mask);
        imshow("颜色筛选", mask);
    }
    
    int main(int argc, char** argv)
    {
        system("color 02");
        cout << "寻找黄色飞龙绣球得到最小外边框" << endl;
        VideoCapture capture(0);
        while (1)
        {
            //帧转变为图像
            capture >> picture;//imread("D:\4.jpg");
             //方框滤波处理
            boxFilter(picture, img, -1, Size(5, 2));
            bgr = img.clone();        //对输出图像大小的限制 Automatic size
            cvtColor(bgr, hsv, CV_BGR2HSV);
    
            createTrackbar("Hmin","颜色筛选",&Hm,255, CALL_BACK);
            createTrackbar("Smin", "颜色筛选", &Sm, 255, CALL_BACK);
            createTrackbar("Vmin", "颜色筛选", &Vm, 255, CALL_BACK);
            createTrackbar("Hx", "颜色筛选", &Hx, 255, CALL_BACK);
            createTrackbar("Sx", "颜色筛选", &Sx, 255, CALL_BACK);
            createTrackbar("Vx", "颜色筛选", &Vx, 255, CALL_BACK);
            CALL_BACK(0, 0);

          Mat element = getStructuringElement(MORPH_RECT, Size(9, 9)); //图像膨胀
          dilate(mask, mask, element, Point(-1, -1), 2);

            
            namedWindow("DEALED", 0);
    
            vector<vector<Point> > contours;
            vector<Vec4i> hierarchy;
            findContours(mask, contours, hierarchy, RETR_CCOMP, CHAIN_APPROX_SIMPLE);
            RotatedRect box;
            double area = 0;
            for (int i = 0; i < contours.size(); i++)
            {
                if (contourArea(contours[i]) > area)
                {
                    area = contourArea(contours[i]);
                    box = minAreaRect(contours[i]);
                }
            }
            Point2f vertex[4];
            box.points(vertex);
            for (int i = 0; i < 4; i++)
            {
               line(img, vertex[i], vertex[(i + 1) % 4], Scalar(100, 200, 300), 2,LINE_AA);
            }
            imshow("DEALED", img);
            waitKey(10);
        }
        return 0;
    }
    

      后续会继续的更新的

  • 相关阅读:
    javascript简繁转换函数
    在嵌套的repeater中加ItemDataBound事件
    asp.net url重写方法和步骤
    打开,另存为,属性,打印"等14个JS代码
    php中global的用法
    ini_get
    PHP学习笔记
    PHP isset()与empty()的使用区别详解
    PHP符号说明
    html禁止清除input文本输入缓存
  • 原文地址:https://www.cnblogs.com/Loving-Q/p/12629627.html
Copyright © 2011-2022 走看看