• 【计算机视觉基础】IPM


    IPM

    code

    #if 0
    void xyp2ipmp(cv::Mat& xyp, cv::Mat& ipmp, cv::Mat& xylim, Size& sz){
    
        //xylimist_[0]-latteral/xylimist_[1]-longitudinal...
        //ipmp-row0-cols-latteral/ipmp-row1-rows-longitudinal...
    
        double xmin = 0, xmax = 0, ymin = 0, ymax = 0;
        minMaxLoc(xylim.row(0), &xmin, &xmax);
        minMaxLoc(xylim.row(1), &ymin, &ymax);
    
        double stepcol = (xmax - xmin) / sz.width;
        double steprow = (ymax - ymin) / sz.height;
    
        cv::Mat tempx = cv::Mat::ones(1, xyp.cols, CV_64FC1) * xmin;
        cv::Mat tempy = cv::Mat::ones(1, xyp.cols, CV_64FC1) * ymax;
    
        ipmp = cv::Mat::zeros(2, xyp.cols, CV_64FC1);
        ipmp.rowRange(0, 1) = ( xyp.rowRange(0, 1) - tempx ) / stepcol;
        ipmp.rowRange(1, 2) = ( tempy - xyp.rowRange(1, 2) ) / steprow;
        for (int i = 0; i < xyp.cols; i++ )
        {
            double y = ipmp.at<double>(1, i);
            if( y > ymax){
                ipmp.at<double>(1, i) = ymax;
            }
        }
        
    }
    #endif

    code

    #if 0
        //IPM-parameters...    
        double left_upper_x = 1;//left
        double left_upper_y = 330;//top-greater than 320...
        double right_down_x = 1280;//right...
        double right_down_y = 720;//bottom...
        double uvlimist[8] = { left_upper_x, right_down_x, left_upper_x, right_down_x, 
                               left_upper_y, left_upper_y, right_down_y, right_down_y };
        cv::Mat uvlmt = cv::Mat(2, 4, CV_64FC1, uvlimist);
    
         //I2G
        cv::Mat xylimit;
        imagetoground(uvlmt, xylimit, h, roll, pitch, camera_param_KK);
         //G2I
        cv::Mat uvgd;
        cv::Size sz = cv::Size(PROB_W, PROB_H);//Size(srcimage.cols, srcimage.rows)
        groundtoimage(xylimit, uvgd, sz, h, roll, pitch, camera_param_KK );
    #endif

    code

    #if 1
            //IPM...
            cv::Mat outimage, coord;
            src2ipm( prob, uvgd, outimage, coord, sz, h, roll, pitch, camera_param_KK );
            outimage.convertTo(outimage, CV_8UC1);
            cv::Mat ipm3 = cv::Mat::zeros(PROB_H, PROB_W, CV_8UC3);
            cv::cvtColor(outimage, ipm3, COLOR_GRAY2BGR);
    
            //
            //cv::Mat uvp = cv::Mat::zeros(2, probp.size(), CV_8UC1);
            cv::Mat uvp = cv::Mat::zeros(2, probp.size(), CV_64FC1);//data-type...
            for (unsigned int i = 0; i <probp.size(); i++ )
            {
                uvp.at<double>(0, i) = probp[i].x;//cols-width.
                uvp.at<double>(1, i) = probp[i].y;//rows-height.
                //std::cout <<  uvp.at<double>(0, i) << "-----" << probp[i].x <<std::endl;
                //std::cout <<  uvp.at<double>(1, i) << "-----" << probp[i].y <<std::endl;
            }
            cv::Mat ipmps, xyp;
            //std::cout << "uvp:" << uvp << std::endl;
            imagetoground(uvp, xyp, h, roll, pitch, camera_param_KK);
            xyp2ipmp(xyp, ipmps, xylimit, sz);
            ipmps.convertTo(ipmps, CV_32SC1);
            for (unsigned int i = 0; i <probp.size(); i++ )
            {
                cv::Point ipmp;
                ipmp.x = ipmps.at<int>(0, i);
                ipmp.y = ipmps.at<int>(1, i);
                if (plabel[i] == 1)//-barrier
                {
                    cv::circle(ipm3, ipmp, 3, cv::Scalar(240, 32, 160), -1); //
                    //cv::putText(orig, std::to_string(i), pt, CV_FONT_NORMAL, 0.1, cv::Scalar(255, 255, 255));
                }
                else if (plabel[i] == 0)//-undifined
                {
                    cv::circle(ipm3, ipmp, 3, cv::Scalar(255, 255, 0), -1); //
                    //cv::putText(orig, std::to_string(i), pt, CV_FONT_NORMAL, 0.1, cv::Scalar(255, 255, 255));
                }
        
            }
    
            cv::imshow("ipmp", ipm3);
            cv::waitKey(1);//unit-ms.
            sprintf(output_path,"./ipmp/00000%05d.png",cnt);
            cv::imwrite(output_path, ipm3);
    #endif

    参考

    1. matlab_逆透视变换详解 及 代码实现(一);

    2. matlab_逆透视变换详解 及 代码实现(二);

  • 相关阅读:
    mysql中InnoDB存储引擎的行锁和表锁
    阿里云出海 埃森哲护航
    阿里云出海 埃森哲护航
    阿里云出海 埃森哲护航
    阿里云出海 埃森哲护航
    Python开发简单爬虫
    Python开发简单爬虫
    Python开发简单爬虫
    Python开发简单爬虫
    问大家一个问题,如何用1万元创业,每天利润达到500元?
  • 原文地址:https://www.cnblogs.com/happyamyhope/p/11855490.html
Copyright © 2020-2023  润新知