钢堆轮廓分割

void frmMain::test_fenge()
{
    //    std::string filename = "E:\\zhouzong\\lats_demo_for_old_computer\\ui\\uidemo01\\form\\image\\rect_1.png";

    cv::Mat img_yushe2=cv::imread("E:\\zhouzong\\new_img\\5.png");

    rect_list= selectAll();

    emit emit_rect_list(rect_list);
    cv::Mat img_yushe_imshow;
    cv::Mat img_yushe_recv;
    if(!img_yushe2.empty())
    {

        img_yushe_imshow=img_yushe2.clone();
        img_yushe_recv=img_yushe2.clone();
        for(unsigned int i=0;i(i,j)) == 0) {

                    coloredImage.at(i,j)[0] = 0;
                    coloredImage.at(i,j)[1] = 0;
                    coloredImage.at(i,j)[2] = 255;

                    binaryImage.at(i,j) = 255;

                    yellowArea.at(n)=yellowArea.at(n)+1;

                    //                    yellowArea.at(n)=yellowArea.at(n)+1;

                }
            }
        }
        if(frame_moving_index!=0)//不是第一帧的时候与之前的帧图片进行判别,
        {
            bool is_moving;
            if(yellowArea_olde.at(n)-yellowArea.at(n)>100)
            {
                is_moving=true;
                is_moving_steel.push_back(is_moving);
            }else
            {
                is_moving=false;
                is_moving_steel.push_back(is_moving);
            }
        }else if(frame_moving_index==0)//第一帧图片的时候进行赋值,
        {
            yellowArea_olde.push_back(yellowArea.at(n));

        }


        qDebug()<<"yellowArea.at(n)"<> contours;
        std::vector> contours_origin;
        std::vector hierarchy;
        cv::findContours(binaryImage, contours, hierarchy, cv::RETR_TREE, cv::CHAIN_APPROX_SIMPLE);
        contours_origin=contours;
        // 在彩色图像上画出轮廓,忽略在大轮廓内部的小轮廓以及面积小于阈值的轮廓
        double minContourArea = 100.0; // 设置最小轮廓面积阈值

        // 在彩色图像上画出轮廓,忽略在大轮廓内部的小轮廓
        for (size_t i = 0; i < contours.size(); i++) {

            //            qDebug()<<"rect_list.at(0).x"< minContourArea) {
                //注意这里要将轮廓的坐标加上截取的起始坐标
                for(size_t j = 0; j < contours[i].size(); j++)
                {

                    contours_origin[i][j].x += rect_list.at(n).x;
                    contours_origin[i][j].y += rect_list.at(n).y;
                }
                cv::drawContours(img_yushe2, contours_origin, static_cast(i), cv::Scalar(255, 0, 0), 5); // 使用蓝色画轮廓
            }
        }




        QPixmap img_test_xmap= my_publiction.cvMatToQPixmap(img_yushe2);
        // 设置QLabel的最小尺寸
        ui->lab1->setMinimumSize(600, 600);
        ui->lab1->setScaledContents(true);
        img_test_xmap = img_test_xmap.scaled( ui->lab1->width(),  ui->lab1->height(), Qt::KeepAspectRatio,Qt::SmoothTransformation); // 将图像缩放到QLabel的大小
        ui->lab1->setPixmap(img_test_xmap);

    }

    //与上次的钢堆进行对比,判别面积是否发生变化

    for(unsigned int k=0;k> contours;
    //          std::vector hierarchy;
    //          cv::findContours(dilated, contours, hierarchy, cv::RETR_TREE, cv::CHAIN_APPROX_SIMPLE);

    //          // 画出轮廓
    //          cv::Mat imageContours = cv::Mat::zeros(dilated.size(), CV_8UC3);
    //          for (size_t i = 0; i < contours.size(); i++) {
    //              cv::drawContours(imageContours, contours, static_cast(i), cv::Scalar(0, 255, 0));
    //          }



    //    // 寻找轮廓

    //    cv::findContours(dilated, contours, cv::RETR_TREE, cv::CHAIN_APPROX_SIMPLE);

    //    // 在原图上画出轮廓
    //    cv::Mat result = cv::Mat::zeros(img_test.size(), CV_8UC3);
    //    cv::drawContours(result, contours, -1, cv::Scalar(0, 255, 255));


    //    // 创建一个3x3的结构元素
        cv::Mat kernel = cv::getStructuringElement(cv::MORPH_RECT, cv::Size(4, 4));
    //    cv::Mat img_areaGrow;


    //    // 调用getArray函数
    //    std::vector pixel_num01 =  my_publiction.Sobel(img_test);
    //    Mat growArea = my_publiction.OTSU(img_test,pixel_num01);
    //    vectorimg_list= my_publiction.Sobelimg(img_test);
    //    //下面是显示图片的

}

你可能感兴趣的:(opencv,人工智能,计算机视觉)