首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >全景形象建设

全景形象建设
EN

Stack Overflow用户
提问于 2017-07-15 05:46:31
回答 1查看 80关注 0票数 1

我试图从不同的图像构建全景图。最初,我试图缝合两幅图片,作为全景结构的一部分。我试图缝制的两幅输入图像是:

我使用ORB特征描述符在图像中找到特征,然后找出这两幅图像之间的单形矩阵。我的代码是:

代码语言:javascript
复制
int main(int argc, char **argv){

Mat img1 = imread(argv[1],1);
Mat img2 = imread(argv[2],1);
//-- Step 1: Detect the keypoints using orb Detector
std::vector<KeyPoint> kp2,kp1;

// Default parameters of ORB
int nfeatures=500;
float scaleFactor=1.2f;
int nlevels=8;
int edgeThreshold=15; // Changed default (31);
int firstLevel=0;
int WTA_K=2;
int scoreType=ORB::HARRIS_SCORE;
int patchSize=31;
int fastThreshold=20;

Ptr<ORB> detector = ORB::create(
        nfeatures,
        scaleFactor,
        nlevels,
        edgeThreshold,
        firstLevel,
        WTA_K,
        scoreType,
        patchSize,
        fastThreshold );
Mat descriptors_img1, descriptors_img2;


//-- Step 2: Calculate descriptors (feature vectors)
detector->detect(img1, kp1,descriptors_img1);
detector->detect(img2, kp2,descriptors_img2);


Ptr<DescriptorExtractor> extractor = ORB::create();
extractor->compute(img1, kp1, descriptors_img1 );
extractor->compute(img2, kp2, descriptors_img2 );
//-- Step 3: Matching descriptor vectors using FLANN matcher
if ( descriptors_img1.empty() )
    cvError(0,"MatchFinder","1st descriptor empty",__FILE__,__LINE__);
if ( descriptors_img2.empty() )
    cvError(0,"MatchFinder","2nd descriptor empty",__FILE__,__LINE__);
descriptors_img1.convertTo(descriptors_img1, CV_32F);
descriptors_img2.convertTo(descriptors_img2, CV_32F);
FlannBasedMatcher matcher;
std::vector<DMatch> matches;
matcher.match(descriptors_img1,descriptors_img2,matches);
double max_dist = 0; double min_dist = 100;

//-- Quick calculation of max and min distances between keypoints
for( int i = 0; i < descriptors_img1.rows; i++ )
{
    double dist = matches[i].distance;
    if( dist < min_dist )
        min_dist = dist;
    if( dist > max_dist )
        max_dist = dist;
}

printf("-- Max dist : %f \n", max_dist );
printf("-- Min dist : %f \n", min_dist );

//-- Draw only "good" matches (i.e. whose distance is less than 3*min_dist )
std::vector< DMatch > good_matches;

for( int i = 0; i < descriptors_img1.rows; i++ )
{
    if( matches[i].distance < 3*min_dist )
    {
        good_matches.push_back( matches[i]);
    }
}
Mat img_matches;
drawMatches(img1,kp1,img2,kp2,good_matches,img_matches,Scalar::all(-1),
        Scalar::all(-1),vector<char>(),DrawMatchesFlags::NOT_DRAW_SINGLE_POINTS );
std::vector<Point2f> obj;
std::vector<Point2f> scene;
for( int i = 0; i < good_matches.size(); i++ )
{
    //-- Get the keypoints from the good matches
    obj.push_back( kp1[ good_matches[i].queryIdx ].pt );
    scene.push_back( kp2[ good_matches[i].trainIdx ].pt );
}

Mat H = findHomography( obj, scene, CV_RANSAC );

在病房之后,一些人告诉我要包括以下代码

代码语言:javascript
复制
cv::Mat result;

warpPerspective( img1, result, H, cv::Size( img1.cols+img2.cols, img1.rows) );
cv::Mat half(result, cv::Rect(0, 0, img2.cols, img2.rows) );
img2.copyTo(half);
imshow("result",result);

我得到的结果是

我还尝试使用内置的opencv缝纫功能。我得到了结果

我试图实现缝纫功能,所以我不想使用内置的opencv缝纫功能。有人能告诉我我哪里出了问题并提前纠正我的code.Thanks吗?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2017-07-15 06:12:35

图像拼接包括以下步骤:

  1. 特征查找
  2. 寻找摄像机参数
  3. 翘曲
  4. 曝光补偿
  5. 煤层发现
  6. 混合

为了得到完美的结果,你必须做所有这些步骤。在您的代码中,您只完成了第一部分,即功能查找。

您可以找到关于图像拼接在学习OpenCV中如何工作的详细说明。

此外,我还有Github上的代码

希望这能有所帮助。

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/45114967

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档