我们可以在没有预定义的情况下在OpenCV中使用push_back()函数吗?

时间:2014-10-29 04:55:08

标签: c++ opencv

我使用push_back函数有和没有预定义(cv :: Mat F& cv :: Mat F(0,5,CV_64F)),但还没有得到任何错误。我想知道在没有预定义的情况下使用push_back是否会导致错误。

这是我的代码:

void kyori(cv::Mat rBlob, cv::Mat bBlob, cv::Mat& dst) {
    int i, j, n, m;
    double x_avg, y_avg;
    double h = 0;
    cv::Mat in, R;
    rBlob.convertTo(in, CV_64F);
    bBlob.convertTo(R, CV_64F);

    n = in.rows;
    m = R.rows;
    cv::Mat F, temp(1, 5, CV_64F);     // also F(0, 5, CV_64F)

    for( i = 0; i <= n; i++ ) {
        for( j = 0; j <= m; j++ ) {
            x_avg = abs( (in.at<double>(i,2) + in.at<double>(i,4))/2 - (R.at<double>(j,2) + R.at<double>(j,4))/2 );
            y_avg = abs( (in.at<double>(i,3) + in.at<double>(i,5))/2 - (R.at<double>(j,3) + R.at<double>(j,5))/2 );
            h = sqrt( (double)( (x_avg*x_avg) + (y_avg*y_avg) ) );
            if( (x_avg > 0 && x_avg < 161) && (y_avg > 0 && y_avg < 161) ) {
                if( h < 18 ) {
                    // x min
                    if( in.at<double>(i,2) < R.at<double>(j,2) ) 
                        temp.at<double>(0, 0) = in.at<double>(i,2);
                    else
                        temp.at<double>(0, 0) = R.at<double>(j,2);
                    // x max
                    if( in.at<double>(i,4) < R.at<double>(j,4) ) 
                        temp.at<double>(0, 1) = in.at<double>(i,4);
                    else
                        temp.at<double>(0, 1) = R.at<double>(j,4);

                    // y min
                    if( in.at<double>(i,3) < R.at<double>(j,3) ) 
                        temp.at<double>(0, 2) = in.at<double>(i,3);
                    else
                        temp.at<double>(0, 2) = R.at<double>(j,3);
                    // y max
                    if( in.at<double>(i,5) < R.at<double>(j,5) ) 
                        temp.at<double>(0, 3) = in.at<double>(i,5);
                    else
                        temp.at<double>(0, 3) = R.at<double>(j,5);


                    temp.at<double>(0,4) = h;   
                    F.push_back(temp);
                }
            }
        }
    }

    if( !F.empty() )
        dst = F.clone();
}

提前致谢。

0 个答案:

没有答案