Question

I'm using the cv::projectPoints to get correspondent pixels of a vector of 3D points.

The points are all near each other.

The problem is that for some points I get correct pixels coordinates but for other I get strange negative values like -22599...

Is it normal that cv::projectPoints return negative values or is it a bug in my code?

void SingleCameraTriangulator::projectPointsToImage2(const std::vector< cv::Vec3d >& pointsGroup, const double scale, std::vector< Pixel >& pixels)
{
    cv::Vec3d 
        t2, r2;

    decomposeTransformation(*g_12_, r2, t2);

    cv::Mat imagePoints2;

    cv::projectPoints(pointsGroup, r2, t2, *camera_matrix_, *distortion_coefficients_, imagePoints2);

    for (std::size_t i = 0; i < imagePoints2.rows; i++)
    {
        cv::Vec2d pixel = imagePoints2.at<cv::Vec2d>(i);
        Pixel p;
        p.x_ = pixel[0];
        p.y_ = pixel[1];
        if ( (p.x_ < 0) || (p.x_ > ((1 / scale) * img_1_->cols)) || (p.y_ < 0) || (p.y_ > ((1/scale) * img_1_->rows)))
        {
            cv::Vec3d point = pointsGroup[i];
            std::cout << point << " - " << pixel << " - " << pixel*scale << "problema" << std::endl;
        }
        p.i_ = getBilinearInterpPix32f(*img_2_, scale * p.x_, scale * p.y_);

        pixels.push_back(p);
    }
}

Thank you in advance for any suggestions.

Was it helpful?

Solution

reprojectImageTo3D (are you use it for getting 3D points?) gives large z coordinates (10000) for outlier points, so I think your problem is here.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top