引入极线约束的surf特征匹配

#include <stdio.h>
#include "opencv2/core/core.hpp"
#include "opencv2/features2d/features2d.hpp"
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/nonfree/nonfree.hpp"
#include <opencv2/calib3d/calib3d.hpp>
#include <iostream>
using namespace std;

using namespace cv;

static void help()
{
    printf("\nThis program demonstrates using features2d detector, descriptor extractor and simple matcher\n"
            "Using the SURF desriptor:\n"
            "\n"
            "Usage:\n matcher_simple <image1> <image2>\n");
}

int main(int argc, char** argv)
{
    //if(argc != 3)
    //{
    //    help();
    //    return -1;
    //}

    Mat img1 = imread("D:\\faceData\\stereopairs\\cones\\imL.jpg", CV_LOAD_IMAGE_GRAYSCALE);
    Mat img2 = imread("D:\\faceData\\stereopairs\\cones\\imR.jpg", CV_LOAD_IMAGE_GRAYSCALE);
    if(img1.empty() 
  • 0
    点赞
  • 13
    收藏
    觉得还不错? 一键收藏
  • 4
    评论
极线约束立体匹配中的SAD(Sum of Absolute Differences)是一种常用的代价度量方法。它用于计算每个像素点在极线上与对应像素点的灰度值之间的差异,并将这些差异累加起来作为代价值。SAD的计算公式如下: ```python SAD = sum(abs(left_pixel - right_pixel)) ``` 其中,`left_pixel`表示左图像上的像素值,`right_pixel`表示右图像上的对应像素值。通过计算SAD,我们可以得到每个像素点在极线上与对应像素点的差异程度,从而进行立体匹配。 下面是一个示例代码,演示了如何使用SAD进行极线约束立体匹配: ```python import numpy as np def stereo_matching(left_image, right_image, window_size, disparity_range): height, width = left_image.shape disparity_map = np.zeros_like(left_image) half_window = window_size // 2 for y in range(half_window, height - half_window): for x in range(half_window, width - half_window): best_disparity = 0 min_sad = float('inf') for d in range(disparity_range): sad = 0 for i in range(-half_window, half_window + 1): for j in range(-half_window, half_window + 1): left_pixel = left_image[y + i, x + j] right_pixel = right_image[y + i, x + j - d] sad += abs(left_pixel - right_pixel) if sad < min_sad: min_sad = sad best_disparity = d disparity_map[y, x] = best_disparity return disparity_map # 示例用法 left_image = np.array([[1, 2, 3], [4, 5, 6], [7, 8, 9]]) right_image = np.array([[1, 2, 4], [4, 5, 7], [7, 8, 10]]) window_size = 3 disparity_range = 5 disparity_map = stereo_matching(left_image, right_image, window_size, disparity_range) print(disparity_map) ``` 这段代码演示了一个简单的立体匹配过程,其中左图像和右图像分别用`left_image`和`right_image`表示,窗口大小为`window_size`,视差范围为`disparity_range`。最终输出的`disparity_map`是一个视差图,表示每个像素点的视差值。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值