使用openCV基于Hough Lines对齐2个图像

时间:2017-02-10 15:30:13

标签: image opencv image-processing opencv3.0 hough-transform

我有两个(空中)图像,从稍微不同的角度拍摄:

图片1: enter image description here

IMAGE2: enter image description here

我需要在水平方向上重新缩放image1以使其与image2对齐。没有任何修改,两个彼此相邻的图像看起来像这样:

enter image description here

这是理想的结果:(用photoshop制作) enter image description here

在Photoshop中,我拍摄了image1的右半部分并将其水平缩小了一点。我对image1的左半部分做了同样的事情,我不得不稍微扩展一下。

我想知道如何使用openCV完成此操作 - 使用Hough Line Transform。我已经开始绘制霍夫线,但我不知道如何进行变换以使霍夫线匹配:

enter image description here

这是我的C ++代码(从objective-c调用):

cv::Mat image1 = [im1 CVMat3];
cv::Mat gray_image1;
// Convert to Grayscale
cvtColor( image1, gray_image1, CV_RGB2GRAY );

cv::Mat dst1, cdst;
Canny(image1, dst1, 40, 90, 3);

double minLineLength = 0;
double maxLineGap = 10;

std::vector<cv::Vec2f> lines;
// detect lines
cv::HoughLines(dst1, lines, 1, CV_PI/180, 90, minLineLength,maxLineGap );


for( size_t i = 0; i < lines.size(); i++ ) {
    float rho = lines[i][0], theta = lines[i][1];
    if( theta>CV_PI/180*70 && theta<CV_PI/180*110) {

        cv::Point pt1, pt2;
        double a = cos(theta), b = sin(theta);
        double x0 = a*rho, y0 = b*rho;
        pt1.x = cvRound(x0 + 1000*(-b));
        pt1.y = cvRound(y0 + 1000*(a));
        pt2.x = cvRound(x0 - 1000*(-b));
        pt2.y = cvRound(y0 - 1000*(a));

        line( image1, pt1, pt2, cvScalar(10,100,255), 3, CV_AA);
    }
}

一些帮助将非常感激:-)。提前谢谢。

0 个答案:

没有答案