SAD算法在opencv上的实现代码(c++)
#include <opencv2/opencv.hpp>
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <iostream>
using namespace std;
using namespace cv;
const int w = 384;
const int h = 288;
const int n = 3;
void SAD(uchar* Limg,
uchar* Rimg,
uchar* Oimg)
{
for (int y = 0; y< h; y++)
{
for (int x = 0; x< w; x++){
unsigned int bestCost = 999999;
unsigned int bestDisparity = 0;
for (int d = 0; d <= w-x-5; d++)
{
unsigned int cost = 0;
for (int i = -n; i <= n; i++)
{
for (int j = -n; j <= n; j++)
{
int yy, xx, xxd;
yy = y + i;
if (yy < 0) yy = 0;
if (yy >= h) yy = h;
xx = x + j;
if (xx < 0) xx = 0;
if (xx >= w) xx = w;
xxd = xx - d;
if (xxd < 0) xxd = 0;
if (xxd >= w) xxd = w;
cost += abs((int)(Limg[yy*w + xx] - Rimg[yy*w + xxd]));
}
}
if (cost < bestCost)
{
bestCost = cost;
bestDisparity = d*d;
}
Oimg[y*w + x] = bestDisparity;
}
}
}
}
int main()
{
Mat imL, imR, imO;
imL = imread("C:\\Users\\Administrator\\Desktop\\im2.png", 0);
if (imL.empty())
{
return -1;
}
imR = imread("C:\\Users\\Administrator\\Desktop\\im6.png", 0);
if (imR.empty())
{
return -1;
}
imO.create(imL.rows, imL.cols, imL.type());
SAD(imL.data, imR.data, imO.data);
namedWindow("left", WINDOW_AUTOSIZE);
namedWindow("right", WINDOW_AUTOSIZE);
namedWindow("Output", WINDOW_AUTOSIZE);
imshow("Output", imO);
imshow("left", imL);
imshow("right", imR);
waitKey(0);
return 0;
}

SAD算法在opencv上的实现代码(c++)的更多相关文章
- (转载)利用SIFT和RANSAC算法(openCV框架)实现物体的检测与定位,并求出变换矩阵(findFundamentalMat和findHomography的比较) 置顶
原文链接:https://blog.csdn.net/qq_25352981/article/details/46914837#commentsedit 本文目标是通过使用SIFT和RANSAC算法, ...
- [转]Android通过NDK调用JNI,使用opencv做本地c++代码开发配置方法
原文地址:http://blog.csdn.net/watkinsong/article/details/9849973 有一种方式不需要自己配置所有的Sun JDK, Android SDK以及ND ...
- C++算法之大数加法计算的代码
如下代码段是关于C++算法之大数加法计算的代码,希望对大家有用. { int length; int index; int smaller; int prefix = 0; if(NULL == sr ...
- Android(安卓)开发通过NDK调用JNI,使用opencv做本地c++代码开发配置方法 边缘检测 范例代码
以前写过两个Android开发配置文档,使用NDK进行JNI开发,这样能够利用以前已经写好的C++代码. 前两篇博客地址: http://blog.csdn.net/watkinsong/articl ...
- 基本算法思想Java实现的详细代码
基本算法思想Java实现的详细代码 算法是一个程序的灵魂,一个好的算法往往可以化繁为简,高效的求解问题.在程序设计中算法是独立于语言的,无论使用哪一种语言都可以使用这些算法,本文笔者将以Java语言为 ...
- 在Eclipse上使用egit插件通过ssh协议方式上传项目代码的具体步骤
在Eclipse上使用egit插件通过ssh协议方式上传项目代码 前戏: 使用ssh方式可以不通过https协议,避免直接提供账号密码的方式上传项目到git在线服务器,如Bitbucket.GitHu ...
- 基于dsp_builder的算法在FPGA上的实现
基于dsp_builder的算法在FPGA上的实现 一.摘要 结合dsp_builder.matlab.modelsim和quartus ii等软件完成算法的FPGA实现. 二.实验平台 硬件平台 ...
- 【优化算法】Greedy Randomized Adaptive Search算法 超详细解析,附代码实现TSP问题求解
01 概述 Greedy Randomized Adaptive Search,贪婪随机自适应搜索(GRAS),是组合优化问题中的多起点元启发式算法,在算法的每次迭代中,主要由两个阶段组成:构造(co ...
- 清晰化算法在DSP上的实现
清晰化算法在DSP TIDM642上的实现,之前的部分工作摘要于此. 1 DSP平台的选择 1.1 DM642 Evolution Module 选择现有的DM642 Evolution Module ...
随机推荐
- 如何在elasticsearch中查看Logstash打到elasticsearch的数据
# cat syslog02.conf #filename:syslog02.conf #注意这个是要用#号注释掉 input{ file{ path => ["/var/log/*. ...
- Jquery.Datatables 基本设置的中文注解
$(document).ready(function() { $('#example').dataTable({ "sScrollX": "100%", //表 ...
- 23.备忘录模式(Memento Pattern)
using System; using System.Collections.Generic; namespace ConsoleApplication6 { /// <summary> ...
- Faster-rnnlm代码分析2 - HSTree的构造
也就是构造一棵Huffman Tree,输入是按照词汇频次由高到低排序的 采用层次SoftMax的做法,是为了使得训练和预测时候的softmax输出加速,原有multinomal softmax,是和 ...
- android 屏幕旋转
转自:http://blog.csdn.net/oyzhizhong/article/details/8131799 屏是LANDSCAPE的,要让它默认显示为PORTRAIT. 1.kernel里要 ...
- test1.A[【dfs简单题】
Test1.A Time Limit: 1000ms Memory limit: 65536K 有疑问?点这里^_^ 题目描述 sdut 2274:http://acm.sdut.edu.cn/ ...
- Localstorage本地存储兼容函数
前言HTML5提供了本地存储的API:localstorage对象和sessionStorage对象,实现将数据存储到用户的电脑上.Web存储易于使用.支持大容量(但非无限量)数据同时存储,同时兼容当 ...
- [Linux] yum和apt-get用法及区别
一般来说著名的linux系统基本上分两大类: 1.RedHat系列:Redhat.Centos.Fedora等 2.Debian系列:Debian.Ubuntu等 RedHat 系列 1 常见的安装包 ...
- 解决全局变量共享---C语言的extern关键字用法
在调试程序时,有一个参数需要在多个函数之间传递,因为是作为调试参数,不想将参数引入到函数中. 很自然的想到使用全局变量来表示这个公共参数,工程代码的结构如下: main.c test.c test.h ...
- loj 1316(spfa预处理+状压dp)
题目链接:http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=27024 题意:求0-(n-1)的经过最多的标记的点的最短路. 思路 ...