微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

stereoRectifyUncalibrated不良结果

如何解决stereoRectifyUncalibrated不良结果

for (size_t i = 0; i < matches.size(); i++)
{
    if (matches[i].distance < 0.6 * matches[i+1].distance)
    {
        good_matches.push_back(matches[i]);
        pt1.push_back(keypoints1[matches[i].queryIdx].pt);
        pt2.push_back(keypoints2[matches[i].trainIdx].pt);

    }
}
std::vector<cv::Point2f> upt1;
std::vector<cv::Point2f> upt2;
cv::undistortPoints(pt1,upt1,cameraMatrix,distCoeffs);
cv::undistortPoints(pt2,upt2,distCoeffs);    
cv::Mat f = cv::findFundamentalMat(cv::Mat(upt1),cv::Mat(upt2),cv::FM_RANSAC,3,0.99);
std::vector<cv::Vec3f> lines1;

cv::computeCorrespondEpilines(cv::Mat(upt1),1,f,lines1);
for (auto iter = lines1.begin(); iter != lines1.end(); ++iter){
    cv::line(img2,cv::Point(0,-(*iter)[2] / (*iter)[1]),cv::Point(img2.cols,-((*iter)[2] + (*iter)[0] * img2.cols) / (*iter)[1]),cv::Scalar(255,255,255));
}


std::vector<cv::Vec3f> lines2;
cv::computeCorrespondEpilines(cv::Mat(upt2),2,lines2);
for (auto iter = lines2.begin(); iter != lines2.end(); ++iter){

    cv::line(img1,cv::Point(img1.cols,-((*iter)[2] + (*iter)[0] * img1.cols) / (*iter)[1]),255));
}
cv::Mat H1(4,4,img1.type());
cv::Mat H2(4,img2.type());
cv::stereoRectifyUncalibrated(upt1,img1.size(),H1,H2);

cv::Mat rectified1(img1.size(),img1.type());
cv::warpPerspective(img1,rectified1,img1.size());
cv::imwrite("rectified1.jpg",rectified1);

cv::Mat rectified2(img2.size(),img2.type());
cv::warpPerspective(img2,rectified2,H2,img2.size());
cv::imwrite("rectified2.jpg",rectified2);

opencv:4.0 ubuntu:20.04

pcameraMatrix和distCoeffs从calibrateCamera()获得。 上面的代码被部分省略。

结果图 [![在此处输入图片描述] [1]] [1]

左侧结果为灰色。问题是什么? 与其他图片一起运行的结果是相同的。 [1]:https://i.stack.imgur.com/HAJLa.jpg

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。