mirror of https://github.com/opencv/opencv.git
fix the channel 3 bug in matrix operation perf and buf fix for LUT haardetect convertC3C4 resize warpaffine copytom settom add convovle remove stereopull/31/head
parent
e94cd1ec72
commit
23244a3565
50 changed files with 2092 additions and 5389 deletions
@ -0,0 +1,167 @@ |
||||
/*M///////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
|
||||
//
|
||||
// By downloading, copying, installing or using the software you agree to this license.
|
||||
// If you do not agree to this license, do not download, install,
|
||||
// copy or use the software.
|
||||
//
|
||||
//
|
||||
// License Agreement
|
||||
// For Open Source Computer Vision Library
|
||||
//
|
||||
// Copyright (C) 2010-2012, Multicoreware, Inc., all rights reserved.
|
||||
// Copyright (C) 2010-2012, Advanced Micro Devices, Inc., all rights reserved.
|
||||
// Third party copyrights are property of their respective owners.
|
||||
//
|
||||
// @Authors
|
||||
// Peng Xiao, pengxiao@multicorewareinc.com
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
// are permitted provided that the following conditions are met:
|
||||
//
|
||||
// * Redistribution's of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
//
|
||||
// * Redistribution's in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other oclMaterials provided with the distribution.
|
||||
//
|
||||
// * The name of the copyright holders may not be used to endorse or promote products
|
||||
// derived from this software without specific prior written permission.
|
||||
//
|
||||
// This software is provided by the copyright holders and contributors as is and
|
||||
// any express or implied warranties, including, but not limited to, the implied
|
||||
// warranties of merchantability and fitness for a particular purpose are disclaimed.
|
||||
// In no event shall the Intel Corporation or contributors be liable for any direct,
|
||||
// indirect, incidental, special, exemplary, or consequential damages
|
||||
// (including, but not limited to, procurement of substitute goods or services;
|
||||
// loss of use, data, or profits; or business interruption) however caused
|
||||
// and on any theory of liability, whether in contract, strict liability,
|
||||
// or tort (including negligence or otherwise) arising in any way out of
|
||||
// the use of this software, even if advised of the possibility of such damage.
|
||||
//
|
||||
//M*/
|
||||
|
||||
#include "precomp.hpp" |
||||
#include <iomanip> |
||||
|
||||
#ifdef HAVE_OPENCL |
||||
|
||||
using namespace cv; |
||||
using namespace cv::ocl; |
||||
using namespace cvtest; |
||||
using namespace testing; |
||||
using namespace std; |
||||
|
||||
#define FILTER_IMAGE "../../../samples/gpu/road.png" |
||||
|
||||
#ifndef MWC_TEST_UTILITY |
||||
#define MWC_TEST_UTILITY |
||||
|
||||
// Param class
|
||||
#ifndef IMPLEMENT_PARAM_CLASS |
||||
#define IMPLEMENT_PARAM_CLASS(name, type) \ |
||||
class name \
|
||||
{ \
|
||||
public: \
|
||||
name ( type arg = type ()) : val_(arg) {} \
|
||||
operator type () const {return val_;} \
|
||||
private: \
|
||||
type val_; \
|
||||
}; \
|
||||
inline void PrintTo( name param, std::ostream* os) \
|
||||
{ \
|
||||
*os << #name << "(" << testing::PrintToString(static_cast< type >(param)) << ")"; \
|
||||
} |
||||
|
||||
#endif // IMPLEMENT_PARAM_CLASS
|
||||
#endif // MWC_TEST_UTILITY
|
||||
|
||||
IMPLEMENT_PARAM_CLASS(WinSizw48, bool); |
||||
|
||||
PARAM_TEST_CASE(HOG, WinSizw48, bool) |
||||
{ |
||||
bool is48; |
||||
vector<float> detector; |
||||
virtual void SetUp() |
||||
{ |
||||
is48 = GET_PARAM(0); |
||||
if(is48) |
||||
{ |
||||
detector = cv::ocl::HOGDescriptor::getPeopleDetector48x96(); |
||||
} |
||||
else |
||||
{ |
||||
detector = cv::ocl::HOGDescriptor::getPeopleDetector64x128(); |
||||
} |
||||
} |
||||
}; |
||||
|
||||
TEST_P(HOG, Performance) |
||||
{ |
||||
cv::Mat img = readImage(FILTER_IMAGE,cv::IMREAD_GRAYSCALE); |
||||
ASSERT_FALSE(img.empty()); |
||||
|
||||
// define HOG related arguments
|
||||
float scale = 1.05; |
||||
int nlevels = 13; |
||||
float gr_threshold = 8; |
||||
float hit_threshold = 1.4; |
||||
bool hit_threshold_auto = true; |
||||
|
||||
int win_width = is48? 48 : 64; |
||||
int win_stride_width = 8; |
||||
int win_stride_height = 8; |
||||
|
||||
bool gamma_corr = true; |
||||
|
||||
Size win_size(win_width, win_width * 2); //(64, 128) or (48, 96)
|
||||
Size win_stride(win_stride_width, win_stride_height); |
||||
|
||||
cv::ocl::HOGDescriptor gpu_hog(win_size, Size(16, 16), Size(8, 8), Size(8, 8), 9, |
||||
cv::ocl::HOGDescriptor::DEFAULT_WIN_SIGMA, 0.2, gamma_corr, |
||||
cv::ocl::HOGDescriptor::DEFAULT_NLEVELS); |
||||
|
||||
gpu_hog.setSVMDetector(detector); |
||||
|
||||
double totalgputick=0; |
||||
double totalgputick_kernel=0; |
||||
|
||||
double t1=0; |
||||
double t2=0; |
||||
for(int j = 0; j < LOOP_TIMES+1; j ++) |
||||
{ |
||||
t1 = (double)cvGetTickCount();//gpu start1
|
||||
|
||||
ocl::oclMat d_src(img);//upload
|
||||
|
||||
t2=(double)cvGetTickCount();//kernel
|
||||
|
||||
vector<Rect> found; |
||||
gpu_hog.detectMultiScale(d_src, found, hit_threshold, win_stride, |
||||
Size(0, 0), scale, gr_threshold); |
||||
|
||||
t2 = (double)cvGetTickCount() - t2;//kernel
|
||||
|
||||
// no download time for HOG
|
||||
|
||||
t1 = (double)cvGetTickCount() - t1;//gpu end1
|
||||
|
||||
if(j == 0) |
||||
continue; |
||||
|
||||
totalgputick=t1+totalgputick; |
||||
|
||||
totalgputick_kernel=t2+totalgputick_kernel;
|
||||
|
||||
} |
||||
|
||||
cout << "average gpu runtime is " << totalgputick/((double)cvGetTickFrequency()* LOOP_TIMES *1000.) << "ms" << endl; |
||||
cout << "average gpu runtime without data transfer is " << totalgputick_kernel/((double)cvGetTickFrequency()* LOOP_TIMES *1000.) << "ms" << endl; |
||||
} |
||||
|
||||
|
||||
INSTANTIATE_TEST_CASE_P(GPU_ObjDetect, HOG, testing::Combine(testing::Values(WinSizw48(false), WinSizw48(true)), testing::Values(false))); |
||||
|
||||
#endif //Have opencl
|
@ -0,0 +1,103 @@ |
||||
/*M///////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
|
||||
//
|
||||
// By downloading, copying, installing or using the software you agree to this license.
|
||||
// If you do not agree to this license, do not download, install,
|
||||
// copy or use the software.
|
||||
//
|
||||
//
|
||||
// License Agreement
|
||||
// For Open Source Computer Vision Library
|
||||
//
|
||||
// Copyright (C) 2010-2012, Multicoreware, Inc., all rights reserved.
|
||||
// Copyright (C) 2010-2012, Advanced Micro Devices, Inc., all rights reserved.
|
||||
// Third party copyrights are property of their respective owners.
|
||||
//
|
||||
// @Authors
|
||||
// Peng Xiao, pengxiao@multicorewareinc.com
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
// are permitted provided that the following conditions are met:
|
||||
//
|
||||
// * Redistribution's of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
//
|
||||
// * Redistribution's in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other oclMaterials provided with the distribution.
|
||||
//
|
||||
// * The name of the copyright holders may not be used to endorse or promote products
|
||||
// derived from this software without specific prior written permission.
|
||||
//
|
||||
// This software is provided by the copyright holders and contributors as is and
|
||||
// any express or implied warranties, including, but not limited to, the implied
|
||||
// warranties of merchantability and fitness for a particular purpose are disclaimed.
|
||||
// In no event shall the Intel Corporation or contributors be liable for any direct,
|
||||
// indirect, incidental, special, exemplary, or consequential damages
|
||||
// (including, but not limited to, procurement of substitute goods or services;
|
||||
// loss of use, data, or profits; or business interruption) however caused
|
||||
// and on any theory of liability, whether in contract, strict liability,
|
||||
// or tort (including negligence or otherwise) arising in any way out of
|
||||
// the use of this software, even if advised of the possibility of such damage.
|
||||
//
|
||||
//M*/
|
||||
|
||||
#include "precomp.hpp" |
||||
#include <iomanip> |
||||
|
||||
#ifdef HAVE_OPENCL |
||||
|
||||
using namespace cv; |
||||
using namespace cv::ocl; |
||||
using namespace cvtest; |
||||
using namespace testing; |
||||
using namespace std; |
||||
|
||||
#define FILTER_IMAGE "../../../samples/gpu/road.png" |
||||
|
||||
TEST(SURF, Performance) |
||||
{ |
||||
cv::Mat img = readImage(FILTER_IMAGE,cv::IMREAD_GRAYSCALE); |
||||
ASSERT_FALSE(img.empty()); |
||||
|
||||
ocl::SURF_OCL d_surf; |
||||
ocl::oclMat d_keypoints; |
||||
ocl::oclMat d_descriptors; |
||||
|
||||
double totalgputick=0; |
||||
double totalgputick_kernel=0; |
||||
|
||||
double t1=0; |
||||
double t2=0; |
||||
for(int j = 0; j < LOOP_TIMES+1; j ++) |
||||
{ |
||||
t1 = (double)cvGetTickCount();//gpu start1
|
||||
|
||||
ocl::oclMat d_src(img);//upload
|
||||
|
||||
t2=(double)cvGetTickCount();//kernel
|
||||
d_surf(d_src, ocl::oclMat(), d_keypoints, d_descriptors); |
||||
t2 = (double)cvGetTickCount() - t2;//kernel
|
||||
|
||||
cv::Mat cpu_kp, cpu_dp; |
||||
d_keypoints.download (cpu_kp);//download
|
||||
d_descriptors.download (cpu_dp);//download
|
||||
|
||||
t1 = (double)cvGetTickCount() - t1;//gpu end1
|
||||
|
||||
if(j == 0) |
||||
continue; |
||||
|
||||
totalgputick=t1+totalgputick; |
||||
|
||||
totalgputick_kernel=t2+totalgputick_kernel;
|
||||
|
||||
} |
||||
|
||||
cout << "average gpu runtime is " << totalgputick/((double)cvGetTickFrequency()* LOOP_TIMES *1000.) << "ms" << endl; |
||||
cout << "average gpu runtime without data transfer is " << totalgputick_kernel/((double)cvGetTickFrequency()* LOOP_TIMES *1000.) << "ms" << endl; |
||||
|
||||
|
||||
} |
||||
#endif //Have opencl
|
@ -1,218 +0,0 @@ |
||||
/*M///////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
|
||||
//
|
||||
// By downloading, copying, installing or using the software you agree to this license.
|
||||
// If you do not agree to this license, do not download, install,
|
||||
// copy or use the software.
|
||||
//
|
||||
//
|
||||
// Intel License Agreement
|
||||
// For Open Source Computer Vision Library
|
||||
//
|
||||
// Copyright (C) 2010-2012, Multicoreware, Inc., all rights reserved.
|
||||
// Copyright (C) 2010-2012, Advanced Micro Devices, Inc., all rights reserved.
|
||||
// Third party copyrights are property of their respective owners.
|
||||
//
|
||||
// @Authors
|
||||
// Fangfang BAI, fangfang@multicorewareinc.com
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
// are permitted provided that the following conditions are met:
|
||||
//
|
||||
// * Redistribution's of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
//
|
||||
// * Redistribution's in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
//
|
||||
// * The name of Intel Corporation may not be used to endorse or promote products
|
||||
// derived from this software without specific prior written permission.
|
||||
//
|
||||
// This software is provided by the copyright holders and contributors "as is" and
|
||||
// any express or implied warranties, including, but not limited to, the implied
|
||||
// warranties of merchantability and fitness for a particular purpose are disclaimed.
|
||||
// In no event shall the Intel Corporation or contributors be liable for any direct,
|
||||
// indirect, incidental, special, exemplary, or consequential damages
|
||||
// (including, but not limited to, procurement of substitute goods or services;
|
||||
// loss of use, data, or profits; or business interruption) however caused
|
||||
// and on any theory of liability, whether in contract, strict liability,
|
||||
// or tort (including negligence or otherwise) arising in any way out of
|
||||
// the use of this software, even if advised of the possibility of such damage.
|
||||
//
|
||||
//M*/
|
||||
|
||||
#include "precomp.hpp" |
||||
#include "opencv2/core/core.hpp" |
||||
#include <iomanip> |
||||
using namespace std; |
||||
|
||||
|
||||
|
||||
#ifdef HAVE_OPENCL |
||||
|
||||
|
||||
PARAM_TEST_CASE(HOG,cv::Size,int) |
||||
{ |
||||
cv::Size winSize; |
||||
int type; |
||||
std::vector<cv::ocl::Info> oclinfo; |
||||
|
||||
virtual void SetUp() |
||||
{ |
||||
winSize = GET_PARAM(0); |
||||
type = GET_PARAM(1); |
||||
int devnums = getDevice(oclinfo); |
||||
CV_Assert(devnums > 0); |
||||
} |
||||
}; |
||||
|
||||
TEST_P(HOG, GetDescriptors) |
||||
{ |
||||
// Load image
|
||||
cv::Mat img_rgb = readImage("D:road.png"); |
||||
ASSERT_FALSE(img_rgb.empty()); |
||||
|
||||
// Convert image
|
||||
cv::Mat img; |
||||
switch (type) |
||||
{ |
||||
case CV_8UC1: |
||||
cv::cvtColor(img_rgb, img, CV_BGR2GRAY); |
||||
break; |
||||
case CV_8UC4: |
||||
default: |
||||
cv::cvtColor(img_rgb, img, CV_BGR2BGRA); |
||||
break; |
||||
} |
||||
// HOGs
|
||||
cv::ocl::HOGDescriptor ocl_hog; |
||||
ocl_hog.gamma_correction = true; |
||||
|
||||
|
||||
// Compute descriptor
|
||||
cv::ocl::oclMat d_descriptors; |
||||
//down_descriptors = down_descriptors.reshape(0, down_descriptors.cols * down_descriptors.rows);
|
||||
|
||||
double totalgputick=0; |
||||
double totalgputick_kernel=0; |
||||
double t1=0; |
||||
double t2=0; |
||||
|
||||
for(int j = 0; j < LOOP_TIMES+1; j ++) |
||||
{ |
||||
|
||||
t1 = (double)cvGetTickCount();//gpu start1
|
||||
|
||||
cv::ocl::oclMat d_img=cv::ocl::oclMat(img);//upload
|
||||
|
||||
t2=(double)cvGetTickCount();//kernel
|
||||
ocl_hog.getDescriptors(d_img, ocl_hog.win_size, d_descriptors, ocl_hog.DESCR_FORMAT_COL_BY_COL); |
||||
t2 = (double)cvGetTickCount() - t2;//kernel
|
||||
|
||||
cv::Mat down_descriptors; |
||||
d_descriptors.download(down_descriptors); |
||||
|
||||
t1 = (double)cvGetTickCount() - t1;//gpu end1
|
||||
|
||||
if(j == 0) |
||||
continue; |
||||
|
||||
totalgputick=t1+totalgputick; |
||||
totalgputick_kernel=t2+totalgputick_kernel;
|
||||
|
||||
} |
||||
|
||||
cout << "average gpu runtime is " << totalgputick/((double)cvGetTickFrequency()* LOOP_TIMES *1000.) << "ms" << endl; |
||||
cout << "average gpu runtime without data transfer is " << totalgputick_kernel/((double)cvGetTickFrequency()* LOOP_TIMES *1000.) << "ms" << endl; |
||||
|
||||
|
||||
} |
||||
|
||||
|
||||
TEST_P(HOG, Detect) |
||||
{ |
||||
// Load image
|
||||
cv::Mat img_rgb = readImage("D:road.png"); |
||||
ASSERT_FALSE(img_rgb.empty()); |
||||
|
||||
// Convert image
|
||||
cv::Mat img; |
||||
switch (type) |
||||
{ |
||||
case CV_8UC1: |
||||
cv::cvtColor(img_rgb, img, CV_BGR2GRAY); |
||||
break; |
||||
case CV_8UC4: |
||||
default: |
||||
cv::cvtColor(img_rgb, img, CV_BGR2BGRA); |
||||
break; |
||||
} |
||||
|
||||
// HOGs
|
||||
if ((winSize != cv::Size(48, 96)) && (winSize != cv::Size(64, 128))) |
||||
winSize = cv::Size(64, 128); |
||||
cv::ocl::HOGDescriptor ocl_hog(winSize); |
||||
ocl_hog.gamma_correction = true; |
||||
|
||||
cv::HOGDescriptor hog; |
||||
hog.winSize = winSize; |
||||
hog.gammaCorrection = true; |
||||
|
||||
if (winSize.width == 48 && winSize.height == 96) |
||||
{ |
||||
// daimler's base
|
||||
ocl_hog.setSVMDetector(ocl_hog.getPeopleDetector48x96()); |
||||
hog.setSVMDetector(hog.getDaimlerPeopleDetector()); |
||||
} |
||||
else if (winSize.width == 64 && winSize.height == 128) |
||||
{ |
||||
ocl_hog.setSVMDetector(ocl_hog.getPeopleDetector64x128()); |
||||
hog.setSVMDetector(hog.getDefaultPeopleDetector()); |
||||
} |
||||
else |
||||
{ |
||||
ocl_hog.setSVMDetector(ocl_hog.getDefaultPeopleDetector()); |
||||
hog.setSVMDetector(hog.getDefaultPeopleDetector()); |
||||
} |
||||
|
||||
// OpenCL detection
|
||||
std::vector<cv::Point> d_v_locations; |
||||
|
||||
double totalgputick=0; |
||||
double totalgputick_kernel=0; |
||||
double t1=0; |
||||
double t2=0; |
||||
|
||||
for(int j = 0; j < LOOP_TIMES+1; j ++) |
||||
{ |
||||
|
||||
t1 = (double)cvGetTickCount();//gpu start1
|
||||
|
||||
cv::ocl::oclMat d_img=cv::ocl::oclMat(img);//upload
|
||||
|
||||
t2=(double)cvGetTickCount();//kernel
|
||||
ocl_hog.detect(d_img, d_v_locations, 0); |
||||
t2 = (double)cvGetTickCount() - t2;//kernel
|
||||
|
||||
t1 = (double)cvGetTickCount() - t1;//gpu end1
|
||||
if(j == 0) |
||||
continue; |
||||
totalgputick=t1+totalgputick; |
||||
totalgputick_kernel=t2+totalgputick_kernel;
|
||||
|
||||
} |
||||
|
||||
cout << "average gpu runtime is " << totalgputick/((double)cvGetTickFrequency()* LOOP_TIMES *1000.) << "ms" << endl; |
||||
cout << "average gpu runtime without data transfer is " << totalgputick_kernel/((double)cvGetTickFrequency()* LOOP_TIMES *1000.) << "ms" << endl; |
||||
|
||||
} |
||||
|
||||
|
||||
INSTANTIATE_TEST_CASE_P(OCL_ObjDetect, HOG, testing::Combine( |
||||
testing::Values(cv::Size(64, 128), cv::Size(48, 96)), |
||||
testing::Values(MatType(CV_8UC1), MatType(CV_8UC4)))); |
||||
|
||||
|
||||
#endif //HAVE_OPENCL
|
@ -0,0 +1,111 @@ |
||||
/*M/////////////////////////////////////////////////////////////////////////////////////// |
||||
// |
||||
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. |
||||
// |
||||
// By downloading, copying, installing or using the software you agree to this license. |
||||
// If you do not agree to this license, do not download, install, |
||||
// copy or use the software. |
||||
// |
||||
// |
||||
// License Agreement |
||||
// For Open Source Computer Vision Library |
||||
// |
||||
// Copyright (C) 2010-2012, Institute Of Software Chinese Academy Of Science, all rights reserved. |
||||
// Copyright (C) 2010-2012, Advanced Micro Devices, Inc., all rights reserved. |
||||
// Third party copyrights are property of their respective owners. |
||||
// |
||||
// @Authors |
||||
// Jiang Liyuan, jlyuan001.good@163.com |
||||
// |
||||
// Redistribution and use in source and binary forms, with or without modification, |
||||
// are permitted provided that the following conditions are met: |
||||
// |
||||
// * Redistribution's of source code must retain the above copyright notice, |
||||
// this list of conditions and the following disclaimer. |
||||
// |
||||
// * Redistribution's in binary form must reproduce the above copyright notice, |
||||
// this list of conditions and the following disclaimer in the documentation |
||||
// and/or other oclMaterials provided with the distribution. |
||||
// |
||||
// * The name of the copyright holders may not be used to endorse or promote products |
||||
// derived from this software without specific prior written permission. |
||||
// |
||||
// This software is provided by the copyright holders and contributors as is and |
||||
// any express or implied warranties, including, but not limited to, the implied |
||||
// warranties of merchantability and fitness for a particular purpose are disclaimed. |
||||
// In no event shall the Intel Corporation or contributors be liable for any direct, |
||||
// indirect, incidental, special, exemplary, or consequential damages |
||||
// (including, but not limited to, procurement of substitute goods or services; |
||||
// loss of use, data, or profits; or business interruption) however caused |
||||
// and on any theory of liability, whether in contract, strict liability, |
||||
// or tort (including negligence or otherwise) arising in any way out of |
||||
// the use of this software, even if advised of the possibility of such damage. |
||||
// |
||||
//M*/ |
||||
|
||||
#if defined (__ATI__) |
||||
#pragma OPENCL EXTENSION cl_amd_fp64:enable |
||||
#elif defined (__NVIDIA__) |
||||
#pragma OPENCL EXTENSION cl_khr_fp64:enable |
||||
#endif |
||||
/************************************** convolve **************************************/ |
||||
__kernel void convolve_D5 (__global float *src, __global float *temp1, __global float *dst, |
||||
int rows, int cols, int src_step, int dst_step,int k_step, int kWidth, int kHeight) |
||||
{ |
||||
__local float smem[16 + 2 * 8][16 + 2 * 8]; |
||||
|
||||
int x = get_local_id(0); |
||||
int y = get_local_id(1); |
||||
int gx = get_global_id(0); |
||||
int gy = get_global_id(1); |
||||
|
||||
// x | x 0 | 0 |
||||
// ----------- |
||||
// x | x 0 | 0 |
||||
// 0 | 0 0 | 0 |
||||
// ----------- |
||||
// 0 | 0 0 | 0 |
||||
smem[y][x] = src[min(max(gy - 8, 0), rows - 1)*(src_step >> 2) + min(max(gx - 8, 0), cols - 1)]; |
||||
|
||||
// 0 | 0 x | x |
||||
// ----------- |
||||
// 0 | 0 x | x |
||||
// 0 | 0 0 | 0 |
||||
// ----------- |
||||
// 0 | 0 0 | 0 |
||||
smem[y][x + 16] = src[min(max(gy - 8, 0), rows - 1)*(src_step >> 2) + min(gx + 8, cols - 1)]; |
||||
|
||||
// 0 | 0 0 | 0 |
||||
// ----------- |
||||
// 0 | 0 0 | 0 |
||||
// x | x 0 | 0 |
||||
// ----------- |
||||
// x | x 0 | 0 |
||||
smem[y + 16][x] = src[min(gy + 8, rows - 1)*(src_step >> 2) + min(max(gx - 8, 0), cols - 1)]; |
||||
|
||||
// 0 | 0 0 | 0 |
||||
// ----------- |
||||
// 0 | 0 0 | 0 |
||||
// 0 | 0 x | x |
||||
// ----------- |
||||
// 0 | 0 x | x |
||||
smem[y + 16][x + 16] = src[min(gy + 8, rows - 1)*(src_step >> 2) + min(gx + 8, cols - 1)]; |
||||
|
||||
barrier(CLK_LOCAL_MEM_FENCE); |
||||
|
||||
if (gx < cols && gy < rows) |
||||
{ |
||||
float res = 0; |
||||
|
||||
for (int i = 0; i < kHeight; ++i) |
||||
{ |
||||
for (int j = 0; j < kWidth; ++j) |
||||
{ |
||||
res += smem[y + 8 - kHeight / 2 + i][x + 8 - kWidth / 2 + j] * temp1[i * (k_step>>2) + j]; |
||||
} |
||||
} |
||||
dst[gy*(dst_step >> 2)+gx] = res; |
||||
} |
||||
} |
||||
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -1,427 +0,0 @@ |
||||
/*M/////////////////////////////////////////////////////////////////////////////////////// |
||||
// |
||||
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. |
||||
// |
||||
// By downloading, copying, installing or using the software you agree to this license. |
||||
// If you do not agree to this license, do not download, install, |
||||
// copy or use the software. |
||||
// |
||||
// |
||||
// License Agreement |
||||
// For Open Source Computer Vision Library |
||||
// |
||||
// Copyright (C) 2010-2012, Institute Of Software Chinese Academy Of Science, all rights reserved. |
||||
// Copyright (C) 2010-2012, Advanced Micro Devices, Inc., all rights reserved. |
||||
// Third party copyrights are property of their respective owners. |
||||
// |
||||
// @Authors |
||||
// Jia Haipeng, jiahaipeng95@gmail.com |
||||
// |
||||
// Redistribution and use in source and binary forms, with or without modification, |
||||
// are permitted provided that the following conditions are met: |
||||
// |
||||
// * Redistribution's of source code must retain the above copyright notice, |
||||
// this list of conditions and the following disclaimer. |
||||
// |
||||
// * Redistribution's in binary form must reproduce the above copyright notice, |
||||
// this list of conditions and the following disclaimer in the documentation |
||||
// and/or other oclMaterials provided with the distribution. |
||||
// |
||||
// * The name of the copyright holders may not be used to endorse or promote products |
||||
// derived from this software without specific prior written permission. |
||||
// |
||||
// This software is provided by the copyright holders and contributors as is and |
||||
// any express or implied warranties, including, but not limited to, the implied |
||||
// warranties of merchantability and fitness for a particular purpose are disclaimed. |
||||
// In no event shall the Intel Corporation or contributors be liable for any direct, |
||||
// indirect, incidental, special, exemplary, or consequential damages |
||||
// (including, but not limited to, procurement of substitute goods or services; |
||||
// loss of use, data, or profits; or business interruption) however caused |
||||
// and on any theory of liability, whether in contract, strict liability, |
||||
// or tort (including negligence or otherwise) arising in any way out of |
||||
// the use of this software, even if advised of the possibility of such damage. |
||||
// |
||||
//M*/ |
||||
|
||||
#define ROWSperTHREAD 21 // the number of rows a thread will process |
||||
#define BLOCK_W 128 // the thread block width (464) |
||||
#define N_DISPARITIES 8 |
||||
|
||||
#define STEREO_MIND 0 // The minimum d range to check |
||||
#define STEREO_DISP_STEP N_DISPARITIES // the d step, must be <= 1 to avoid aliasing |
||||
|
||||
int SQ(int a) |
||||
{ |
||||
return a * a; |
||||
} |
||||
|
||||
unsigned int CalcSSD(volatile __local unsigned int *col_ssd_cache, |
||||
volatile __local unsigned int *col_ssd, int radius) |
||||
{ |
||||
unsigned int cache = 0; |
||||
unsigned int cache2 = 0; |
||||
|
||||
for(int i = 1; i <= radius; i++) |
||||
cache += col_ssd[i]; |
||||
|
||||
col_ssd_cache[0] = cache; |
||||
|
||||
barrier(CLK_LOCAL_MEM_FENCE); |
||||
|
||||
if (get_local_id(0) < BLOCK_W - radius) |
||||
cache2 = col_ssd_cache[radius]; |
||||
else |
||||
for(int i = radius + 1; i < (2 * radius + 1); i++) |
||||
cache2 += col_ssd[i]; |
||||
|
||||
return col_ssd[0] + cache + cache2; |
||||
} |
||||
|
||||
uint2 MinSSD(volatile __local unsigned int *col_ssd_cache, |
||||
volatile __local unsigned int *col_ssd, int radius) |
||||
{ |
||||
unsigned int ssd[N_DISPARITIES]; |
||||
|
||||
//See above: #define COL_SSD_SIZE (BLOCK_W + 2 * radius) |
||||
ssd[0] = CalcSSD(col_ssd_cache, col_ssd + 0 * (BLOCK_W + 2 * radius), radius); |
||||
barrier(CLK_LOCAL_MEM_FENCE); |
||||
ssd[1] = CalcSSD(col_ssd_cache, col_ssd + 1 * (BLOCK_W + 2 * radius), radius); |
||||
barrier(CLK_LOCAL_MEM_FENCE); |
||||
ssd[2] = CalcSSD(col_ssd_cache, col_ssd + 2 * (BLOCK_W + 2 * radius), radius); |
||||
barrier(CLK_LOCAL_MEM_FENCE); |
||||
ssd[3] = CalcSSD(col_ssd_cache, col_ssd + 3 * (BLOCK_W + 2 * radius), radius); |
||||
barrier(CLK_LOCAL_MEM_FENCE); |
||||
ssd[4] = CalcSSD(col_ssd_cache, col_ssd + 4 * (BLOCK_W + 2 * radius), radius); |
||||
barrier(CLK_LOCAL_MEM_FENCE); |
||||
ssd[5] = CalcSSD(col_ssd_cache, col_ssd + 5 * (BLOCK_W + 2 * radius), radius); |
||||
barrier(CLK_LOCAL_MEM_FENCE); |
||||
ssd[6] = CalcSSD(col_ssd_cache, col_ssd + 6 * (BLOCK_W + 2 * radius), radius); |
||||
barrier(CLK_LOCAL_MEM_FENCE); |
||||
ssd[7] = CalcSSD(col_ssd_cache, col_ssd + 7 * (BLOCK_W + 2 * radius), radius); |
||||
barrier(CLK_LOCAL_MEM_FENCE); |
||||
|
||||
unsigned int mssd = min(min(min(ssd[0], ssd[1]), min(ssd[4], ssd[5])), min(min(ssd[2], ssd[3]), min(ssd[6], ssd[7]))); |
||||
|
||||
int bestIdx = 0; |
||||
for (int i = 0; i < N_DISPARITIES; i++) |
||||
{ |
||||
if (mssd == ssd[i]) |
||||
bestIdx = i; |
||||
} |
||||
|
||||
return (uint2)(mssd, bestIdx); |
||||
} |
||||
|
||||
void StepDown(int idx1, int idx2, __global unsigned char* imageL, |
||||
__global unsigned char* imageR, int d, volatile __local unsigned int *col_ssd, int radius) |
||||
{ |
||||
unsigned char leftPixel1; |
||||
unsigned char leftPixel2; |
||||
unsigned char rightPixel1[8]; |
||||
unsigned char rightPixel2[8]; |
||||
unsigned int diff1, diff2; |
||||
|
||||
leftPixel1 = imageL[idx1]; |
||||
leftPixel2 = imageL[idx2]; |
||||
|
||||
idx1 = idx1 - d; |
||||
idx2 = idx2 - d; |
||||
|
||||
rightPixel1[7] = imageR[idx1 - 7]; |
||||
rightPixel1[0] = imageR[idx1 - 0]; |
||||
rightPixel1[1] = imageR[idx1 - 1]; |
||||
rightPixel1[2] = imageR[idx1 - 2]; |
||||
rightPixel1[3] = imageR[idx1 - 3]; |
||||
rightPixel1[4] = imageR[idx1 - 4]; |
||||
rightPixel1[5] = imageR[idx1 - 5]; |
||||
rightPixel1[6] = imageR[idx1 - 6]; |
||||
|
||||
rightPixel2[7] = imageR[idx2 - 7]; |
||||
rightPixel2[0] = imageR[idx2 - 0]; |
||||
rightPixel2[1] = imageR[idx2 - 1]; |
||||
rightPixel2[2] = imageR[idx2 - 2]; |
||||
rightPixel2[3] = imageR[idx2 - 3]; |
||||
rightPixel2[4] = imageR[idx2 - 4]; |
||||
rightPixel2[5] = imageR[idx2 - 5]; |
||||
rightPixel2[6] = imageR[idx2 - 6]; |
||||
|
||||
//See above: #define COL_SSD_SIZE (BLOCK_W + 2 * radius) |
||||
diff1 = leftPixel1 - rightPixel1[0]; |
||||
diff2 = leftPixel2 - rightPixel2[0]; |
||||
col_ssd[0 * (BLOCK_W + 2 * radius)] += SQ(diff2) - SQ(diff1); |
||||
|
||||
diff1 = leftPixel1 - rightPixel1[1]; |
||||
diff2 = leftPixel2 - rightPixel2[1]; |
||||
col_ssd[1 * (BLOCK_W + 2 * radius)] += SQ(diff2) - SQ(diff1); |
||||
|
||||
diff1 = leftPixel1 - rightPixel1[2]; |
||||
diff2 = leftPixel2 - rightPixel2[2]; |
||||
col_ssd[2 * (BLOCK_W + 2 * radius)] += SQ(diff2) - SQ(diff1); |
||||
|
||||
diff1 = leftPixel1 - rightPixel1[3]; |
||||
diff2 = leftPixel2 - rightPixel2[3]; |
||||
col_ssd[3 * (BLOCK_W + 2 * radius)] += SQ(diff2) - SQ(diff1); |
||||
|
||||
diff1 = leftPixel1 - rightPixel1[4]; |
||||
diff2 = leftPixel2 - rightPixel2[4]; |
||||
col_ssd[4 * (BLOCK_W + 2 * radius)] += SQ(diff2) - SQ(diff1); |
||||
|
||||
diff1 = leftPixel1 - rightPixel1[5]; |
||||
diff2 = leftPixel2 - rightPixel2[5]; |
||||
col_ssd[5 * (BLOCK_W + 2 * radius)] += SQ(diff2) - SQ(diff1); |
||||
|
||||
diff1 = leftPixel1 - rightPixel1[6]; |
||||
diff2 = leftPixel2 - rightPixel2[6]; |
||||
col_ssd[6 * (BLOCK_W + 2 * radius)] += SQ(diff2) - SQ(diff1); |
||||
|
||||
diff1 = leftPixel1 - rightPixel1[7]; |
||||
diff2 = leftPixel2 - rightPixel2[7]; |
||||
col_ssd[7 * (BLOCK_W + 2 * radius)] += SQ(diff2) - SQ(diff1); |
||||
} |
||||
|
||||
void InitColSSD(int x_tex, int y_tex, int im_pitch, __global unsigned char* imageL, |
||||
__global unsigned char* imageR, int d, |
||||
volatile __local unsigned int *col_ssd, int radius) |
||||
{ |
||||
unsigned char leftPixel1; |
||||
int idx; |
||||
unsigned int diffa[] = {0, 0, 0, 0, 0, 0, 0, 0}; |
||||
|
||||
for(int i = 0; i < (2 * radius + 1); i++) |
||||
{ |
||||
idx = y_tex * im_pitch + x_tex; |
||||
leftPixel1 = imageL[idx]; |
||||
idx = idx - d; |
||||
|
||||
diffa[0] += SQ(leftPixel1 - imageR[idx - 0]); |
||||
diffa[1] += SQ(leftPixel1 - imageR[idx - 1]); |
||||
diffa[2] += SQ(leftPixel1 - imageR[idx - 2]); |
||||
diffa[3] += SQ(leftPixel1 - imageR[idx - 3]); |
||||
diffa[4] += SQ(leftPixel1 - imageR[idx - 4]); |
||||
diffa[5] += SQ(leftPixel1 - imageR[idx - 5]); |
||||
diffa[6] += SQ(leftPixel1 - imageR[idx - 6]); |
||||
diffa[7] += SQ(leftPixel1 - imageR[idx - 7]); |
||||
|
||||
y_tex += 1; |
||||
} |
||||
//See above: #define COL_SSD_SIZE (BLOCK_W + 2 * radius) |
||||
col_ssd[0 * (BLOCK_W + 2 * radius)] = diffa[0]; |
||||
col_ssd[1 * (BLOCK_W + 2 * radius)] = diffa[1]; |
||||
col_ssd[2 * (BLOCK_W + 2 * radius)] = diffa[2]; |
||||
col_ssd[3 * (BLOCK_W + 2 * radius)] = diffa[3]; |
||||
col_ssd[4 * (BLOCK_W + 2 * radius)] = diffa[4]; |
||||
col_ssd[5 * (BLOCK_W + 2 * radius)] = diffa[5]; |
||||
col_ssd[6 * (BLOCK_W + 2 * radius)] = diffa[6]; |
||||
col_ssd[7 * (BLOCK_W + 2 * radius)] = diffa[7]; |
||||
} |
||||
|
||||
__kernel void stereoKernel(__global unsigned char *left, __global unsigned char *right, |
||||
__global unsigned int *cminSSDImage, int cminSSD_step, |
||||
__global unsigned char *disp, int disp_step,int cwidth, int cheight, |
||||
int img_step, int maxdisp, int radius, |
||||
__local unsigned int *col_ssd_cache) |
||||
{ |
||||
|
||||
volatile __local unsigned int *col_ssd = col_ssd_cache + BLOCK_W + get_local_id(0); |
||||
volatile __local unsigned int *col_ssd_extra = get_local_id(0) < (2 * radius) ? col_ssd + BLOCK_W : 0; |
||||
|
||||
int X = get_group_id(0) * BLOCK_W + get_local_id(0) + maxdisp + radius; |
||||
// int Y = get_group_id(1) * ROWSperTHREAD + radius; |
||||
|
||||
#define Y (get_group_id(1) * ROWSperTHREAD + radius) |
||||
|
||||
volatile __global unsigned int* minSSDImage = cminSSDImage + X + Y * cminSSD_step; |
||||
__global unsigned char* disparImage = disp + X + Y * disp_step; |
||||
|
||||
int end_row = ROWSperTHREAD < (cheight - Y) ? ROWSperTHREAD:(cheight - Y); |
||||
int y_tex; |
||||
int x_tex = X - radius; |
||||
|
||||
if (x_tex >= cwidth) |
||||
return; |
||||
|
||||
for(int d = STEREO_MIND; d < maxdisp; d += STEREO_DISP_STEP) |
||||
{ |
||||
y_tex = Y - radius; |
||||
|
||||
InitColSSD(x_tex, y_tex, img_step, left, right, d, col_ssd, radius); |
||||
if (col_ssd_extra > 0) |
||||
if (x_tex + BLOCK_W < cwidth) |
||||
InitColSSD(x_tex + BLOCK_W, y_tex, img_step, left, right, d, col_ssd_extra, radius); |
||||
|
||||
barrier(CLK_LOCAL_MEM_FENCE); //before MinSSD function |
||||
|
||||
if (X < cwidth - radius && Y < cheight - radius) |
||||
{ |
||||
uint2 minSSD = MinSSD(col_ssd_cache + get_local_id(0), col_ssd, radius); |
||||
if (minSSD.x < minSSDImage[0]) |
||||
{ |
||||
disparImage[0] = (unsigned char)(d + minSSD.y); |
||||
minSSDImage[0] = minSSD.x; |
||||
} |
||||
} |
||||
|
||||
for(int row = 1; row < end_row; row++) |
||||
{ |
||||
int idx1 = y_tex * img_step + x_tex; |
||||
int idx2 = (y_tex + (2 * radius + 1)) * img_step + x_tex; |
||||
|
||||
barrier(CLK_GLOBAL_MEM_FENCE); |
||||
barrier(CLK_LOCAL_MEM_FENCE); |
||||
|
||||
StepDown(idx1, idx2, left, right, d, col_ssd, radius); |
||||
if (col_ssd_extra > 0) |
||||
if (x_tex + BLOCK_W < cwidth) |
||||
StepDown(idx1, idx2, left + BLOCK_W, right + BLOCK_W, d, col_ssd_extra, radius); |
||||
|
||||
y_tex += 1; |
||||
|
||||
barrier(CLK_LOCAL_MEM_FENCE); |
||||
|
||||
if (X < cwidth - radius && row < cheight - radius - Y) |
||||
{ |
||||
int idx = row * cminSSD_step; |
||||
uint2 minSSD = MinSSD(col_ssd_cache + get_local_id(0), col_ssd, radius); |
||||
if (minSSD.x < minSSDImage[idx]) |
||||
{ |
||||
disparImage[disp_step * row] = (unsigned char)(d + minSSD.y); |
||||
minSSDImage[idx] = minSSD.x; |
||||
} |
||||
} |
||||
} // for row loop |
||||
} // for d loop |
||||
} |
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////// |
||||
//////////////////////////// Sobel Prefiler (signal channel)////////////////////////////////////// |
||||
////////////////////////////////////////////////////////////////////////////////////////////////// |
||||
|
||||
__kernel void prefilter_xsobel(__global unsigned char *input, __global unsigned char *output, |
||||
int rows, int cols, int prefilterCap) |
||||
{ |
||||
int x = get_global_id(0); |
||||
int y = get_global_id(1); |
||||
|
||||
if(x < cols && y < rows) |
||||
{ |
||||
int cov = input[(y-1) * cols + (x-1)] * (-1) + input[(y-1) * cols + (x+1)] * (1) + |
||||
input[(y) * cols + (x-1)] * (-2) + input[(y) * cols + (x+1)] * (2) + |
||||
input[(y+1) * cols + (x-1)] * (-1) + input[(y+1) * cols + (x+1)] * (1); |
||||
|
||||
cov = min(min(max(-prefilterCap, cov), prefilterCap) + prefilterCap, 255); |
||||
output[y * cols + x] = cov & 0xFF; |
||||
} |
||||
} |
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////// |
||||
/////////////////////////////////// Textureness filtering //////////////////////////////////////// |
||||
////////////////////////////////////////////////////////////////////////////////////////////////// |
||||
|
||||
float sobel(__global unsigned char *input, int x, int y, int rows, int cols) |
||||
{ |
||||
float conv = 0; |
||||
int y1 = y==0? 0 : y-1; |
||||
int x1 = x==0? 0 : x-1; |
||||
if(x < cols && y < rows) |
||||
{ |
||||
conv = (float)input[(y1) * cols + (x1)] * (-1) + (float)input[(y1) * cols + (x+1)] * (1) + |
||||
(float)input[(y) * cols + (x1)] * (-2) + (float)input[(y) * cols + (x+1)] * (2) + |
||||
(float)input[(y+1) * cols + (x1)] * (-1) + (float)input[(y+1) * cols + (x+1)] * (1); |
||||
|
||||
} |
||||
return fabs(conv); |
||||
} |
||||
|
||||
float CalcSums(__local float *cols, __local float *cols_cache, int winsz) |
||||
{ |
||||
float cache = 0; |
||||
float cache2 = 0; |
||||
int winsz2 = winsz/2; |
||||
|
||||
int x = get_local_id(0); |
||||
int group_size_x = get_local_size(0); |
||||
|
||||
for(int i = 1; i <= winsz2; i++) |
||||
cache += cols[i]; |
||||
|
||||
cols_cache[0] = cache; |
||||
|
||||
barrier(CLK_LOCAL_MEM_FENCE); |
||||
|
||||
if (x < group_size_x - winsz2) |
||||
cache2 = cols_cache[winsz2]; |
||||
else |
||||
for(int i = winsz2 + 1; i < winsz; i++) |
||||
cache2 += cols[i]; |
||||
|
||||
return cols[0] + cache + cache2; |
||||
} |
||||
|
||||
#define RpT (2 * ROWSperTHREAD) // got experimentally |
||||
__kernel void textureness_kernel(__global unsigned char *disp, int disp_rows, int disp_cols, |
||||
int disp_step, __global unsigned char *input, int input_rows, |
||||
int input_cols,int winsz, float threshold, |
||||
__local float *cols_cache) |
||||
{ |
||||
int winsz2 = winsz/2; |
||||
int n_dirty_pixels = (winsz2) * 2; |
||||
|
||||
int local_id_x = get_local_id(0); |
||||
int group_size_x = get_local_size(0); |
||||
int group_id_y = get_group_id(1); |
||||
|
||||
__local float *cols = cols_cache + group_size_x + local_id_x; |
||||
__local float *cols_extra = local_id_x < n_dirty_pixels ? cols + group_size_x : 0; |
||||
|
||||
int x = get_global_id(0); |
||||
int beg_row = group_id_y * RpT; |
||||
int end_row = min(beg_row + RpT, disp_rows); |
||||
|
||||
if (x < disp_cols) |
||||
{ |
||||
int y = beg_row; |
||||
|
||||
float sum = 0; |
||||
float sum_extra = 0; |
||||
|
||||
for(int i = y - winsz2; i <= y + winsz2; ++i) |
||||
{ |
||||
sum += sobel(input, x - winsz2, i, input_rows, input_cols); |
||||
if (cols_extra) |
||||
sum_extra += sobel(input, x + group_size_x - winsz2, i, input_rows, input_cols); |
||||
} |
||||
*cols = sum; |
||||
if (cols_extra) |
||||
*cols_extra = sum_extra; |
||||
|
||||
barrier(CLK_LOCAL_MEM_FENCE); |
||||
|
||||
float sum_win = CalcSums(cols, cols_cache + local_id_x, winsz) * 255; |
||||
if (sum_win < threshold) |
||||
disp[y * disp_step + x] = 0; |
||||
|
||||
barrier(CLK_LOCAL_MEM_FENCE); |
||||
|
||||
for(int y = beg_row + 1; y < end_row; ++y) |
||||
{ |
||||
sum = sum - sobel(input, x - winsz2, y - winsz2 - 1, input_rows, input_cols) + |
||||
sobel(input, x - winsz2, y + winsz2, input_rows, input_cols); |
||||
*cols = sum; |
||||
|
||||
if (cols_extra) |
||||
{ |
||||
sum_extra = sum_extra - sobel(input, x + group_size_x - winsz2, y - winsz2 - 1,input_rows, input_cols) |
||||
+ sobel(input, x + group_size_x - winsz2, y + winsz2, input_rows, input_cols); |
||||
*cols_extra = sum_extra; |
||||
} |
||||
|
||||
barrier(CLK_LOCAL_MEM_FENCE); |
||||
float sum_win = CalcSums(cols, cols_cache + local_id_x, winsz) * 255; |
||||
if (sum_win < threshold) |
||||
disp[y * disp_step + x] = 0; |
||||
|
||||
barrier(CLK_LOCAL_MEM_FENCE); |
||||
} |
||||
} |
||||
} |
@ -1,580 +0,0 @@ |
||||
/*M/////////////////////////////////////////////////////////////////////////////////////// |
||||
// |
||||
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. |
||||
// |
||||
// By downloading, copying, installing or using the software you agree to this license. |
||||
// If you do not agree to this license, do not download, install, |
||||
// copy or use the software. |
||||
// |
||||
// |
||||
// License Agreement |
||||
// For Open Source Computer Vision Library |
||||
// |
||||
// Copyright (C) 2010-2012, Institute Of Software Chinese Academy Of Science, all rights reserved. |
||||
// Copyright (C) 2010-2012, Advanced Micro Devices, Inc., all rights reserved. |
||||
// Third party copyrights are property of their respective owners. |
||||
// |
||||
// @Authors |
||||
// Jia Haipeng, jiahaipeng95@gmail.com |
||||
// |
||||
// Redistribution and use in source and binary forms, with or without modification, |
||||
// are permitted provided that the following conditions are met: |
||||
// |
||||
// * Redistribution's of source code must retain the above copyright notice, |
||||
// this list of conditions and the following disclaimer. |
||||
// |
||||
// * Redistribution's in binary form must reproduce the above copyright notice, |
||||
// this list of conditions and the following disclaimer in the documentation |
||||
// and/or other GpuMaterials provided with the distribution. |
||||
// |
||||
// * The name of the copyright holders may not be used to endorse or promote products |
||||
// derived from this software without specific prior written permission. |
||||
// |
||||
// This software is provided by the copyright holders and contributors as is and |
||||
// any express or implied warranties, including, but not limited to, the implied |
||||
// warranties of merchantability and fitness for a particular purpose are disclaimed. |
||||
// In no event shall the Intel Corporation or contributors be liable for any direct, |
||||
// indirect, incidental, special, exemplary, or consequential damages |
||||
// (including, but not limited to, procurement of substitute goods or services; |
||||
// loss of use, data, or profits; or business interruption) however caused |
||||
// and on any theory of liability, whether in contract, strict liability, |
||||
// or tort (including negligence or otherwise) arising in any way out of |
||||
// the use of this software, even if advised of the possibility of such damage. |
||||
// |
||||
//M*/ |
||||
|
||||
#if defined (__ATI__) |
||||
#pragma OPENCL EXTENSION cl_amd_fp64:enable |
||||
#elif defined (__NVIDIA__) |
||||
#pragma OPENCL EXTENSION cl_khr_fp64:enable |
||||
#endif |
||||
/////////////////////////////////////////////////////////////// |
||||
/////////////////common/////////////////////////////////////// |
||||
///////////////////////////////////////////////////////////// |
||||
short round_short(float v){ |
||||
return convert_short_sat_rte(v); |
||||
} |
||||
#define FLOAT_MAX 3.402823466e+38f |
||||
typedef struct |
||||
{ |
||||
int cndisp; |
||||
float cmax_data_term; |
||||
float cdata_weight; |
||||
float cmax_disc_term; |
||||
float cdisc_single_jump; |
||||
}con_srtuct_t; |
||||
/////////////////////////////////////////////////////////////// |
||||
////////////////////////// comp data ////////////////////////// |
||||
/////////////////////////////////////////////////////////////// |
||||
|
||||
float pix_diff_1(__global const uchar *ls, __global const uchar *rs) |
||||
{ |
||||
return abs((int)(*ls) - *rs); |
||||
} |
||||
|
||||
float pix_diff_3(__global const uchar *ls, __global const uchar *rs) |
||||
{ |
||||
const float tr = 0.299f; |
||||
const float tg = 0.587f; |
||||
const float tb = 0.114f; |
||||
|
||||
float val; |
||||
|
||||
val = tb * abs((int)ls[0] - rs[0]); |
||||
val += tg * abs((int)ls[1] - rs[1]); |
||||
val += tr * abs((int)ls[2] - rs[2]); |
||||
|
||||
return val; |
||||
} |
||||
float pix_diff_4(__global const uchar *ls, __global const uchar *rs) |
||||
{ |
||||
uchar4 l, r; |
||||
l = *((__global uchar4 *)ls); |
||||
r = *((__global uchar4 *)rs); |
||||
|
||||
const float tr = 0.299f; |
||||
const float tg = 0.587f; |
||||
const float tb = 0.114f; |
||||
|
||||
float val; |
||||
|
||||
val = tb * abs((int)l.x - r.x); |
||||
val += tg * abs((int)l.y - r.y); |
||||
val += tr * abs((int)l.z - r.z); |
||||
|
||||
return val; |
||||
} |
||||
|
||||
__kernel void comp_data_0(__global uchar *left, int left_rows, int left_cols, int left_step, |
||||
__global uchar *right, int right_step, |
||||
__global short *data, int data_cols, int data_step, |
||||
__constant con_srtuct_t *con_st, int cn) |
||||
// int cndisp, float cmax_data_term, float cdata_weight, int cn) |
||||
{ |
||||
int x = get_global_id(0); |
||||
int y = get_global_id(1); |
||||
|
||||
if (y > 0 && y < (left_rows - 1) && x > 0 && x < (left_cols - 1)) |
||||
{ |
||||
const __global uchar* ls = left + y * left_step + x * cn; |
||||
const __global uchar* rs = right + y * right_step + x * cn; |
||||
|
||||
__global short *ds = (__global short *)((__global uchar *)data + y * data_step) + x; |
||||
|
||||
const unsigned int disp_step = data_cols * left_rows ; |
||||
|
||||
for (int disp = 0; disp < con_st -> cndisp; disp++) |
||||
{ |
||||
if (x - disp >= 1) |
||||
{ |
||||
float val = 0; |
||||
if(cn == 1) |
||||
val = pix_diff_1(ls, rs - disp * cn); |
||||
if(cn == 3) |
||||
val = pix_diff_3(ls, rs - disp * cn); |
||||
if(cn == 4) |
||||
val = pix_diff_4(ls, rs - disp *cn); |
||||
|
||||
ds[disp * disp_step] = round_short(fmin(con_st -> cdata_weight * val, |
||||
con_st -> cdata_weight * con_st -> cmax_data_term)); |
||||
} |
||||
else |
||||
{ |
||||
ds[disp * disp_step] = round_short(con_st -> cdata_weight * con_st -> cmax_data_term); |
||||
} |
||||
} |
||||
} |
||||
} |
||||
|
||||
__kernel void comp_data_1(__global uchar *left, int left_rows, int left_cols, int left_step, |
||||
__global uchar *right, int right_step, |
||||
__global float *data, int data_cols, int data_step, |
||||
__constant con_srtuct_t *con_st, int cn) |
||||
//int cndisp, float cmax_data_term, float cdata_weight, int cn) |
||||
{ |
||||
int x = get_global_id(0); |
||||
int y = get_global_id(1); |
||||
|
||||
if (y > 0 && y < left_rows - 1 && x > 0 && x < left_cols - 1) |
||||
{ |
||||
const __global uchar* ls = left + y * left_step + x * cn; |
||||
const __global uchar* rs = right + y * right_step + x * cn; |
||||
|
||||
__global float *ds = (__global float *)((__global char *)data + y * data_step) + x; |
||||
|
||||
const unsigned int disp_step = data_cols * left_rows; |
||||
|
||||
for (int disp = 0; disp < con_st -> cndisp; disp++) |
||||
{ |
||||
if (x - disp >= 1) |
||||
{ |
||||
float val = 0; |
||||
if(cn == 1) |
||||
val = pix_diff_1(ls, rs - disp * cn); |
||||
if(cn == 3) |
||||
val = pix_diff_3(ls, rs - disp * cn); |
||||
if(cn == 4) |
||||
val = pix_diff_4(ls, rs - disp *cn); |
||||
|
||||
ds[disp * disp_step] = fmin(con_st -> cdata_weight * val, |
||||
con_st -> cdata_weight * con_st -> cmax_data_term); |
||||
} |
||||
else |
||||
{ |
||||
ds[disp * disp_step] = con_st -> cdata_weight * con_st -> cmax_data_term; |
||||
} |
||||
} |
||||
} |
||||
} |
||||
|
||||
/////////////////////////////////////////////////////////////// |
||||
//////////////////////// data step down /////////////////////// |
||||
/////////////////////////////////////////////////////////////// |
||||
__kernel void data_step_down_0(__global short *src, int src_rows, int src_cols, |
||||
__global short *dst, int dst_rows, int dst_cols, int dst_real_cols, |
||||
int cndisp) |
||||
{ |
||||
const int x = get_global_id(0); |
||||
const int y = get_global_id(1);; |
||||
|
||||
if (x < dst_cols && y < dst_rows) |
||||
{ |
||||
for (int d = 0; d < cndisp; ++d) |
||||
{ |
||||
//float dst_reg = src.ptr(d * src_rows + (2*y+0))[(2*x+0)]; |
||||
float dst_reg; |
||||
dst_reg = src[(d * src_rows + (2*y+0)) * src_cols + 2*x+0]; |
||||
dst_reg += src[(d * src_rows + (2*y+1)) * src_cols + 2*x+0]; |
||||
dst_reg += src[(d * src_rows + (2*y+0)) * src_cols + 2*x+1]; |
||||
dst_reg += src[(d * src_rows + (2*y+1)) * src_cols + 2*x+1]; |
||||
|
||||
//dst.ptr(d * dst_rows + y)[x] = saturate_cast<T>(dst_reg); |
||||
dst[(d * dst_rows + y) * dst_real_cols + x] = round_short(dst_reg); |
||||
} |
||||
} |
||||
} |
||||
__kernel void data_step_down_1(__global float *src, int src_rows, int src_cols, |
||||
__global float *dst, int dst_rows, int dst_cols, int dst_real_cols, |
||||
int cndisp) |
||||
{ |
||||
const int x = get_global_id(0); |
||||
const int y = get_global_id(1);; |
||||
|
||||
if (x < dst_cols && y < dst_rows) |
||||
{ |
||||
for (int d = 0; d < cndisp; ++d) |
||||
{ |
||||
//float dst_reg = src.ptr(d * src_rows + (2*y+0))[(2*x+0)]; |
||||
float dst_reg; |
||||
dst_reg = src[(d * src_rows + (2*y+0)) * src_cols + 2*x+0]; |
||||
dst_reg += src[(d * src_rows + (2*y+1)) * src_cols + 2*x+0]; |
||||
dst_reg += src[(d * src_rows + (2*y+0)) * src_cols + 2*x+1]; |
||||
dst_reg += src[(d * src_rows + (2*y+1)) * src_cols + 2*x+1]; |
||||
|
||||
//dst.ptr(d * dst_rows + y)[x] = saturate_cast<T>(dst_reg); |
||||
dst[(d * dst_rows + y) * dst_real_cols + x] = round_short(dst_reg); |
||||
} |
||||
} |
||||
} |
||||
|
||||
/////////////////////////////////////////////////////////////// |
||||
/////////////////// level up messages //////////////////////// |
||||
/////////////////////////////////////////////////////////////// |
||||
__kernel void level_up_message_0(__global short *src, int src_rows, int src_step, |
||||
__global short *dst, int dst_rows, int dst_cols, int dst_step, |
||||
int cndisp) |
||||
|
||||
{ |
||||
const int x = get_global_id(0); |
||||
const int y = get_global_id(1); |
||||
|
||||
if (x < dst_cols && y < dst_rows) |
||||
{ |
||||
const int dst_disp_step = (dst_step / sizeof(short)) * dst_rows; |
||||
const int src_disp_step = (src_step / sizeof(short)) * src_rows; |
||||
|
||||
__global short *dstr = (__global short *)((__global char *)dst + y * dst_step) + x; |
||||
__global const short *srcr = (__global short *)((__global char *)src + y/2 * src_step) + x/2; |
||||
|
||||
for (int d = 0; d < cndisp; ++d) |
||||
dstr[d * dst_disp_step] = srcr[d * src_disp_step]; |
||||
} |
||||
} |
||||
__kernel void level_up_message_1(__global float *src, int src_rows, int src_step, |
||||
__global float *dst, int dst_rows, int dst_cols, int dst_step, |
||||
int cndisp) |
||||
|
||||
{ |
||||
const int x = get_global_id(0); |
||||
const int y = get_global_id(1); |
||||
|
||||
if (x < dst_cols && y < dst_rows) |
||||
{ |
||||
const int dst_disp_step = (dst_step/sizeof(float)) * dst_rows; |
||||
const int src_disp_step = (src_step/sizeof(float)) * src_rows; |
||||
|
||||
__global float *dstr = (__global float *)((__global char *)dst + y * dst_step) + x; |
||||
__global const float *srcr = (__global float *)((__global char *)src + y/2 * src_step) + x/2; |
||||
|
||||
for (int d = 0; d < cndisp; ++d) |
||||
dstr[d * dst_disp_step] = srcr[d * src_disp_step]; |
||||
} |
||||
} |
||||
|
||||
/////////////////////////////////////////////////////////////// |
||||
//////////////////// calc all iterations ///////////////////// |
||||
/////////////////////////////////////////////////////////////// |
||||
void calc_min_linear_penalty_0(__global short * dst, int disp_step, |
||||
int cndisp, float cdisc_single_jump) |
||||
{ |
||||
float prev = dst[0]; |
||||
float cur; |
||||
|
||||
for (int disp = 1; disp < cndisp; ++disp) |
||||
{ |
||||
prev += cdisc_single_jump; |
||||
cur = dst[disp_step * disp]; |
||||
|
||||
if (prev < cur) |
||||
{ |
||||
cur = prev; |
||||
dst[disp_step * disp] = round_short(prev); |
||||
} |
||||
|
||||
prev = cur; |
||||
} |
||||
|
||||
prev = dst[(cndisp - 1) * disp_step]; |
||||
for (int disp = cndisp - 2; disp >= 0; disp--) |
||||
{ |
||||
prev += cdisc_single_jump; |
||||
cur = dst[disp_step * disp]; |
||||
|
||||
if (prev < cur) |
||||
{ |
||||
cur = prev; |
||||
dst[disp_step * disp] = round_short(prev); |
||||
} |
||||
prev = cur; |
||||
} |
||||
} |
||||
void message_0(const __global short *msg1, const __global short *msg2, |
||||
const __global short *msg3, const __global short *data, __global short *dst, |
||||
int msg_disp_step, int data_disp_step, int cndisp, float cmax_disc_term, float cdisc_single_jump) |
||||
{ |
||||
float minimum = FLOAT_MAX; |
||||
|
||||
for(int i = 0; i < cndisp; ++i) |
||||
{ |
||||
float dst_reg; |
||||
dst_reg = msg1[msg_disp_step * i]; |
||||
dst_reg += msg2[msg_disp_step * i]; |
||||
dst_reg += msg3[msg_disp_step * i]; |
||||
dst_reg += data[data_disp_step * i]; |
||||
|
||||
if (dst_reg < minimum) |
||||
minimum = dst_reg; |
||||
|
||||
dst[msg_disp_step * i] = round_short(dst_reg); |
||||
} |
||||
|
||||
calc_min_linear_penalty_0(dst, msg_disp_step, cndisp, cdisc_single_jump); |
||||
|
||||
minimum += cmax_disc_term; |
||||
|
||||
float sum = 0; |
||||
for(int i = 0; i < cndisp; ++i) |
||||
{ |
||||
float dst_reg = dst[msg_disp_step * i]; |
||||
if (dst_reg > minimum) |
||||
{ |
||||
dst_reg = minimum; |
||||
dst[msg_disp_step * i] = round_short(minimum); |
||||
} |
||||
sum += dst_reg; |
||||
} |
||||
sum /= cndisp; |
||||
|
||||
for(int i = 0; i < cndisp; ++i) |
||||
dst[msg_disp_step * i] -= sum; |
||||
} |
||||
__kernel void one_iteration_0(__global short *u, int u_step, int u_cols, |
||||
__global short *data, int data_step, int data_cols, |
||||
__global short *d, __global short *l, __global short *r, |
||||
int t, int cols, int rows, |
||||
int cndisp, float cmax_disc_term, float cdisc_single_jump) |
||||
{ |
||||
const int y = get_global_id(1); |
||||
const int x = ((get_global_id(0)) << 1) + ((y + t) & 1); |
||||
|
||||
if ((y > 0) && (y < rows - 1) && (x > 0) && (x < cols - 1)) |
||||
{ |
||||
__global short *us = (__global short *)((__global char *)u + y * u_step) + x; |
||||
__global short *ds = d + y * u_cols + x; |
||||
__global short *ls = l + y * u_cols + x; |
||||
__global short *rs = r + y * u_cols + x; |
||||
const __global short *dt = (__global short *)((__global char *)data + y * data_step) + x; |
||||
|
||||
int msg_disp_step = u_cols * rows; |
||||
int data_disp_step = data_cols * rows; |
||||
|
||||
message_0(us + u_cols, ls + 1, rs - 1, dt, us, msg_disp_step, data_disp_step, cndisp, |
||||
cmax_disc_term, cdisc_single_jump); |
||||
message_0(ds - u_cols, ls + 1, rs - 1, dt, ds, msg_disp_step, data_disp_step, cndisp, |
||||
cmax_disc_term, cdisc_single_jump); |
||||
|
||||
message_0(us + u_cols, ds - u_cols, rs - 1, dt, rs, msg_disp_step, data_disp_step, cndisp, |
||||
cmax_disc_term, cdisc_single_jump); |
||||
message_0(us + u_cols, ds - u_cols, ls + 1, dt, ls, msg_disp_step, data_disp_step, cndisp, |
||||
cmax_disc_term, cdisc_single_jump); |
||||
} |
||||
} |
||||
void calc_min_linear_penalty_1(__global float * dst, int step, |
||||
int cndisp, float cdisc_single_jump) |
||||
{ |
||||
float prev = dst[0]; |
||||
float cur; |
||||
|
||||
for (int disp = 1; disp < cndisp; ++disp) |
||||
{ |
||||
prev += cdisc_single_jump; |
||||
cur = dst[step * disp]; |
||||
|
||||
if (prev < cur) |
||||
{ |
||||
cur = prev; |
||||
dst[step * disp] = prev; |
||||
} |
||||
|
||||
prev = cur; |
||||
} |
||||
|
||||
prev = dst[(cndisp - 1) * step]; |
||||
for (int disp = cndisp - 2; disp >= 0; disp--) |
||||
{ |
||||
prev += cdisc_single_jump; |
||||
cur = dst[step * disp]; |
||||
|
||||
if (prev < cur) |
||||
{ |
||||
cur = prev; |
||||
dst[step * disp] = prev; |
||||
} |
||||
prev = cur; |
||||
} |
||||
} |
||||
void message_1(const __global float *msg1, const __global float *msg2, |
||||
const __global float *msg3, const __global float *data, __global float *dst, |
||||
int msg_disp_step, int data_disp_step, int cndisp, float cmax_disc_term, float cdisc_single_jump) |
||||
{ |
||||
float minimum = FLOAT_MAX; |
||||
|
||||
for(int i = 0; i < cndisp; ++i) |
||||
{ |
||||
float dst_reg = 0; |
||||
dst_reg = msg1[msg_disp_step * i]; |
||||
dst_reg += msg2[msg_disp_step * i]; |
||||
dst_reg += msg3[msg_disp_step * i]; |
||||
dst_reg += data[data_disp_step * i]; |
||||
|
||||
if (dst_reg < minimum) |
||||
minimum = dst_reg; |
||||
|
||||
dst[msg_disp_step * i] = dst_reg; |
||||
} |
||||
|
||||
calc_min_linear_penalty_1(dst, msg_disp_step, cndisp, cdisc_single_jump); |
||||
|
||||
minimum += cmax_disc_term; |
||||
|
||||
float sum = 0; |
||||
for(int i = 0; i < cndisp; ++i) |
||||
{ |
||||
float dst_reg = dst[msg_disp_step * i]; |
||||
if (dst_reg > minimum) |
||||
{ |
||||
dst_reg = minimum; |
||||
dst[msg_disp_step * i] = minimum; |
||||
} |
||||
sum += dst_reg; |
||||
} |
||||
sum /= cndisp; |
||||
|
||||
for(int i = 0; i < cndisp; ++i) |
||||
dst[msg_disp_step * i] -= sum; |
||||
} |
||||
__kernel void one_iteration_1(__global float *u, int u_step, int u_cols, |
||||
__global float *data, int data_step, int data_cols, |
||||
__global float *d, __global float *l, __global float *r, |
||||
int t, int cols, int rows, |
||||
int cndisp,float cmax_disc_term, float cdisc_single_jump) |
||||
{ |
||||
const int y = get_global_id(1); |
||||
const int x = ((get_global_id(0)) << 1) + ((y + t) & 1); |
||||
|
||||
if ((y > 0) && (y < rows - 1) && (x > 0) && (x < cols - 1)) |
||||
{ |
||||
__global float* us = (__global float *)((__global char *)u + y * u_step) + x; |
||||
__global float* ds = d + y * u_cols + x; |
||||
__global float* ls = l + y * u_cols + x; |
||||
__global float* rs = r + y * u_cols + x; |
||||
const __global float* dt = (__global float *)((__global char *)data + y * data_step) + x; |
||||
|
||||
int msg_disp_step = u_cols * rows; |
||||
int data_disp_step = data_cols * rows; |
||||
|
||||
message_1(us + u_cols, ls + 1, rs - 1, dt, us, msg_disp_step, data_disp_step, cndisp, |
||||
cmax_disc_term, cdisc_single_jump); |
||||
message_1(ds - u_cols, ls + 1, rs - 1, dt, ds, msg_disp_step, data_disp_step, cndisp, |
||||
cmax_disc_term, cdisc_single_jump); |
||||
message_1(us + u_cols, ds - u_cols, rs - 1, dt, rs, msg_disp_step, data_disp_step, cndisp, |
||||
cmax_disc_term, cdisc_single_jump); |
||||
message_1(us + u_cols, ds - u_cols, ls + 1, dt, ls, msg_disp_step, data_disp_step, cndisp, |
||||
cmax_disc_term, cdisc_single_jump); |
||||
} |
||||
} |
||||
|
||||
/////////////////////////////////////////////////////////////// |
||||
/////////////////////////// output //////////////////////////// |
||||
/////////////////////////////////////////////////////////////// |
||||
__kernel void output_0(const __global short *u, int u_step, int u_cols, |
||||
const __global short *d, const __global short *l, |
||||
const __global short *r, const __global short *data, |
||||
__global short *disp, int disp_rows, int disp_cols, int disp_step, |
||||
int cndisp) |
||||
{ |
||||
const int x = get_global_id(0); |
||||
const int y = get_global_id(1); |
||||
|
||||
if (y > 0 && y < disp_rows - 1 && x > 0 && x < disp_cols - 1) |
||||
{ |
||||
const __global short *us =(__global short *)((__global char *)u + (y + 1) * u_step) + x; |
||||
const __global short *ds = d + (y - 1) * u_cols + x; |
||||
const __global short *ls = l + y * u_cols + (x + 1); |
||||
const __global short *rs = r + y * u_cols + (x - 1); |
||||
const __global short *dt = data + y * u_cols + x; |
||||
|
||||
int disp_steps = disp_rows * u_cols; |
||||
|
||||
int best = 0; |
||||
float best_val = FLOAT_MAX; |
||||
for (int d = 0; d < cndisp; ++d) |
||||
{ |
||||
float val; |
||||
val = us[d * disp_steps]; |
||||
val += ds[d * disp_steps]; |
||||
val += ls[d * disp_steps]; |
||||
val += rs[d * disp_steps]; |
||||
val += dt[d * disp_steps]; |
||||
|
||||
if (val < best_val) |
||||
{ |
||||
best_val = val; |
||||
best = d; |
||||
} |
||||
} |
||||
|
||||
((__global short *)((__global char *)disp + y * disp_step))[x] = convert_short_sat(best); |
||||
} |
||||
} |
||||
__kernel void output_1(const __global float *u, int u_step, int u_cols, |
||||
const __global float *d, const __global float *l, |
||||
const __global float *r, const __global float *data, |
||||
__global short *disp, int disp_rows, int disp_cols, int disp_step, |
||||
int cndisp) |
||||
{ |
||||
const int x = get_global_id(0); |
||||
const int y = get_global_id(1); |
||||
|
||||
if (y > 0 && y < disp_rows - 1 && x > 0 && x < disp_cols - 1) |
||||
{ |
||||
const __global float *us =(__global float *)((__global char *)u + (y + 1) * u_step) + x; |
||||
const __global float *ds = d + (y - 1) * u_cols + x; |
||||
const __global float *ls = l + y * u_cols + (x + 1); |
||||
const __global float *rs = r + y * u_cols + (x - 1); |
||||
const __global float *dt = data + y * u_cols + x; |
||||
|
||||
int disp_steps = disp_rows * u_cols; |
||||
|
||||
int best = 0; |
||||
float best_val = FLOAT_MAX; |
||||
for (int d = 0; d < cndisp; ++d) |
||||
{ |
||||
float val; |
||||
val = us[d * disp_steps]; |
||||
val += ds[d * disp_steps]; |
||||
val += ls[d * disp_steps]; |
||||
val += rs[d * disp_steps]; |
||||
val += dt[d * disp_steps]; |
||||
|
||||
if (val < best_val) |
||||
{ |
||||
best_val = val; |
||||
best = d; |
||||
} |
||||
} |
||||
|
||||
//disp[y * disp_cols + x] = convert_short_sat(best); |
||||
((__global short *)((__global char *)disp + y * disp_step))[x] = convert_short_sat(best); |
||||
} |
||||
} |
File diff suppressed because it is too large
Load Diff
@ -1,786 +0,0 @@ |
||||
/*M///////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
|
||||
//
|
||||
// By downloading, copying, installing or using the software you agree to this license.
|
||||
// If you do not agree to this license, do not download, install,
|
||||
// copy or use the software.
|
||||
//
|
||||
//
|
||||
// License Agreement
|
||||
// For Open Source Computer Vision Library
|
||||
//
|
||||
// Copyright (C) 2010-2012, Institute Of Software Chinese Academy Of Science, all rights reserved.
|
||||
// Copyright (C) 2010-2012, Advanced Micro Devices, Inc., all rights reserved.
|
||||
// Third party copyrights are property of their respective owners.
|
||||
//
|
||||
// @Authors
|
||||
// Jia Haipeng, jiahaipeng95@gmail.com
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
// are permitted provided that the following conditions are met:
|
||||
//
|
||||
// * Redistribution's of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
//
|
||||
// * Redistribution's in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other oclMaterials provided with the distribution.
|
||||
//
|
||||
// * The name of the copyright holders may not be used to endorse or promote products
|
||||
// derived from this software without specific prior written permission.
|
||||
//
|
||||
// This software is provided by the copyright holders and contributors "as is" and
|
||||
// any express or implied warranties, including, but not limited to, the implied
|
||||
// warranties of merchantability and fitness for a particular purpose are disclaimed.
|
||||
// In no event shall the Intel Corporation or contributors be liable for any direct,
|
||||
// indirect, incidental, special, exemplary, or consequential damages
|
||||
// (including, but not limited to, procurement of substitute goods or services;
|
||||
// loss of use, data, or profits; or business interruption) however caused
|
||||
// and on any theory of liability, whether in contract, strict liability,
|
||||
// or tort (including negligence or otherwise) arising in any way out of
|
||||
// the use of this software, even if advised of the possibility of such damage.
|
||||
//
|
||||
//M*/
|
||||
|
||||
#include "precomp.hpp" |
||||
|
||||
using namespace cv; |
||||
using namespace cv::ocl; |
||||
using namespace std; |
||||
|
||||
#if !defined (HAVE_OPENCL) |
||||
|
||||
namespace cv |
||||
{ |
||||
namespace ocl |
||||
{ |
||||
|
||||
void cv::ocl::StereoConstantSpaceBP::estimateRecommendedParams(int, int, int &, int &, int &, int &) |
||||
{ |
||||
throw_nogpu(); |
||||
} |
||||
cv::ocl::StereoConstantSpaceBP::StereoConstantSpaceBP(int, int, int, int, int) |
||||
{ |
||||
throw_nogpu(); |
||||
} |
||||
cv::ocl::StereoConstantSpaceBP::StereoConstantSpaceBP(int, int, int, int, float, float, |
||||
float, float, int, int) |
||||
{ |
||||
throw_nogpu(); |
||||
} |
||||
|
||||
void cv::ocl::StereoConstantSpaceBP::operator()(const oclMat &, const oclMat &, oclMat &) |
||||
{ |
||||
throw_nogpu(); |
||||
} |
||||
} |
||||
} |
||||
|
||||
#else /* !defined (HAVE_OPENCL) */ |
||||
|
||||
namespace cv |
||||
{ |
||||
namespace ocl |
||||
{ |
||||
|
||||
///////////////////////////OpenCL kernel strings///////////////////////////
|
||||
extern const char *stereocsbp; |
||||
} |
||||
|
||||
} |
||||
namespace cv |
||||
{ |
||||
namespace ocl |
||||
{ |
||||
namespace stereoCSBP |
||||
{ |
||||
//////////////////////////////////////////////////////////////////////////
|
||||
//////////////////////////////common////////////////////////////////////
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
static inline int divUp(int total, int grain) |
||||
{ |
||||
return (total + grain - 1) / grain; |
||||
} |
||||
static string get_kernel_name(string kernel_name, int data_type) |
||||
{ |
||||
stringstream idxStr; |
||||
if(data_type == CV_16S) |
||||
idxStr << "0"; |
||||
else |
||||
idxStr << "1"; |
||||
kernel_name += idxStr.str(); |
||||
|
||||
return kernel_name; |
||||
} |
||||
using cv::ocl::StereoConstantSpaceBP; |
||||
//////////////////////////////////////////////////////////////////////////////////
|
||||
/////////////////////////////////init_data_cost//////////////////////////////////
|
||||
//////////////////////////////////////////////////////////////////////////////////
|
||||
static void init_data_cost_caller(const oclMat &left, const oclMat &right, oclMat &temp, |
||||
StereoConstantSpaceBP &rthis, |
||||
int msg_step, int h, int w, int level) |
||||
{ |
||||
Context *clCxt = left.clCxt; |
||||
int data_type = rthis.msg_type; |
||||
int channels = left.channels(); |
||||
|
||||
string kernelName = get_kernel_name("init_data_cost_", data_type); |
||||
|
||||
cl_kernel kernel = openCLGetKernelFromSource(clCxt, &stereocsbp, kernelName); |
||||
|
||||
size_t blockSize = 256; |
||||
size_t localThreads[] = {32, 8}; |
||||
size_t globalThreads[] = {divUp(w, localThreads[0]) * localThreads[0], |
||||
divUp(h, localThreads[1]) * localThreads[1] |
||||
}; |
||||
|
||||
int cdisp_step1 = msg_step * h; |
||||
openCLVerifyKernel(clCxt, kernel, &blockSize, globalThreads, localThreads); |
||||
openCLSafeCall(clSetKernelArg(kernel, 0, sizeof(cl_mem), (void *)&temp.data)); |
||||
openCLSafeCall(clSetKernelArg(kernel, 1, sizeof(cl_mem), (void *)&left.data)); |
||||
openCLSafeCall(clSetKernelArg(kernel, 2, sizeof(cl_mem), (void *)&right.data)); |
||||
openCLSafeCall(clSetKernelArg(kernel, 3, sizeof(cl_int), (void *)&h)); |
||||
openCLSafeCall(clSetKernelArg(kernel, 4, sizeof(cl_int), (void *)&w)); |
||||
openCLSafeCall(clSetKernelArg(kernel, 5, sizeof(cl_int), (void *)&level)); |
||||
openCLSafeCall(clSetKernelArg(kernel, 6, sizeof(cl_int), (void *)&channels)); |
||||
openCLSafeCall(clSetKernelArg(kernel, 7, sizeof(cl_int), (void *)&msg_step)); |
||||
openCLSafeCall(clSetKernelArg(kernel, 8, sizeof(cl_float), (void *)&rthis.data_weight)); |
||||
openCLSafeCall(clSetKernelArg(kernel, 9, sizeof(cl_float), (void *)&rthis.max_data_term)); |
||||
openCLSafeCall(clSetKernelArg(kernel, 10, sizeof(cl_int), (void *)&cdisp_step1)); |
||||
openCLSafeCall(clSetKernelArg(kernel, 11, sizeof(cl_int), (void *)&rthis.min_disp_th)); |
||||
openCLSafeCall(clSetKernelArg(kernel, 12, sizeof(cl_int), (void *)&left.step)); |
||||
openCLSafeCall(clSetKernelArg(kernel, 13, sizeof(cl_int), (void *)&rthis.ndisp)); |
||||
openCLSafeCall(clEnqueueNDRangeKernel(clCxt->impl->clCmdQueue, kernel, 2, NULL, |
||||
globalThreads, localThreads, 0, NULL, NULL)); |
||||
|
||||
clFinish(clCxt->impl->clCmdQueue); |
||||
openCLSafeCall(clReleaseKernel(kernel)); |
||||
} |
||||
|
||||
static void init_data_cost_reduce_caller(const oclMat &left, const oclMat &right, oclMat &temp, |
||||
StereoConstantSpaceBP &rthis, |
||||
int msg_step, int h, int w, int level) |
||||
{ |
||||
Context *clCxt = left.clCxt; |
||||
int data_type = rthis.msg_type; |
||||
int channels = left.channels(); |
||||
int win_size = (int)std::pow(2.f, level); |
||||
|
||||
string kernelName = get_kernel_name("init_data_cost_reduce_", data_type); |
||||
|
||||
cl_kernel kernel = openCLGetKernelFromSource(clCxt, &stereocsbp, kernelName); |
||||
|
||||
const int threadsNum = 256; |
||||
size_t blockSize = threadsNum; |
||||
size_t localThreads[3] = {win_size, 1, threadsNum / win_size}; |
||||
size_t globalThreads[3] = {w *localThreads[0], |
||||
h *divUp(rthis.ndisp, localThreads[2]) * localThreads[1], 1 * localThreads[2] |
||||
}; |
||||
|
||||
int local_mem_size = threadsNum * sizeof(float); |
||||
int cdisp_step1 = msg_step * h; |
||||
|
||||
openCLVerifyKernel(clCxt, kernel, &blockSize, globalThreads, localThreads); |
||||
openCLSafeCall(clSetKernelArg(kernel, 0, sizeof(cl_mem), (void *)&temp.data)); |
||||
openCLSafeCall(clSetKernelArg(kernel, 1, sizeof(cl_mem), (void *)&left.data)); |
||||
openCLSafeCall(clSetKernelArg(kernel, 2, sizeof(cl_mem), (void *)&right.data)); |
||||
openCLSafeCall(clSetKernelArg(kernel, 3, local_mem_size, (void *)NULL)); |
||||
openCLSafeCall(clSetKernelArg(kernel, 4, sizeof(cl_int), (void *)&level)); |
||||
openCLSafeCall(clSetKernelArg(kernel, 5, sizeof(cl_int), (void *)&left.rows)); |
||||
openCLSafeCall(clSetKernelArg(kernel, 6, sizeof(cl_int), (void *)&left.cols)); |
||||
openCLSafeCall(clSetKernelArg(kernel, 7, sizeof(cl_int), (void *)&h)); |
||||
openCLSafeCall(clSetKernelArg(kernel, 8, sizeof(cl_int), (void *)&win_size)); |
||||
openCLSafeCall(clSetKernelArg(kernel, 9, sizeof(cl_int), (void *)&channels)); |
||||
openCLSafeCall(clSetKernelArg(kernel, 10, sizeof(cl_int), (void *)&rthis.ndisp)); |
||||
openCLSafeCall(clSetKernelArg(kernel, 11, sizeof(cl_int), (void *)&left.step)); |
||||
openCLSafeCall(clSetKernelArg(kernel, 12, sizeof(cl_float), (void *)&rthis.data_weight)); |
||||
openCLSafeCall(clSetKernelArg(kernel, 13, sizeof(cl_float), (void *)&rthis.max_data_term)); |
||||
openCLSafeCall(clSetKernelArg(kernel, 14, sizeof(cl_int), (void *)&rthis.min_disp_th)); |
||||
openCLSafeCall(clSetKernelArg(kernel, 15, sizeof(cl_int), (void *)&cdisp_step1)); |
||||
openCLSafeCall(clSetKernelArg(kernel, 16, sizeof(cl_int), (void *)&msg_step)); |
||||
openCLSafeCall(clEnqueueNDRangeKernel(clCxt->impl->clCmdQueue, kernel, 3, NULL, |
||||
globalThreads, localThreads, 0, NULL, NULL)); |
||||
|
||||
clFinish(clCxt->impl->clCmdQueue); |
||||
openCLSafeCall(clReleaseKernel(kernel)); |
||||
|
||||
} |
||||
|
||||
static void get_first_initial_local_caller(uchar *data_cost_selected, uchar *disp_selected_pyr, |
||||
oclMat &temp, StereoConstantSpaceBP &rthis, |
||||
int h, int w, int nr_plane, int msg_step) |
||||
{ |
||||
Context *clCxt = temp.clCxt; |
||||
int data_type = rthis.msg_type; |
||||
|
||||
string kernelName = get_kernel_name("get_first_k_initial_local_", data_type); |
||||
|
||||
cl_kernel kernel = openCLGetKernelFromSource(clCxt, &stereocsbp, kernelName); |
||||
|
||||
size_t blockSize = 256; |
||||
size_t localThreads[] = {32, 8}; |
||||
size_t globalThreads[] = {divUp(w, localThreads[0]) * localThreads[0], |
||||
divUp(h, localThreads[1]) * localThreads[1] |
||||
}; |
||||
|
||||
int disp_step = msg_step * h; |
||||
openCLVerifyKernel(clCxt, kernel, &blockSize, globalThreads, localThreads); |
||||
openCLSafeCall(clSetKernelArg(kernel, 0, sizeof(cl_mem), (void *)&data_cost_selected)); |
||||
openCLSafeCall(clSetKernelArg(kernel, 1, sizeof(cl_mem), (void *)&disp_selected_pyr)); |
||||
openCLSafeCall(clSetKernelArg(kernel, 2, sizeof(cl_mem), (void *)&temp.data)); |
||||
openCLSafeCall(clSetKernelArg(kernel, 3, sizeof(cl_int), (void *)&h)); |
||||
openCLSafeCall(clSetKernelArg(kernel, 4, sizeof(cl_int), (void *)&w)); |
||||
openCLSafeCall(clSetKernelArg(kernel, 5, sizeof(cl_int), (void *)&nr_plane)); |
||||
openCLSafeCall(clSetKernelArg(kernel, 6, sizeof(cl_int), (void *)&msg_step)); |
||||
openCLSafeCall(clSetKernelArg(kernel, 7, sizeof(cl_int), (void *)&disp_step)); |
||||
openCLSafeCall(clSetKernelArg(kernel, 8, sizeof(cl_int), (void *)&rthis.ndisp)); |
||||
openCLSafeCall(clEnqueueNDRangeKernel(clCxt->impl->clCmdQueue, kernel, 2, NULL, |
||||
globalThreads, localThreads, 0, NULL, NULL)); |
||||
|
||||
clFinish(clCxt->impl->clCmdQueue); |
||||
openCLSafeCall(clReleaseKernel(kernel)); |
||||
} |
||||
static void get_first_initial_global_caller(uchar *data_cost_selected, uchar *disp_selected_pyr, |
||||
oclMat &temp, StereoConstantSpaceBP &rthis, |
||||
int h, int w, int nr_plane, int msg_step) |
||||
{ |
||||
Context *clCxt = temp.clCxt; |
||||
int data_type = rthis.msg_type; |
||||
|
||||
string kernelName = get_kernel_name("get_first_k_initial_global_", data_type); |
||||
|
||||
cl_kernel kernel = openCLGetKernelFromSource(clCxt, &stereocsbp, kernelName); |
||||
|
||||
size_t blockSize = 256; |
||||
size_t localThreads[] = {32, 8}; |
||||
size_t globalThreads[] = {divUp(w, localThreads[0]) * localThreads[0], |
||||
divUp(h, localThreads[1]) * localThreads[1] |
||||
}; |
||||
|
||||
int disp_step = msg_step * h; |
||||
openCLVerifyKernel(clCxt, kernel, &blockSize, globalThreads, localThreads); |
||||
openCLSafeCall(clSetKernelArg(kernel, 0, sizeof(cl_mem), (void *)&data_cost_selected)); |
||||
openCLSafeCall(clSetKernelArg(kernel, 1, sizeof(cl_mem), (void *)&disp_selected_pyr)); |
||||
openCLSafeCall(clSetKernelArg(kernel, 2, sizeof(cl_mem), (void *)&temp.data)); |
||||
openCLSafeCall(clSetKernelArg(kernel, 3, sizeof(cl_int), (void *)&h)); |
||||
openCLSafeCall(clSetKernelArg(kernel, 4, sizeof(cl_int), (void *)&w)); |
||||
openCLSafeCall(clSetKernelArg(kernel, 5, sizeof(cl_int), (void *)&nr_plane)); |
||||
openCLSafeCall(clSetKernelArg(kernel, 6, sizeof(cl_int), (void *)&msg_step)); |
||||
openCLSafeCall(clSetKernelArg(kernel, 7, sizeof(cl_int), (void *)&disp_step)); |
||||
openCLSafeCall(clSetKernelArg(kernel, 8, sizeof(cl_int), (void *)&rthis.ndisp)); |
||||
openCLSafeCall(clEnqueueNDRangeKernel(clCxt->impl->clCmdQueue, kernel, 2, NULL, |
||||
globalThreads, localThreads, 0, NULL, NULL)); |
||||
|
||||
clFinish(clCxt->impl->clCmdQueue); |
||||
openCLSafeCall(clReleaseKernel(kernel)); |
||||
} |
||||
|
||||
void init_data_cost(const oclMat &left, const oclMat &right, oclMat &temp, StereoConstantSpaceBP &rthis, |
||||
uchar *disp_selected_pyr, uchar *data_cost_selected, |
||||
size_t msg_step, int h, int w, int level, int nr_plane) |
||||
{ |
||||
|
||||
if(level <= 1) |
||||
init_data_cost_caller(left, right, temp, rthis, msg_step, h, w, level); |
||||
else |
||||
init_data_cost_reduce_caller(left, right, temp, rthis, msg_step, h, w, level); |
||||
|
||||
if(rthis.use_local_init_data_cost == true) |
||||
get_first_initial_local_caller(data_cost_selected, disp_selected_pyr, temp, rthis, h, w, |
||||
nr_plane, msg_step); |
||||
else |
||||
get_first_initial_global_caller(data_cost_selected, disp_selected_pyr, temp, rthis, h, w, |
||||
nr_plane, msg_step); |
||||
} |
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
///////////////////////////////////compute_data_cost//////////////////////////////////////////////
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
static void compute_data_cost_caller(uchar *disp_selected_pyr, uchar *data_cost, |
||||
StereoConstantSpaceBP &rthis, int msg_step1, |
||||
int msg_step2, const oclMat &left, const oclMat &right, int h, |
||||
int w, int h2, int level, int nr_plane) |
||||
{ |
||||
Context *clCxt = left.clCxt; |
||||
int channels = left.channels(); |
||||
int data_type = rthis.msg_type; |
||||
|
||||
string kernelName = get_kernel_name("compute_data_cost_", data_type); |
||||
|
||||
cl_kernel kernel = openCLGetKernelFromSource(clCxt, &stereocsbp, kernelName); |
||||
|
||||
size_t blockSize = 256; |
||||
size_t localThreads[] = {32, 8}; |
||||
size_t globalThreads[] = {divUp(w, localThreads[0]) * localThreads[0], |
||||
divUp(h, localThreads[1]) * localThreads[1] |
||||
}; |
||||
|
||||
int disp_step1 = msg_step1 * h; |
||||
int disp_step2 = msg_step2 * h2; |
||||
openCLVerifyKernel(clCxt, kernel, &blockSize, globalThreads, localThreads); |
||||
openCLSafeCall(clSetKernelArg(kernel, 0, sizeof(cl_mem), (void *)&disp_selected_pyr)); |
||||
openCLSafeCall(clSetKernelArg(kernel, 1, sizeof(cl_mem), (void *)&data_cost)); |
||||
openCLSafeCall(clSetKernelArg(kernel, 2, sizeof(cl_mem), (void *)&left.data)); |
||||
openCLSafeCall(clSetKernelArg(kernel, 3, sizeof(cl_mem), (void *)&right.data)); |
||||
openCLSafeCall(clSetKernelArg(kernel, 4, sizeof(cl_int), (void *)&h)); |
||||
openCLSafeCall(clSetKernelArg(kernel, 5, sizeof(cl_int), (void *)&w)); |
||||
openCLSafeCall(clSetKernelArg(kernel, 6, sizeof(cl_int), (void *)&level)); |
||||
openCLSafeCall(clSetKernelArg(kernel, 7, sizeof(cl_int), (void *)&nr_plane)); |
||||
openCLSafeCall(clSetKernelArg(kernel, 8, sizeof(cl_int), (void *)&channels)); |
||||
openCLSafeCall(clSetKernelArg(kernel, 9, sizeof(cl_int), (void *)&msg_step1)); |
||||
openCLSafeCall(clSetKernelArg(kernel, 10, sizeof(cl_int), (void *)&msg_step2)); |
||||
openCLSafeCall(clSetKernelArg(kernel, 11, sizeof(cl_int), (void *)&disp_step1)); |
||||
openCLSafeCall(clSetKernelArg(kernel, 12, sizeof(cl_int), (void *)&disp_step2)); |
||||
openCLSafeCall(clSetKernelArg(kernel, 13, sizeof(cl_float), (void *)&rthis.data_weight)); |
||||
openCLSafeCall(clSetKernelArg(kernel, 14, sizeof(cl_float), (void *)&rthis.max_data_term)); |
||||
openCLSafeCall(clSetKernelArg(kernel, 15, sizeof(cl_int), (void *)&left.step)); |
||||
openCLSafeCall(clSetKernelArg(kernel, 16, sizeof(cl_int), (void *)&rthis.min_disp_th)); |
||||
openCLSafeCall(clEnqueueNDRangeKernel(clCxt->impl->clCmdQueue, kernel, 2, NULL, |
||||
globalThreads, localThreads, 0, NULL, NULL)); |
||||
|
||||
clFinish(clCxt->impl->clCmdQueue); |
||||
openCLSafeCall(clReleaseKernel(kernel)); |
||||
} |
||||
static void compute_data_cost_reduce_caller(uchar *disp_selected_pyr, uchar *data_cost, |
||||
StereoConstantSpaceBP &rthis, int msg_step1, |
||||
int msg_step2, const oclMat &left, const oclMat &right, int h, |
||||
int w, int h2, int level, int nr_plane) |
||||
{ |
||||
Context *clCxt = left.clCxt; |
||||
int data_type = rthis.msg_type; |
||||
int channels = left.channels(); |
||||
int win_size = (int)std::pow(2.f, level); |
||||
|
||||
string kernelName = get_kernel_name("compute_data_cost_reduce_", data_type); |
||||
|
||||
cl_kernel kernel = openCLGetKernelFromSource(clCxt, &stereocsbp, kernelName); |
||||
|
||||
const size_t threadsNum = 256; |
||||
size_t blockSize = threadsNum; |
||||
size_t localThreads[3] = {win_size, 1, threadsNum / win_size}; |
||||
size_t globalThreads[3] = {w *localThreads[0], |
||||
h *divUp(nr_plane, localThreads[2]) * localThreads[1], 1 * localThreads[2] |
||||
}; |
||||
|
||||
int disp_step1 = msg_step1 * h; |
||||
int disp_step2 = msg_step2 * h2; |
||||
size_t local_mem_size = threadsNum * sizeof(float); |
||||
openCLVerifyKernel(clCxt, kernel, &blockSize, globalThreads, localThreads); |
||||
openCLSafeCall(clSetKernelArg(kernel, 0, sizeof(cl_mem), (void *)&disp_selected_pyr)); |
||||
openCLSafeCall(clSetKernelArg(kernel, 1, sizeof(cl_mem), (void *)&data_cost)); |
||||
openCLSafeCall(clSetKernelArg(kernel, 2, sizeof(cl_mem), (void *)&left.data)); |
||||
openCLSafeCall(clSetKernelArg(kernel, 3, sizeof(cl_mem), (void *)&right.data)); |
||||
openCLSafeCall(clSetKernelArg(kernel, 4, local_mem_size, (void *)NULL)); |
||||
openCLSafeCall(clSetKernelArg(kernel, 5, sizeof(cl_int), (void *)&level)); |
||||
openCLSafeCall(clSetKernelArg(kernel, 6, sizeof(cl_int), (void *)&left.rows)); |
||||
openCLSafeCall(clSetKernelArg(kernel, 7, sizeof(cl_int), (void *)&left.cols)); |
||||
openCLSafeCall(clSetKernelArg(kernel, 8, sizeof(cl_int), (void *)&h)); |
||||
openCLSafeCall(clSetKernelArg(kernel, 9, sizeof(cl_int), (void *)&nr_plane)); |
||||
openCLSafeCall(clSetKernelArg(kernel, 10, sizeof(cl_int), (void *)&channels)); |
||||
openCLSafeCall(clSetKernelArg(kernel, 11, sizeof(cl_int), (void *)&win_size)); |
||||
openCLSafeCall(clSetKernelArg(kernel, 12, sizeof(cl_int), (void *)&msg_step1)); |
||||
openCLSafeCall(clSetKernelArg(kernel, 13, sizeof(cl_int), (void *)&msg_step2)); |
||||
openCLSafeCall(clSetKernelArg(kernel, 14, sizeof(cl_int), (void *)&disp_step1)); |
||||
openCLSafeCall(clSetKernelArg(kernel, 15, sizeof(cl_int), (void *)&disp_step2)); |
||||
openCLSafeCall(clSetKernelArg(kernel, 16, sizeof(cl_float), (void *)&rthis.data_weight)); |
||||
openCLSafeCall(clSetKernelArg(kernel, 17, sizeof(cl_float), (void *)&rthis.max_data_term)); |
||||
openCLSafeCall(clSetKernelArg(kernel, 18, sizeof(cl_int), (void *)&left.step)); |
||||
openCLSafeCall(clSetKernelArg(kernel, 19, sizeof(cl_int), (void *)&rthis.min_disp_th)); |
||||
openCLSafeCall(clEnqueueNDRangeKernel(clCxt->impl->clCmdQueue, kernel, 3, NULL, |
||||
globalThreads, localThreads, 0, NULL, NULL)); |
||||
|
||||
clFinish(clCxt->impl->clCmdQueue); |
||||
openCLSafeCall(clReleaseKernel(kernel)); |
||||
} |
||||
void compute_data_cost(uchar *disp_selected_pyr, uchar *data_cost, StereoConstantSpaceBP &rthis, |
||||
int msg_step1, int msg_step2, const oclMat &left, const oclMat &right, int h, int w, |
||||
int h2, int level, int nr_plane) |
||||
{ |
||||
if(level <= 1) |
||||
compute_data_cost_caller(disp_selected_pyr, data_cost, rthis, msg_step1, msg_step2, |
||||
left, right, h, w, h2, level, nr_plane); |
||||
else |
||||
compute_data_cost_reduce_caller(disp_selected_pyr, data_cost, rthis, msg_step1, msg_step2, |
||||
left, right, h, w, h2, level, nr_plane); |
||||
} |
||||
////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
//////////////////////////////////////init message//////////////////////////////////////////////
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
void init_message(uchar *u_new, uchar *d_new, uchar *l_new, uchar *r_new, |
||||
uchar *u_cur, uchar *d_cur, uchar *l_cur, uchar *r_cur, |
||||
uchar *disp_selected_pyr_new, uchar *disp_selected_pyr_cur, |
||||
uchar *data_cost_selected, uchar *data_cost, oclMat &temp, StereoConstantSpaceBP rthis, |
||||
size_t msg_step1, size_t msg_step2, int h, int w, int nr_plane, |
||||
int h2, int w2, int nr_plane2) |
||||
{ |
||||
Context *clCxt = temp.clCxt; |
||||
int data_type = rthis.msg_type; |
||||
|
||||
string kernelName = get_kernel_name("init_message_", data_type); |
||||
|
||||
cl_kernel kernel = openCLGetKernelFromSource(clCxt, &stereocsbp, kernelName); |
||||
|
||||
size_t blockSize = 256; |
||||
size_t localThreads[] = {32, 8}; |
||||
size_t globalThreads[] = {divUp(w, localThreads[0]) * localThreads[0], |
||||
divUp(h, localThreads[1]) * localThreads[1] |
||||
}; |
||||
|
||||
int disp_step1 = msg_step1 * h; |
||||
int disp_step2 = msg_step2 * h2; |
||||
openCLVerifyKernel(clCxt, kernel, &blockSize, globalThreads, localThreads); |
||||
openCLSafeCall(clSetKernelArg(kernel, 0, sizeof(cl_mem), (void *)&u_new)); |
||||
openCLSafeCall(clSetKernelArg(kernel, 1, sizeof(cl_mem), (void *)&d_new)); |
||||
openCLSafeCall(clSetKernelArg(kernel, 2, sizeof(cl_mem), (void *)&l_new)); |
||||
openCLSafeCall(clSetKernelArg(kernel, 3, sizeof(cl_mem), (void *)&r_new)); |
||||
openCLSafeCall(clSetKernelArg(kernel, 4, sizeof(cl_mem), (void *)&u_cur)); |
||||
openCLSafeCall(clSetKernelArg(kernel, 5, sizeof(cl_mem), (void *)&d_cur)); |
||||
openCLSafeCall(clSetKernelArg(kernel, 6, sizeof(cl_mem), (void *)&l_cur)); |
||||
openCLSafeCall(clSetKernelArg(kernel, 7, sizeof(cl_mem), (void *)&r_cur)); |
||||
openCLSafeCall(clSetKernelArg(kernel, 8, sizeof(cl_mem), (void *)&temp.data)); |
||||
openCLSafeCall(clSetKernelArg(kernel, 9, sizeof(cl_mem), (void *)&disp_selected_pyr_new)); |
||||
openCLSafeCall(clSetKernelArg(kernel, 10, sizeof(cl_mem), (void *)&disp_selected_pyr_cur)); |
||||
openCLSafeCall(clSetKernelArg(kernel, 11, sizeof(cl_mem), (void *)&data_cost_selected)); |
||||
openCLSafeCall(clSetKernelArg(kernel, 12, sizeof(cl_mem), (void *)&data_cost)); |
||||
openCLSafeCall(clSetKernelArg(kernel, 13, sizeof(cl_int), (void *)&h)); |
||||
openCLSafeCall(clSetKernelArg(kernel, 14, sizeof(cl_int), (void *)&w)); |
||||
openCLSafeCall(clSetKernelArg(kernel, 15, sizeof(cl_int), (void *)&nr_plane)); |
||||
openCLSafeCall(clSetKernelArg(kernel, 16, sizeof(cl_int), (void *)&h2)); |
||||
openCLSafeCall(clSetKernelArg(kernel, 17, sizeof(cl_int), (void *)&w2)); |
||||
openCLSafeCall(clSetKernelArg(kernel, 18, sizeof(cl_int), (void *)&nr_plane2)); |
||||
openCLSafeCall(clSetKernelArg(kernel, 19, sizeof(cl_int), (void *)&disp_step1)); |
||||
openCLSafeCall(clSetKernelArg(kernel, 20, sizeof(cl_int), (void *)&disp_step2)); |
||||
openCLSafeCall(clSetKernelArg(kernel, 21, sizeof(cl_int), (void *)&msg_step1)); |
||||
openCLSafeCall(clSetKernelArg(kernel, 22, sizeof(cl_int), (void *)&msg_step2)); |
||||
openCLSafeCall(clEnqueueNDRangeKernel(clCxt->impl->clCmdQueue, kernel, 2, NULL, |
||||
globalThreads, localThreads, 0, NULL, NULL)); |
||||
|
||||
clFinish(clCxt->impl->clCmdQueue); |
||||
openCLSafeCall(clReleaseKernel(kernel)); |
||||
} |
||||
////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
///////////////////////////calc_all_iterations////////////////////////////////////////////////
|
||||
//////////////////////////////////////////////////////////////////////////////////////////////
|
||||
void calc_all_iterations_caller(uchar *u, uchar *d, uchar *l, uchar *r, uchar *data_cost_selected, |
||||
uchar *disp_selected_pyr, oclMat &temp, StereoConstantSpaceBP rthis, |
||||
int msg_step, int h, int w, int nr_plane, int i) |
||||
{ |
||||
Context *clCxt = temp.clCxt; |
||||
int data_type = rthis.msg_type; |
||||
|
||||
string kernelName = get_kernel_name("compute_message_", data_type); |
||||
|
||||
cl_kernel kernel = openCLGetKernelFromSource(clCxt, &stereocsbp, kernelName); |
||||
|
||||
size_t blockSize = 256; |
||||
size_t localThreads[] = {32, 8}; |
||||
size_t globalThreads[] = {divUp(w, (localThreads[0]) << 1) * localThreads[0], |
||||
divUp(h, localThreads[1]) * localThreads[1] |
||||
}; |
||||
|
||||
int disp_step = msg_step * h; |
||||
openCLVerifyKernel(clCxt, kernel, &blockSize, globalThreads, localThreads); |
||||
openCLSafeCall(clSetKernelArg(kernel, 0, sizeof(cl_mem), (void *)&u)); |
||||
openCLSafeCall(clSetKernelArg(kernel, 1, sizeof(cl_mem), (void *)&d)); |
||||
openCLSafeCall(clSetKernelArg(kernel, 2, sizeof(cl_mem), (void *)&l)); |
||||
openCLSafeCall(clSetKernelArg(kernel, 3, sizeof(cl_mem), (void *)&r)); |
||||
openCLSafeCall(clSetKernelArg(kernel, 4, sizeof(cl_mem), (void *)&data_cost_selected)); |
||||
openCLSafeCall(clSetKernelArg(kernel, 5, sizeof(cl_mem), (void *)&disp_selected_pyr)); |
||||
openCLSafeCall(clSetKernelArg(kernel, 6, sizeof(cl_mem), (void *)&temp.data)); |
||||
openCLSafeCall(clSetKernelArg(kernel, 7, sizeof(cl_int), (void *)&h)); |
||||
openCLSafeCall(clSetKernelArg(kernel, 8, sizeof(cl_int), (void *)&w)); |
||||
openCLSafeCall(clSetKernelArg(kernel, 9, sizeof(cl_int), (void *)&nr_plane)); |
||||
openCLSafeCall(clSetKernelArg(kernel, 10, sizeof(cl_int), (void *)&i)); |
||||
openCLSafeCall(clSetKernelArg(kernel, 11, sizeof(cl_float), (void *)&rthis.max_disc_term)); |
||||
openCLSafeCall(clSetKernelArg(kernel, 12, sizeof(cl_int), (void *)&disp_step)); |
||||
openCLSafeCall(clSetKernelArg(kernel, 13, sizeof(cl_int), (void *)&msg_step)); |
||||
openCLSafeCall(clSetKernelArg(kernel, 14, sizeof(cl_float), (void *)&rthis.disc_single_jump)); |
||||
openCLSafeCall(clEnqueueNDRangeKernel(clCxt->impl->clCmdQueue, kernel, 2, NULL, |
||||
globalThreads, localThreads, 0, NULL, NULL)); |
||||
|
||||
clFinish(clCxt->impl->clCmdQueue); |
||||
openCLSafeCall(clReleaseKernel(kernel)); |
||||
} |
||||
void calc_all_iterations(uchar *u, uchar *d, uchar *l, uchar *r, uchar *data_cost_selected, |
||||
uchar *disp_selected_pyr, oclMat &temp, StereoConstantSpaceBP rthis, |
||||
int msg_step, int h, int w, int nr_plane) |
||||
{ |
||||
for(int t = 0; t < rthis.iters; t++) |
||||
calc_all_iterations_caller(u, d, l, r, data_cost_selected, disp_selected_pyr, temp, rthis, |
||||
msg_step, h, w, nr_plane, t & 1); |
||||
} |
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////
|
||||
//////////////////////////compute_disp////////////////////////////////////////////////////////
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////
|
||||
void compute_disp(uchar *u, uchar *d, uchar *l, uchar *r, uchar *data_cost_selected, |
||||
uchar *disp_selected_pyr, StereoConstantSpaceBP &rthis, size_t msg_step, |
||||
oclMat &disp, int nr_plane) |
||||
{ |
||||
Context *clCxt = disp.clCxt; |
||||
int data_type = rthis.msg_type; |
||||
|
||||
string kernelName = get_kernel_name("compute_disp_", data_type); |
||||
|
||||
cl_kernel kernel = openCLGetKernelFromSource(clCxt, &stereocsbp, kernelName); |
||||
|
||||
size_t blockSize = 256; |
||||
size_t localThreads[] = {32, 8}; |
||||
size_t globalThreads[] = {divUp(disp.cols, localThreads[0]) * localThreads[0], |
||||
divUp(disp.rows, localThreads[1]) * localThreads[1] |
||||
}; |
||||
|
||||
int step_size = disp.step / disp.elemSize(); |
||||
int disp_step = disp.rows * msg_step; |
||||
openCLVerifyKernel(clCxt, kernel, &blockSize, globalThreads, localThreads); |
||||
openCLSafeCall(clSetKernelArg(kernel, 0, sizeof(cl_mem), (void *)&u)); |
||||
openCLSafeCall(clSetKernelArg(kernel, 1, sizeof(cl_mem), (void *)&d)); |
||||
openCLSafeCall(clSetKernelArg(kernel, 2, sizeof(cl_mem), (void *)&l)); |
||||
openCLSafeCall(clSetKernelArg(kernel, 3, sizeof(cl_mem), (void *)&r)); |
||||
openCLSafeCall(clSetKernelArg(kernel, 4, sizeof(cl_mem), (void *)&data_cost_selected)); |
||||
openCLSafeCall(clSetKernelArg(kernel, 5, sizeof(cl_mem), (void *)&disp_selected_pyr)); |
||||
openCLSafeCall(clSetKernelArg(kernel, 6, sizeof(cl_mem), (void *)&disp.data)); |
||||
openCLSafeCall(clSetKernelArg(kernel, 7, sizeof(cl_int), (void *)&step_size)); |
||||
openCLSafeCall(clSetKernelArg(kernel, 8, sizeof(cl_int), (void *)&disp.cols)); |
||||
openCLSafeCall(clSetKernelArg(kernel, 9, sizeof(cl_int), (void *)&disp.rows)); |
||||
openCLSafeCall(clSetKernelArg(kernel, 10, sizeof(cl_int), (void *)&nr_plane)); |
||||
openCLSafeCall(clSetKernelArg(kernel, 11, sizeof(cl_int), (void *)&msg_step)); |
||||
openCLSafeCall(clSetKernelArg(kernel, 12, sizeof(cl_int), (void *)&disp_step)); |
||||
openCLSafeCall(clEnqueueNDRangeKernel(clCxt->impl->clCmdQueue, kernel, 2, NULL, |
||||
globalThreads, localThreads, 0, NULL, NULL)); |
||||
|
||||
clFinish(clCxt->impl->clCmdQueue); |
||||
openCLSafeCall(clReleaseKernel(kernel)); |
||||
} |
||||
} |
||||
} |
||||
} |
||||
namespace |
||||
{ |
||||
const float DEFAULT_MAX_DATA_TERM = 30.0f; |
||||
const float DEFAULT_DATA_WEIGHT = 1.0f; |
||||
const float DEFAULT_MAX_DISC_TERM = 160.0f; |
||||
const float DEFAULT_DISC_SINGLE_JUMP = 10.0f; |
||||
|
||||
template<typename T> |
||||
void print_gpu_mat(const oclMat &mat) |
||||
{ |
||||
T *data_1 = new T[mat.rows * mat.cols * mat.channels()]; |
||||
Context *clCxt = mat.clCxt; |
||||
int status = clEnqueueReadBuffer(clCxt -> impl->clCmdQueue, (cl_mem)mat.data, CL_TRUE, 0, |
||||
mat.rows * mat.cols * mat.channels() * sizeof(T), data_1, 0, NULL, NULL); |
||||
|
||||
if(status != CL_SUCCESS) |
||||
cout << "error " << status << endl; |
||||
|
||||
cout << ".........................................................." << endl; |
||||
cout << "elemSize() " << mat.elemSize() << endl; |
||||
cout << "elemSize() " << mat.elemSize1() << endl; |
||||
cout << "channels: " << mat.channels() << endl; |
||||
cout << "rows: " << mat.rows << endl; |
||||
cout << "cols: " << mat.cols << endl; |
||||
|
||||
for(int i = 0; i < 100; i++) |
||||
{ |
||||
for(int j = 0; j < 30; j++) |
||||
{ |
||||
cout << (int)data_1[i * mat.cols * mat.channels() + j] << " "; |
||||
} |
||||
cout << endl; |
||||
} |
||||
} |
||||
} |
||||
|
||||
|
||||
void cv::ocl::StereoConstantSpaceBP::estimateRecommendedParams(int width, int height, int &ndisp, int &iters, int &levels, int &nr_plane) |
||||
{ |
||||
ndisp = (int) ((float) width / 3.14f); |
||||
if ((ndisp & 1) != 0) |
||||
ndisp++; |
||||
|
||||
int mm = ::max(width, height); |
||||
iters = mm / 100 + ((mm > 1200) ? - 4 : 4); |
||||
|
||||
levels = (int)::log(static_cast<double>(mm)) * 2 / 3; |
||||
if (levels == 0) levels++; |
||||
|
||||
nr_plane = (int) ((float) ndisp / std::pow(2.0, levels + 1)); |
||||
} |
||||
|
||||
cv::ocl::StereoConstantSpaceBP::StereoConstantSpaceBP(int ndisp_, int iters_, int levels_, int nr_plane_, |
||||
int msg_type_) |
||||
|
||||
: ndisp(ndisp_), iters(iters_), levels(levels_), nr_plane(nr_plane_), |
||||
max_data_term(DEFAULT_MAX_DATA_TERM), data_weight(DEFAULT_DATA_WEIGHT), |
||||
max_disc_term(DEFAULT_MAX_DISC_TERM), disc_single_jump(DEFAULT_DISC_SINGLE_JUMP), min_disp_th(0), |
||||
msg_type(msg_type_), use_local_init_data_cost(true) |
||||
{ |
||||
CV_Assert(msg_type_ == CV_32F || msg_type_ == CV_16S); |
||||
} |
||||
|
||||
|
||||
cv::ocl::StereoConstantSpaceBP::StereoConstantSpaceBP(int ndisp_, int iters_, int levels_, int nr_plane_, |
||||
float max_data_term_, float data_weight_, float max_disc_term_, float disc_single_jump_, |
||||
int min_disp_th_, int msg_type_) |
||||
: ndisp(ndisp_), iters(iters_), levels(levels_), nr_plane(nr_plane_), |
||||
max_data_term(max_data_term_), data_weight(data_weight_), |
||||
max_disc_term(max_disc_term_), disc_single_jump(disc_single_jump_), min_disp_th(min_disp_th_), |
||||
msg_type(msg_type_), use_local_init_data_cost(true) |
||||
{ |
||||
CV_Assert(msg_type_ == CV_32F || msg_type_ == CV_16S); |
||||
} |
||||
|
||||
template<class T> |
||||
static void csbp_operator(StereoConstantSpaceBP &rthis, oclMat u[2], oclMat d[2], oclMat l[2], oclMat r[2], |
||||
oclMat disp_selected_pyr[2], oclMat &data_cost, oclMat &data_cost_selected, |
||||
oclMat &temp, oclMat &out, const oclMat &left, const oclMat &right, oclMat &disp) |
||||
{ |
||||
CV_DbgAssert(0 < rthis.ndisp && 0 < rthis.iters && 0 < rthis.levels && 0 < rthis.nr_plane |
||||
&& left.rows == right.rows && left.cols == right.cols && left.type() == right.type()); |
||||
|
||||
CV_Assert(rthis.levels <= 8 && (left.type() == CV_8UC1 || left.type() == CV_8UC3)); |
||||
|
||||
const Scalar zero = Scalar::all(0); |
||||
|
||||
////////////////////////////////////Init///////////////////////////////////////////////////
|
||||
int rows = left.rows; |
||||
int cols = left.cols; |
||||
|
||||
rthis.levels = min(rthis.levels, int(log((double)rthis.ndisp) / log(2.0))); |
||||
int levels = rthis.levels; |
||||
|
||||
AutoBuffer<int> buf(levels * 4); |
||||
|
||||
int *cols_pyr = buf; |
||||
int *rows_pyr = cols_pyr + levels; |
||||
int *nr_plane_pyr = rows_pyr + levels; |
||||
int *step_pyr = nr_plane_pyr + levels; |
||||
|
||||
cols_pyr[0] = cols; |
||||
rows_pyr[0] = rows; |
||||
nr_plane_pyr[0] = rthis.nr_plane; |
||||
|
||||
const int n = 64; |
||||
step_pyr[0] = alignSize(cols * sizeof(T), n) / sizeof(T); |
||||
for (int i = 1; i < levels; i++) |
||||
{ |
||||
cols_pyr[i] = (cols_pyr[i-1] + 1) / 2; |
||||
rows_pyr[i] = (rows_pyr[i-1] + 1) / 2; |
||||
|
||||
nr_plane_pyr[i] = nr_plane_pyr[i-1] * 2; |
||||
|
||||
step_pyr[i] = alignSize(cols_pyr[i] * sizeof(T), n) / sizeof(T); |
||||
} |
||||
|
||||
Size msg_size(step_pyr[0], rows * nr_plane_pyr[0]); |
||||
Size data_cost_size(step_pyr[0], rows * nr_plane_pyr[0] * 2); |
||||
|
||||
u[0].create(msg_size, DataType<T>::type); |
||||
d[0].create(msg_size, DataType<T>::type); |
||||
l[0].create(msg_size, DataType<T>::type); |
||||
r[0].create(msg_size, DataType<T>::type); |
||||
|
||||
u[1].create(msg_size, DataType<T>::type); |
||||
d[1].create(msg_size, DataType<T>::type); |
||||
l[1].create(msg_size, DataType<T>::type); |
||||
r[1].create(msg_size, DataType<T>::type); |
||||
|
||||
disp_selected_pyr[0].create(msg_size, DataType<T>::type); |
||||
disp_selected_pyr[1].create(msg_size, DataType<T>::type); |
||||
|
||||
data_cost.create(data_cost_size, DataType<T>::type); |
||||
data_cost_selected.create(msg_size, DataType<T>::type); |
||||
|
||||
step_pyr[0] = data_cost.step / sizeof(T); |
||||
|
||||
Size temp_size = data_cost_size; |
||||
if (data_cost_size.width * data_cost_size.height < step_pyr[levels - 1] * rows_pyr[levels - 1] * rthis.ndisp) |
||||
temp_size = Size(step_pyr[levels - 1], rows_pyr[levels - 1] * rthis.ndisp); |
||||
|
||||
temp.create(temp_size, DataType<T>::type); |
||||
|
||||
///////////////////////////////// Compute////////////////////////////////////////////////
|
||||
|
||||
//csbp::load_constants(rthis.ndisp, rthis.max_data_term, rthis.data_weight,
|
||||
// rthis.max_disc_term, rthis.disc_single_jump, rthis.min_disp_th, left, right, temp);
|
||||
|
||||
l[0] = zero; |
||||
d[0] = zero; |
||||
r[0] = zero; |
||||
u[0] = zero; |
||||
|
||||
l[1] = zero; |
||||
d[1] = zero; |
||||
r[1] = zero; |
||||
u[1] = zero; |
||||
|
||||
data_cost = zero; |
||||
data_cost_selected = zero; |
||||
|
||||
int cur_idx = 0; |
||||
|
||||
for (int i = levels - 1; i >= 0; i--) |
||||
{ |
||||
if (i == levels - 1) |
||||
{ |
||||
cv::ocl::stereoCSBP::init_data_cost(left, right, temp, rthis, disp_selected_pyr[cur_idx].ptr(), |
||||
data_cost_selected.ptr(), step_pyr[i], rows_pyr[i], cols_pyr[i], |
||||
i, nr_plane_pyr[i]); |
||||
} |
||||
else |
||||
{ |
||||
cv::ocl::stereoCSBP::compute_data_cost(disp_selected_pyr[cur_idx].ptr(), data_cost.ptr(), rthis, step_pyr[i], |
||||
step_pyr[i+1], left, right, rows_pyr[i], cols_pyr[i], rows_pyr[i+1], i, |
||||
nr_plane_pyr[i+1]); |
||||
|
||||
|
||||
int new_idx = (cur_idx + 1) & 1; |
||||
|
||||
cv::ocl::stereoCSBP::init_message(u[new_idx].ptr(), d[new_idx].ptr(), l[new_idx].ptr(), r[new_idx].ptr(), |
||||
u[cur_idx].ptr(), d[cur_idx].ptr(), l[cur_idx].ptr(), r[cur_idx].ptr(), |
||||
disp_selected_pyr[new_idx].ptr(), disp_selected_pyr[cur_idx].ptr(), |
||||
data_cost_selected.ptr(), data_cost.ptr(), temp, rthis, step_pyr[i], |
||||
step_pyr[i+1], rows_pyr[i], cols_pyr[i], nr_plane_pyr[i], rows_pyr[i+1], |
||||
cols_pyr[i+1], nr_plane_pyr[i+1]); |
||||
|
||||
cur_idx = new_idx; |
||||
} |
||||
|
||||
cv::ocl::stereoCSBP::calc_all_iterations(u[cur_idx].ptr(), d[cur_idx].ptr(), l[cur_idx].ptr(), r[cur_idx].ptr(), |
||||
data_cost_selected.ptr(), disp_selected_pyr[cur_idx].ptr(), temp, |
||||
rthis, step_pyr[i], rows_pyr[i], cols_pyr[i], nr_plane_pyr[i]); |
||||
} |
||||
|
||||
|
||||
if (disp.empty()) |
||||
disp.create(rows, cols, CV_16S); |
||||
|
||||
out = ((disp.type() == CV_16S) ? disp : (out.create(rows, cols, CV_16S), out)); |
||||
out = zero; |
||||
|
||||
stereoCSBP::compute_disp(u[cur_idx].ptr(), d[cur_idx].ptr(), l[cur_idx].ptr(), r[cur_idx].ptr(), |
||||
data_cost_selected.ptr(), disp_selected_pyr[cur_idx].ptr(), rthis, step_pyr[0], |
||||
out, nr_plane_pyr[0]); |
||||
|
||||
|
||||
if (disp.type() != CV_16S) |
||||
out.convertTo(disp, disp.type()); |
||||
} |
||||
|
||||
|
||||
typedef void (*csbp_operator_t)(StereoConstantSpaceBP &rthis, oclMat u[2], oclMat d[2], oclMat l[2], oclMat r[2], |
||||
oclMat disp_selected_pyr[2], oclMat &data_cost, oclMat &data_cost_selected, |
||||
oclMat &temp, oclMat &out, const oclMat &left, const oclMat &right, oclMat &disp); |
||||
|
||||
const static csbp_operator_t operators[] = {0, 0, 0, csbp_operator<short>, 0, csbp_operator<float>, 0, 0}; |
||||
|
||||
void cv::ocl::StereoConstantSpaceBP::operator()(const oclMat &left, const oclMat &right, oclMat &disp) |
||||
{ |
||||
|
||||
CV_Assert(msg_type == CV_32F || msg_type == CV_16S); |
||||
operators[msg_type](*this, u, d, l, r, disp_selected_pyr, data_cost, data_cost_selected, temp, out, |
||||
left, right, disp); |
||||
} |
||||
|
||||
#endif /* !defined (HAVE_OPENCL) */ |
@ -1,291 +0,0 @@ |
||||
/*M///////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
|
||||
//
|
||||
// By downloading, copying, installing or using the software you agree to this license.
|
||||
// If you do not agree to this license, do not download, install,
|
||||
// copy or use the software.
|
||||
//
|
||||
//
|
||||
// License Agreement
|
||||
// For Open Source Computer Vision Library
|
||||
//
|
||||
// Copyright (C) 2010-2012, Institute Of Software Chinese Academy Of Science, all rights reserved.
|
||||
// Copyright (C) 2010-2012, Advanced Micro Devices, Inc., all rights reserved.
|
||||
// Third party copyrights are property of their respective owners.
|
||||
//
|
||||
// @Authors
|
||||
// Jia Haipeng, jiahaipeng95@gmail.com
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
// are permitted provided that the following conditions are met:
|
||||
//
|
||||
// * Redistribution's of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
//
|
||||
// * Redistribution's in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other oclMaterials provided with the distribution.
|
||||
//
|
||||
// * The name of the copyright holders may not be used to endorse or promote products
|
||||
// derived from this software without specific prior written permission.
|
||||
//
|
||||
// This software is provided by the copyright holders and contributors "as is" and
|
||||
// any express or implied warranties, including, but not limited to, the implied
|
||||
// warranties of merchantability and fitness for a particular purpose are disclaimed.
|
||||
// In no event shall the Intel Corporation or contributors be liable for any direct,
|
||||
// indirect, incidental, special, exemplary, or consequential damages
|
||||
// (including, but not limited to, procurement of substitute goods or services;
|
||||
// loss of use, data, or profits; or business interruption) however caused
|
||||
// and on any theory of liability, whether in contract, strict liability,
|
||||
// or tort (including negligence or otherwise) arising in any way out of
|
||||
// the use of this software, even if advised of the possibility of such damage.
|
||||
//
|
||||
//M*/
|
||||
|
||||
#include "precomp.hpp" |
||||
#include <vector> |
||||
|
||||
using namespace cv; |
||||
using namespace cv::ocl; |
||||
using namespace std; |
||||
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
///////////////// stereoBM /////////////////////////////////////////////
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#if !defined (HAVE_OPENCL) |
||||
|
||||
namespace cv |
||||
{ |
||||
namespace ocl |
||||
{ |
||||
cv::ocl::StereoBM_GPU::StereoBM_GPU() |
||||
{ |
||||
throw_nogpu(); |
||||
} |
||||
cv::ocl::StereoBM_GPU::StereoBM_GPU(int, int, int) |
||||
{ |
||||
throw_nogpu(); |
||||
} |
||||
bool cv::ocl::StereoBM_GPU::checkIfGpuCallReasonable() |
||||
{ |
||||
throw_nogpu(); |
||||
return false; |
||||
} |
||||
void cv::ocl::StereoBM_GPU::operator() ( const oclMat &, const oclMat &, oclMat &) |
||||
{ |
||||
throw_nogpu(); |
||||
} |
||||
} |
||||
} |
||||
|
||||
#else /* !defined (HAVE_OPENCL) */ |
||||
|
||||
namespace cv |
||||
{ |
||||
namespace ocl |
||||
{ |
||||
|
||||
///////////////////////////OpenCL kernel strings///////////////////////////
|
||||
extern const char *stereobm; |
||||
|
||||
} |
||||
} |
||||
namespace cv |
||||
{ |
||||
namespace ocl |
||||
{ |
||||
namespace stereoBM |
||||
{ |
||||
/////////////////////////////////////////////////////////////////////////
|
||||
//////////////////////////prefilter_xsbel////////////////////////////////
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
void prefilter_xsobel(const oclMat &input, oclMat &output, int prefilterCap) |
||||
{ |
||||
Context *clCxt = input.clCxt; |
||||
|
||||
string kernelName = "prefilter_xsobel"; |
||||
cl_kernel kernel = openCLGetKernelFromSource(clCxt, &stereobm, kernelName); |
||||
|
||||
size_t blockSize = 1; |
||||
size_t globalThreads[3] = { input.cols, input.rows, 1 }; |
||||
size_t localThreads[3] = { blockSize, blockSize, 1 }; |
||||
|
||||
openCLVerifyKernel(clCxt, kernel, &blockSize, globalThreads, localThreads); |
||||
openCLSafeCall(clSetKernelArg(kernel, 0, sizeof(cl_mem), (void *)&input.data)); |
||||
openCLSafeCall(clSetKernelArg(kernel, 1, sizeof(cl_mem), (void *)&output.data)); |
||||
openCLSafeCall(clSetKernelArg(kernel, 2, sizeof(cl_int), (void *)&input.rows)); |
||||
openCLSafeCall(clSetKernelArg(kernel, 3, sizeof(cl_int), (void *)&input.cols)); |
||||
openCLSafeCall(clSetKernelArg(kernel, 4, sizeof(cl_int), (void *)&prefilterCap)); |
||||
|
||||
openCLSafeCall(clEnqueueNDRangeKernel(clCxt->impl->clCmdQueue, kernel, 3, NULL, |
||||
globalThreads, localThreads, 0, NULL, NULL)); |
||||
|
||||
clFinish(clCxt->impl->clCmdQueue); |
||||
openCLSafeCall(clReleaseKernel(kernel)); |
||||
|
||||
} |
||||
//////////////////////////////////////////////////////////////////////////
|
||||
//////////////////////////////common////////////////////////////////////
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
#define N_DISPARITIES 8 |
||||
#define ROWSperTHREAD 21 |
||||
#define BLOCK_W 128 |
||||
static inline int divUp(int total, int grain) |
||||
{ |
||||
return (total + grain - 1) / grain; |
||||
} |
||||
////////////////////////////////////////////////////////////////////////////
|
||||
///////////////////////////////stereoBM_GPU////////////////////////////////
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
void stereo_bm(const oclMat &left, const oclMat &right, oclMat &disp, |
||||
int maxdisp, int winSize, oclMat &minSSD_buf) |
||||
{ |
||||
int winsz2 = winSize >> 1; |
||||
|
||||
//if(winsz2 == 0 || winsz2 >= calles_num)
|
||||
//cv::ocl:error("Unsupported window size", __FILE__, __LINE__, __FUNCTION__);
|
||||
|
||||
Context *clCxt = left.clCxt; |
||||
|
||||
string kernelName = "stereoKernel"; |
||||
cl_kernel kernel = openCLGetKernelFromSource(clCxt, &stereobm, kernelName); |
||||
|
||||
disp.setTo(Scalar_<unsigned char>::all(0)); |
||||
minSSD_buf.setTo(Scalar_<unsigned int>::all(0xFFFFFFFF)); |
||||
|
||||
size_t minssd_step = minSSD_buf.step / minSSD_buf.elemSize(); |
||||
size_t local_mem_size = (BLOCK_W + N_DISPARITIES * (BLOCK_W + 2 * winsz2)) * |
||||
sizeof(cl_uint); |
||||
size_t blockSize = 1; |
||||
size_t localThreads[] = { BLOCK_W, 1}; |
||||
size_t globalThreads[] = { divUp(left.cols - maxdisp - 2 * winsz2, BLOCK_W) * BLOCK_W, |
||||
divUp(left.rows - 2 * winsz2, ROWSperTHREAD) |
||||
}; |
||||
|
||||
openCLVerifyKernel(clCxt, kernel, &blockSize, globalThreads, localThreads); |
||||
openCLSafeCall(clSetKernelArg(kernel, 0, sizeof(cl_mem), (void *)&left.data)); |
||||
openCLSafeCall(clSetKernelArg(kernel, 1, sizeof(cl_mem), (void *)&right.data)); |
||||
openCLSafeCall(clSetKernelArg(kernel, 2, sizeof(cl_mem), (void *)&minSSD_buf.data)); |
||||
openCLSafeCall(clSetKernelArg(kernel, 3, sizeof(cl_int), (void *)&minssd_step)); |
||||
openCLSafeCall(clSetKernelArg(kernel, 4, sizeof(cl_mem), (void *)&disp.data)); |
||||
openCLSafeCall(clSetKernelArg(kernel, 5, sizeof(cl_int), (void *)&disp.step)); |
||||
openCLSafeCall(clSetKernelArg(kernel, 6, sizeof(cl_int), (void *)&left.cols)); |
||||
openCLSafeCall(clSetKernelArg(kernel, 7, sizeof(cl_int), (void *)&left.rows)); |
||||
openCLSafeCall(clSetKernelArg(kernel, 8, sizeof(cl_int), (void *)&left.step)); |
||||
openCLSafeCall(clSetKernelArg(kernel, 9, sizeof(cl_int), (void *)&maxdisp)); |
||||
openCLSafeCall(clSetKernelArg(kernel, 10, sizeof(cl_int), (void *)&winsz2)); |
||||
openCLSafeCall(clSetKernelArg(kernel, 11, local_mem_size, (void *)NULL)); |
||||
|
||||
openCLSafeCall(clEnqueueNDRangeKernel(clCxt->impl->clCmdQueue, kernel, 2, NULL, |
||||
globalThreads, localThreads, 0, NULL, NULL)); |
||||
|
||||
|
||||
clFinish(clCxt->impl->clCmdQueue); |
||||
openCLSafeCall(clReleaseKernel(kernel)); |
||||
} |
||||
////////////////////////////////////////////////////////////////////////////
|
||||
///////////////////////////////postfilter_textureness///////////////////////
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
void postfilter_textureness(oclMat &left, int winSize, |
||||
float avergeTexThreshold, oclMat &disparity) |
||||
{ |
||||
Context *clCxt = left.clCxt; |
||||
|
||||
string kernelName = "textureness_kernel"; |
||||
cl_kernel kernel = openCLGetKernelFromSource(clCxt, &stereobm, kernelName); |
||||
|
||||
size_t blockSize = 1; |
||||
size_t localThreads[] = { BLOCK_W, blockSize}; |
||||
size_t globalThreads[] = { divUp(left.cols, BLOCK_W) * BLOCK_W, |
||||
divUp(left.rows, 2 * ROWSperTHREAD) |
||||
}; |
||||
|
||||
size_t local_mem_size = (localThreads[0] + localThreads[0] + (winSize / 2) * 2) * sizeof(float); |
||||
|
||||
openCLVerifyKernel(clCxt, kernel, &blockSize, globalThreads, localThreads); |
||||
openCLSafeCall(clSetKernelArg(kernel, 0, sizeof(cl_mem), (void *)&disparity.data)); |
||||
openCLSafeCall(clSetKernelArg(kernel, 1, sizeof(cl_int), (void *)&disparity.rows)); |
||||
openCLSafeCall(clSetKernelArg(kernel, 2, sizeof(cl_int), (void *)&disparity.cols)); |
||||
openCLSafeCall(clSetKernelArg(kernel, 3, sizeof(cl_int), (void *)&disparity.step)); |
||||
openCLSafeCall(clSetKernelArg(kernel, 4, sizeof(cl_mem), (void *)&left.data)); |
||||
openCLSafeCall(clSetKernelArg(kernel, 5, sizeof(cl_int), (void *)&left.rows)); |
||||
openCLSafeCall(clSetKernelArg(kernel, 6, sizeof(cl_int), (void *)&left.cols)); |
||||
openCLSafeCall(clSetKernelArg(kernel, 7, sizeof(cl_int), (void *)&winSize)); |
||||
openCLSafeCall(clSetKernelArg(kernel, 8, sizeof(cl_float), (void *)&avergeTexThreshold)); |
||||
openCLSafeCall(clSetKernelArg(kernel, 9, local_mem_size, NULL)); |
||||
openCLSafeCall(clEnqueueNDRangeKernel(clCxt->impl->clCmdQueue, kernel, 2, NULL, |
||||
globalThreads, localThreads, 0, NULL, NULL)); |
||||
|
||||
clFinish(clCxt->impl->clCmdQueue); |
||||
openCLSafeCall(clReleaseKernel(kernel)); |
||||
} |
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
/////////////////////////////////////operator/////////////////////////////////
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
void operator_(oclMat &minSSD, oclMat &leBuf, oclMat &riBuf, int preset, int ndisp, |
||||
int winSize, float avergeTexThreshold, const oclMat &left, |
||||
const oclMat &right, oclMat &disparity) |
||||
|
||||
{ |
||||
CV_DbgAssert(left.rows == right.rows && left.cols == right.cols); |
||||
CV_DbgAssert(left.type() == CV_8UC1); |
||||
CV_DbgAssert(right.type() == CV_8UC1); |
||||
|
||||
disparity.create(left.size(), CV_8UC1); |
||||
minSSD.create(left.size(), CV_32SC1); |
||||
|
||||
oclMat le_for_bm = left; |
||||
oclMat ri_for_bm = right; |
||||
|
||||
if (preset == cv::ocl::StereoBM_GPU::PREFILTER_XSOBEL) |
||||
{ |
||||
leBuf.create( left.size(), left.type()); |
||||
riBuf.create(right.size(), right.type()); |
||||
|
||||
prefilter_xsobel( left, leBuf, 31); |
||||
prefilter_xsobel(right, riBuf, 31); |
||||
|
||||
le_for_bm = leBuf; |
||||
ri_for_bm = riBuf; |
||||
} |
||||
|
||||
stereo_bm(le_for_bm, ri_for_bm, disparity, ndisp, winSize, minSSD); |
||||
|
||||
if (avergeTexThreshold) |
||||
{ |
||||
postfilter_textureness(le_for_bm, winSize, avergeTexThreshold, disparity); |
||||
} |
||||
} |
||||
} |
||||
} |
||||
} |
||||
const float defaultAvgTexThreshold = 3; |
||||
|
||||
cv::ocl::StereoBM_GPU::StereoBM_GPU() |
||||
: preset(BASIC_PRESET), ndisp(DEFAULT_NDISP), winSize(DEFAULT_WINSZ), |
||||
avergeTexThreshold(defaultAvgTexThreshold) {} |
||||
|
||||
cv::ocl::StereoBM_GPU::StereoBM_GPU(int preset_, int ndisparities_, int winSize_) |
||||
: preset(preset_), ndisp(ndisparities_), winSize(winSize_), |
||||
avergeTexThreshold(defaultAvgTexThreshold) |
||||
{ |
||||
const int max_supported_ndisp = 1 << (sizeof(unsigned char) * 8); |
||||
CV_Assert(0 < ndisp && ndisp <= max_supported_ndisp); |
||||
CV_Assert(ndisp % 8 == 0); |
||||
CV_Assert(winSize % 2 == 1); |
||||
} |
||||
|
||||
bool cv::ocl::StereoBM_GPU::checkIfGpuCallReasonable() |
||||
{ |
||||
return true; |
||||
} |
||||
|
||||
void cv::ocl::StereoBM_GPU::operator() ( const oclMat &left, const oclMat &right, |
||||
oclMat &disparity) |
||||
{ |
||||
cv::ocl::stereoBM::operator_(minSSD, leBuf, riBuf, preset, ndisp, winSize, avergeTexThreshold, left, right, disparity); |
||||
} |
||||
|
||||
#endif /* !defined (HAVE_OPENCL) */ |
@ -1,661 +0,0 @@ |
||||
/*M///////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
|
||||
//
|
||||
// By downloading, copying, installing or using the software you agree to this license.
|
||||
// If you do not agree to this license, do not download, install,
|
||||
// copy or use the software.
|
||||
//
|
||||
//
|
||||
// License Agreement
|
||||
// For Open Source Computer Vision Library
|
||||
//
|
||||
// Copyright (C) 2010-2012, Institute Of Software Chinese Academy Of Science, all rights reserved.
|
||||
// Copyright (C) 2010-2012, Advanced Micro Devices, Inc., all rights reserved.
|
||||
// Third party copyrights are property of their respective owners.
|
||||
//
|
||||
// @Authors
|
||||
// Jia Haipeng, jiahaipeng95@gmail.com
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
// are permitted provided that the following conditions are met:
|
||||
//
|
||||
// * Redistribution's of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
//
|
||||
// * Redistribution's in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other oclMaterials provided with the distribution.
|
||||
//
|
||||
// * The name of the copyright holders may not be used to endorse or promote products
|
||||
// derived from this software without specific prior written permission.
|
||||
//
|
||||
// This software is provided by the copyright holders and contributors "as is" and
|
||||
// any express or implied warranties, including, but not limited to, the implied
|
||||
// warranties of merchantability and fitness for a particular purpose are disclaimed.
|
||||
// In no event shall the Intel Corporation or contributors be liable for any direct,
|
||||
// indirect, incidental, special, exemplary, or consequential damages
|
||||
// (including, but not limited to, procurement of substitute goods or services;
|
||||
// loss of use, data, or profits; or business interruption) however caused
|
||||
// and on any theory of liability, whether in contract, strict liability,
|
||||
// or tort (including negligence or otherwise) arising in any way out of
|
||||
// the use of this software, even if advised of the possibility of such damage.
|
||||
//
|
||||
//M*/
|
||||
|
||||
#include "precomp.hpp" |
||||
#include <vector> |
||||
|
||||
using namespace cv; |
||||
using namespace cv::ocl; |
||||
using namespace std; |
||||
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
///////////////// stereoBP /////////////////////////////////////////////
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#if !defined (HAVE_OPENCL) |
||||
|
||||
namespace cv |
||||
{ |
||||
namespace ocl |
||||
{ |
||||
void cv::ocl::StereoBeliefPropagation::estimateRecommendedParams(int, int, int &, int &, int &) |
||||
{ |
||||
throw_nogpu(); |
||||
} |
||||
|
||||
cv::ocl::StereoBeliefPropagation::StereoBeliefPropagation(int, int, int, int) |
||||
{ |
||||
throw_nogpu(); |
||||
} |
||||
|
||||
cv::ocl::StereoBeliefPropagation::StereoBeliefPropagation(int, int, int, float, float, float, float, int) |
||||
{ |
||||
throw_nogpu(); |
||||
} |
||||
|
||||
void cv::ocl::StereoBeliefPropagation::operator()(const oclMat &, const oclMat &, oclMat &) |
||||
{ |
||||
throw_nogpu(); |
||||
} |
||||
|
||||
void cv::ocl::StereoBeliefPropagation::operator()(const oclMat &, oclMat &) |
||||
{ |
||||
throw_nogpu(); |
||||
} |
||||
} |
||||
} |
||||
|
||||
#else /* !defined (HAVE_OPENCL) */ |
||||
|
||||
namespace cv |
||||
{ |
||||
namespace ocl |
||||
{ |
||||
|
||||
///////////////////////////OpenCL kernel strings///////////////////////////
|
||||
extern const char *stereobp; |
||||
} |
||||
|
||||
} |
||||
namespace cv |
||||
{ |
||||
namespace ocl |
||||
{ |
||||
namespace stereoBP |
||||
{ |
||||
//////////////////////////////////////////////////////////////////////////
|
||||
//////////////////////////////common////////////////////////////////////
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
typedef struct
|
||||
{ |
||||
int cndisp; |
||||
float cmax_data_term; |
||||
float cdata_weight; |
||||
float cmax_disc_term; |
||||
float cdisc_single_jump; |
||||
} con_struct_t; |
||||
|
||||
cl_mem cl_con_struct = NULL; |
||||
void load_constants(Context *clCxt, int ndisp, float max_data_term, float data_weight, |
||||
float max_disc_term, float disc_single_jump) |
||||
{ |
||||
con_struct_t *con_struct = new con_struct_t; |
||||
con_struct -> cndisp = ndisp; |
||||
con_struct -> cmax_data_term = max_data_term; |
||||
con_struct -> cdata_weight = data_weight; |
||||
con_struct -> cmax_disc_term = max_data_term; |
||||
con_struct -> cdisc_single_jump = disc_single_jump; |
||||
|
||||
cl_con_struct = load_constant(clCxt->impl->clContext, clCxt->impl->clCmdQueue, (void *)con_struct, |
||||
sizeof(con_struct_t)); |
||||
|
||||
delete con_struct; |
||||
} |
||||
void release_constants() |
||||
{ |
||||
openCLFree(cl_con_struct); |
||||
} |
||||
static inline int divUp(int total, int grain) |
||||
{ |
||||
return (total + grain - 1) / grain; |
||||
} |
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
///////////////////////////comp data////////////////////////////////////////
|
||||
/////////////////////////////////////////////////////////////////////////
|
||||
void comp_data_call(const oclMat &left, const oclMat &right, oclMat &data, int disp, float cmax_data_term, float cdata_weight) |
||||
{ |
||||
Context *clCxt = left.clCxt; |
||||
int channels = left.channels(); |
||||
int data_type = data.type(); |
||||
|
||||
string kernelName = "comp_data_"; |
||||
stringstream idxStr; |
||||
if(data_type == CV_16S) |
||||
idxStr << "0"; |
||||
else |
||||
idxStr << "1"; |
||||
kernelName += idxStr.str(); |
||||
|
||||
cl_kernel kernel = openCLGetKernelFromSource(clCxt, &stereobp, kernelName); |
||||
|
||||
size_t blockSize = 32; |
||||
size_t localThreads[] = {32, 8}; |
||||
size_t globalThreads[] = {divUp(left.cols, localThreads[0]) * localThreads[0], |
||||
divUp(left.rows, localThreads[1]) * localThreads[1] |
||||
}; |
||||
|
||||
openCLVerifyKernel(clCxt, kernel, &blockSize, globalThreads, localThreads); |
||||
openCLSafeCall(clSetKernelArg(kernel, 0, sizeof(cl_mem), (void *)&left.data)); |
||||
openCLSafeCall(clSetKernelArg(kernel, 1, sizeof(cl_int), (void *)&left.rows)); |
||||
openCLSafeCall(clSetKernelArg(kernel, 2, sizeof(cl_int), (void *)&left.cols)); |
||||
openCLSafeCall(clSetKernelArg(kernel, 3, sizeof(cl_int), (void *)&left.step)); |
||||
openCLSafeCall(clSetKernelArg(kernel, 4, sizeof(cl_mem), (void *)&right.data)); |
||||
openCLSafeCall(clSetKernelArg(kernel, 5, sizeof(cl_int), (void *)&right.step)); |
||||
openCLSafeCall(clSetKernelArg(kernel, 6, sizeof(cl_mem), (void *)&data.data)); |
||||
openCLSafeCall(clSetKernelArg(kernel, 7, sizeof(cl_int), (void *)&data.cols)); |
||||
openCLSafeCall(clSetKernelArg(kernel, 8, sizeof(cl_int), (void *)&data.step)); |
||||
openCLSafeCall(clSetKernelArg(kernel, 9, sizeof(cl_mem), (void *)&cl_con_struct)); |
||||
//openCLSafeCall(clSetKernelArg(kernel,12,sizeof(cl_int),(void*)&disp));
|
||||
//openCLSafeCall(clSetKernelArg(kernel,13,sizeof(cl_float),(void*)&cmax_data_term));
|
||||
//openCLSafeCall(clSetKernelArg(kernel,14,sizeof(cl_float),(void*)&cdata_weight));
|
||||
openCLSafeCall(clSetKernelArg(kernel, 10, sizeof(cl_int), (void *)&channels)); |
||||
|
||||
openCLSafeCall(clEnqueueNDRangeKernel(clCxt->impl->clCmdQueue, kernel, 2, NULL, |
||||
globalThreads, localThreads, 0, NULL, NULL)); |
||||
|
||||
clFinish(clCxt->impl->clCmdQueue); |
||||
openCLSafeCall(clReleaseKernel(kernel)); |
||||
} |
||||
///////////////////////////////////////////////////////////////////////////////////
|
||||
/////////////////////////data set down////////////////////////////////////////////
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
void data_step_down_call(int dst_cols, int dst_rows, int src_rows, |
||||
const oclMat &src, oclMat &dst, int disp) |
||||
{ |
||||
Context *clCxt = src.clCxt; |
||||
int data_type = src.type(); |
||||
|
||||
string kernelName = "data_step_down_"; |
||||
stringstream idxStr; |
||||
if(data_type == CV_16S) |
||||
idxStr << "0"; |
||||
else |
||||
idxStr << "1"; |
||||
kernelName += idxStr.str(); |
||||
|
||||
cl_kernel kernel = openCLGetKernelFromSource(clCxt, &stereobp, kernelName); |
||||
|
||||
size_t blockSize = 32; |
||||
size_t localThreads[] = {32, 8}; |
||||
size_t globalThreads[] = {divUp(dst_cols, localThreads[0]) * localThreads[0], |
||||
divUp(dst_rows, localThreads[1]) * localThreads[1] |
||||
}; |
||||
|
||||
openCLVerifyKernel(clCxt, kernel, &blockSize, globalThreads, localThreads); |
||||
openCLSafeCall(clSetKernelArg(kernel, 0, sizeof(cl_mem), (void *)&src.data)); |
||||
openCLSafeCall(clSetKernelArg(kernel, 1, sizeof(cl_int), (void *)&src_rows)); |
||||
openCLSafeCall(clSetKernelArg(kernel, 2, sizeof(cl_int), (void *)&src.cols)); |
||||
openCLSafeCall(clSetKernelArg(kernel, 3, sizeof(cl_mem), (void *)&dst.data)); |
||||
openCLSafeCall(clSetKernelArg(kernel, 4, sizeof(cl_int), (void *)&dst_rows)); |
||||
openCLSafeCall(clSetKernelArg(kernel, 5, sizeof(cl_int), (void *)&dst_cols)); |
||||
openCLSafeCall(clSetKernelArg(kernel, 6, sizeof(cl_int), (void *)&dst.cols)); |
||||
openCLSafeCall(clSetKernelArg(kernel, 7, sizeof(cl_int), (void *)&disp)); |
||||
|
||||
openCLSafeCall(clEnqueueNDRangeKernel(clCxt->impl->clCmdQueue, kernel, 2, NULL, |
||||
globalThreads, localThreads, 0, NULL, NULL)); |
||||
|
||||
clFinish(clCxt->impl->clCmdQueue); |
||||
openCLSafeCall(clReleaseKernel(kernel)); |
||||
} |
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
///////////////////////////live up message////////////////////////////////////////
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
void level_up_message_call(int dst_idx, int dst_cols, int dst_rows, int src_rows, |
||||
oclMat &src, oclMat &dst, int ndisp) |
||||
{ |
||||
Context *clCxt = src.clCxt; |
||||
int data_type = src.type(); |
||||
|
||||
string kernelName = "level_up_message_"; |
||||
stringstream idxStr; |
||||
if(data_type == CV_16S) |
||||
idxStr << "0"; |
||||
else |
||||
idxStr << "1"; |
||||
kernelName += idxStr.str(); |
||||
|
||||
cl_kernel kernel = openCLGetKernelFromSource(clCxt, &stereobp, kernelName); |
||||
|
||||
size_t blockSize = 32; |
||||
size_t localThreads[] = {32, 8}; |
||||
size_t globalThreads[] = {divUp(dst_cols, localThreads[0]) * localThreads[0], |
||||
divUp(dst_rows, localThreads[1]) * localThreads[1] |
||||
}; |
||||
|
||||
openCLVerifyKernel(clCxt, kernel, &blockSize, globalThreads, localThreads); |
||||
openCLSafeCall(clSetKernelArg(kernel, 0, sizeof(cl_mem), (void *)&src.data)); |
||||
openCLSafeCall(clSetKernelArg(kernel, 1, sizeof(cl_int), (void *)&src_rows)); |
||||
openCLSafeCall(clSetKernelArg(kernel, 2, sizeof(cl_int), (void *)&src.step)); |
||||
openCLSafeCall(clSetKernelArg(kernel, 3, sizeof(cl_mem), (void *)&dst.data)); |
||||
openCLSafeCall(clSetKernelArg(kernel, 4, sizeof(cl_int), (void *)&dst_rows)); |
||||
openCLSafeCall(clSetKernelArg(kernel, 5, sizeof(cl_int), (void *)&dst_cols)); |
||||
openCLSafeCall(clSetKernelArg(kernel, 6, sizeof(cl_int), (void *)&dst.step)); |
||||
openCLSafeCall(clSetKernelArg(kernel, 7, sizeof(cl_int), (void *)&ndisp)); |
||||
|
||||
openCLSafeCall(clEnqueueNDRangeKernel(clCxt->impl->clCmdQueue, kernel, 2, NULL, |
||||
globalThreads, localThreads, 0, NULL, NULL)); |
||||
|
||||
clFinish(clCxt->impl->clCmdQueue); |
||||
openCLSafeCall(clReleaseKernel(kernel)); |
||||
} |
||||
void level_up_messages_calls(int dst_idx, int dst_cols, int dst_rows, int src_rows, |
||||
oclMat *mus, oclMat *mds, oclMat *mls, oclMat *mrs, |
||||
int ndisp) |
||||
{ |
||||
int src_idx = (dst_idx + 1) & 1; |
||||
|
||||
level_up_message_call(dst_idx, dst_cols, dst_rows, src_rows, |
||||
mus[src_idx], mus[dst_idx], ndisp); |
||||
|
||||
level_up_message_call(dst_idx, dst_cols, dst_rows, src_rows, |
||||
mds[src_idx], mds[dst_idx], ndisp); |
||||
|
||||
level_up_message_call(dst_idx, dst_cols, dst_rows, src_rows, |
||||
mls[src_idx], mls[dst_idx], ndisp); |
||||
|
||||
level_up_message_call(dst_idx, dst_cols, dst_rows, src_rows, |
||||
mrs[src_idx], mrs[dst_idx], ndisp); |
||||
} |
||||
//////////////////////////////////////////////////////////////////////////////////
|
||||
//////////////////////////////cals_all_iterations_call///////////////////////////
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
void calc_all_iterations_call(int cols, int rows, oclMat &u, oclMat &d, |
||||
oclMat &l, oclMat &r, oclMat &data, |
||||
int t, int cndisp, float cmax_disc_term, |
||||
float cdisc_single_jump) |
||||
{ |
||||
Context *clCxt = l.clCxt; |
||||
int data_type = u.type(); |
||||
|
||||
string kernelName = "one_iteration_"; |
||||
stringstream idxStr; |
||||
if(data_type == CV_16S) |
||||
idxStr << "0"; |
||||
else |
||||
idxStr << "1"; |
||||
kernelName += idxStr.str(); |
||||
|
||||
cl_kernel kernel = openCLGetKernelFromSource(clCxt, &stereobp, kernelName); |
||||
|
||||
size_t blockSize = 32; |
||||
size_t localThreads[] = {32, 8}; |
||||
size_t globalThreads[] = {divUp(cols, (localThreads[0] << 1)) * (localThreads[0] << 1), |
||||
divUp(rows, localThreads[1]) * localThreads[1] |
||||
}; |
||||
|
||||
openCLVerifyKernel(clCxt, kernel, &blockSize, globalThreads, localThreads); |
||||
openCLSafeCall(clSetKernelArg(kernel, 0, sizeof(cl_mem), (void *)&u.data)); |
||||
openCLSafeCall(clSetKernelArg(kernel, 1, sizeof(cl_int), (void *)&u.step)); |
||||
openCLSafeCall(clSetKernelArg(kernel, 2, sizeof(cl_int), (void *)&u.cols)); |
||||
openCLSafeCall(clSetKernelArg(kernel, 3, sizeof(cl_mem), (void *)&data.data)); |
||||
openCLSafeCall(clSetKernelArg(kernel, 4, sizeof(cl_int), (void *)&data.step)); |
||||
openCLSafeCall(clSetKernelArg(kernel, 5, sizeof(cl_int), (void *)&data.cols)); |
||||
openCLSafeCall(clSetKernelArg(kernel, 6, sizeof(cl_mem), (void *)&d.data)); |
||||
openCLSafeCall(clSetKernelArg(kernel, 7, sizeof(cl_mem), (void *)&l.data)); |
||||
openCLSafeCall(clSetKernelArg(kernel, 8, sizeof(cl_mem), (void *)&r.data)); |
||||
openCLSafeCall(clSetKernelArg(kernel, 9, sizeof(cl_int), (void *)&t)); |
||||
openCLSafeCall(clSetKernelArg(kernel, 10, sizeof(cl_int), (void *)&cols)); |
||||
openCLSafeCall(clSetKernelArg(kernel, 11, sizeof(cl_int), (void *)&rows)); |
||||
openCLSafeCall(clSetKernelArg(kernel, 12, sizeof(cl_int), (void *)&cndisp)); |
||||
openCLSafeCall(clSetKernelArg(kernel, 13, sizeof(cl_float), (void *)&cmax_disc_term)); |
||||
openCLSafeCall(clSetKernelArg(kernel, 14, sizeof(cl_float), (void *)&cdisc_single_jump)); |
||||
|
||||
openCLSafeCall(clEnqueueNDRangeKernel(clCxt->impl->clCmdQueue, kernel, 2, NULL, |
||||
globalThreads, localThreads, 0, NULL, NULL)); |
||||
|
||||
clFinish(clCxt->impl->clCmdQueue); |
||||
openCLSafeCall(clReleaseKernel(kernel)); |
||||
} |
||||
|
||||
void calc_all_iterations_calls(int cols, int rows, int iters, oclMat &u, |
||||
oclMat &d, oclMat &l, oclMat &r, |
||||
oclMat &data, int cndisp, float cmax_disc_term, |
||||
float cdisc_single_jump) |
||||
{ |
||||
for(int t = 0; t < iters; ++t) |
||||
calc_all_iterations_call(cols, rows, u, d, l, r, data, t, cndisp, |
||||
cmax_disc_term, cdisc_single_jump); |
||||
} |
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
///////////////////////output///////////////////////////////////////////////////
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
void output_call(const oclMat &u, const oclMat &d, const oclMat l, const oclMat &r, |
||||
const oclMat &data, oclMat &disp, int ndisp) |
||||
{ |
||||
Context *clCxt = u.clCxt; |
||||
int data_type = u.type(); |
||||
|
||||
string kernelName = "output_"; |
||||
stringstream idxStr; |
||||
if(data_type == CV_16S) |
||||
idxStr << "0"; |
||||
else |
||||
idxStr << "1"; |
||||
kernelName += idxStr.str(); |
||||
|
||||
cl_kernel kernel = openCLGetKernelFromSource(clCxt, &stereobp, kernelName); |
||||
|
||||
size_t blockSize = 32; |
||||
size_t localThreads[] = {32, 8}; |
||||
size_t globalThreads[] = {divUp(disp.cols, localThreads[0]) * localThreads[0], |
||||
divUp(disp.rows, localThreads[1]) * localThreads[1] |
||||
}; |
||||
|
||||
openCLVerifyKernel(clCxt, kernel, &blockSize, globalThreads, localThreads); |
||||
openCLSafeCall(clSetKernelArg(kernel, 0, sizeof(cl_mem), (void *)&u.data)); |
||||
openCLSafeCall(clSetKernelArg(kernel, 1, sizeof(cl_int), (void *)&u.step)); |
||||
openCLSafeCall(clSetKernelArg(kernel, 2, sizeof(cl_int), (void *)&u.cols)); |
||||
openCLSafeCall(clSetKernelArg(kernel, 3, sizeof(cl_mem), (void *)&d.data)); |
||||
openCLSafeCall(clSetKernelArg(kernel, 4, sizeof(cl_mem), (void *)&l.data)); |
||||
openCLSafeCall(clSetKernelArg(kernel, 5, sizeof(cl_mem), (void *)&r.data)); |
||||
openCLSafeCall(clSetKernelArg(kernel, 6, sizeof(cl_mem), (void *)&data.data)); |
||||
openCLSafeCall(clSetKernelArg(kernel, 7, sizeof(cl_mem), (void *)&disp.data)); |
||||
openCLSafeCall(clSetKernelArg(kernel, 8, sizeof(cl_int), (void *)&disp.rows)); |
||||
openCLSafeCall(clSetKernelArg(kernel, 9, sizeof(cl_int), (void *)&disp.cols)); |
||||
openCLSafeCall(clSetKernelArg(kernel, 10, sizeof(cl_int), (void *)&disp.step)); |
||||
openCLSafeCall(clSetKernelArg(kernel, 11, sizeof(cl_int), (void *)&ndisp)); |
||||
|
||||
openCLSafeCall(clEnqueueNDRangeKernel(clCxt->impl->clCmdQueue, kernel, 2, NULL, |
||||
globalThreads, localThreads, 0, NULL, NULL)); |
||||
|
||||
clFinish(clCxt->impl->clCmdQueue); |
||||
openCLSafeCall(clReleaseKernel(kernel)); |
||||
|
||||
} |
||||
} |
||||
} |
||||
} |
||||
namespace |
||||
{ |
||||
const float DEFAULT_MAX_DATA_TERM = 10.0f; |
||||
const float DEFAULT_DATA_WEIGHT = 0.07f; |
||||
const float DEFAULT_MAX_DISC_TERM = 1.7f; |
||||
const float DEFAULT_DISC_SINGLE_JUMP = 1.0f; |
||||
|
||||
template<typename T> |
||||
void print_gpu_mat(const oclMat &mat) |
||||
{ |
||||
T *data_1 = new T[mat.rows * mat.cols * mat.channels()]; |
||||
Context *clCxt = mat.clCxt; |
||||
int status = clEnqueueReadBuffer(clCxt -> impl-> clCmdQueue, (cl_mem)mat.data, CL_TRUE, 0, |
||||
mat.rows * mat.cols * mat.channels() * sizeof(T), data_1, 0, NULL, NULL); |
||||
|
||||
if(status != CL_SUCCESS) |
||||
cout << "error " << status << endl; |
||||
|
||||
cout << ".........................................................." << endl; |
||||
cout << "elemSize() " << mat.elemSize() << endl; |
||||
cout << "elemSize() " << mat.elemSize1() << endl; |
||||
cout << "channels: " << mat.channels() << endl; |
||||
cout << "rows: " << mat.rows << endl; |
||||
cout << "cols: " << mat.cols << endl; |
||||
|
||||
for(int i = 0; i < 30; i++) |
||||
{ |
||||
for(int j = 0; j < 30; j++) |
||||
{ |
||||
cout << (int)data_1[i * mat.cols * mat.channels() + j] << " "; |
||||
} |
||||
cout << endl; |
||||
} |
||||
} |
||||
} |
||||
|
||||
void cv::ocl::StereoBeliefPropagation::estimateRecommendedParams(int width, int height, int &ndisp, int &iters, int &levels) |
||||
{ |
||||
ndisp = width / 4; |
||||
if ((ndisp & 1) != 0) |
||||
ndisp++; |
||||
|
||||
int mm = ::max(width, height); |
||||
iters = mm / 100 + 2; |
||||
|
||||
levels = (int)(::log(static_cast<double>(mm)) + 1) * 4 / 5; |
||||
if (levels == 0) levels++; |
||||
} |
||||
|
||||
cv::ocl::StereoBeliefPropagation::StereoBeliefPropagation(int ndisp_, int iters_, int levels_, int msg_type_) |
||||
: ndisp(ndisp_), iters(iters_), levels(levels_), |
||||
max_data_term(DEFAULT_MAX_DATA_TERM), data_weight(DEFAULT_DATA_WEIGHT), |
||||
max_disc_term(DEFAULT_MAX_DISC_TERM), disc_single_jump(DEFAULT_DISC_SINGLE_JUMP), |
||||
msg_type(msg_type_), datas(levels_) |
||||
{ |
||||
} |
||||
|
||||
cv::ocl::StereoBeliefPropagation::StereoBeliefPropagation(int ndisp_, int iters_, int levels_, float max_data_term_, float data_weight_, float max_disc_term_, float disc_single_jump_, int msg_type_) |
||||
: ndisp(ndisp_), iters(iters_), levels(levels_), |
||||
max_data_term(max_data_term_), data_weight(data_weight_), |
||||
max_disc_term(max_disc_term_), disc_single_jump(disc_single_jump_), |
||||
msg_type(msg_type_), datas(levels_) |
||||
{ |
||||
} |
||||
|
||||
namespace |
||||
{ |
||||
class StereoBeliefPropagationImpl |
||||
{ |
||||
public: |
||||
StereoBeliefPropagationImpl(StereoBeliefPropagation &rthis_, |
||||
oclMat &u_, oclMat &d_, oclMat &l_, oclMat &r_, |
||||
oclMat &u2_, oclMat &d2_, oclMat &l2_, oclMat &r2_, |
||||
vector<oclMat>& datas_, oclMat &out_) |
||||
: rthis(rthis_), u(u_), d(d_), l(l_), r(r_), u2(u2_), d2(d2_), l2(l2_), r2(r2_), datas(datas_), out(out_), |
||||
zero(Scalar::all(0)), scale(rthis_.msg_type == CV_32F ? 1.0f : 10.0f) |
||||
{ |
||||
CV_Assert(0 < rthis.ndisp && 0 < rthis.iters && 0 < rthis.levels); |
||||
CV_Assert(rthis.msg_type == CV_32F || rthis.msg_type == CV_16S); |
||||
CV_Assert(rthis.msg_type == CV_32F || (1 << (rthis.levels - 1)) * scale * rthis.max_data_term < numeric_limits<short>::max()); |
||||
} |
||||
|
||||
void operator()(const oclMat &left, const oclMat &right, oclMat &disp) |
||||
{ |
||||
CV_Assert(left.size() == right.size() && left.type() == right.type()); |
||||
CV_Assert(left.type() == CV_8UC1 || left.type() == CV_8UC3 || left.type() == CV_8UC4); |
||||
|
||||
rows = left.rows; |
||||
cols = left.cols; |
||||
|
||||
int divisor = (int)pow(2.f, rthis.levels - 1.0f); |
||||
int lowest_cols = cols / divisor; |
||||
int lowest_rows = rows / divisor; |
||||
const int min_image_dim_size = 2; |
||||
CV_Assert(min(lowest_cols, lowest_rows) > min_image_dim_size); |
||||
|
||||
init(); |
||||
|
||||
datas[0].create(rows * rthis.ndisp, cols, rthis.msg_type); |
||||
datas[0].setTo(Scalar_<short>::all(0)); |
||||
|
||||
cv::ocl::stereoBP::comp_data_call(left, right, datas[0], rthis.ndisp, rthis.max_data_term, scale * rthis.data_weight); |
||||
|
||||
calcBP(disp); |
||||
} |
||||
|
||||
void operator()(const oclMat &data, oclMat &disp) |
||||
{ |
||||
CV_Assert((data.type() == rthis.msg_type) && (data.rows % rthis.ndisp == 0)); |
||||
|
||||
rows = data.rows / rthis.ndisp; |
||||
cols = data.cols; |
||||
|
||||
int divisor = (int)pow(2.f, rthis.levels - 1.0f); |
||||
int lowest_cols = cols / divisor; |
||||
int lowest_rows = rows / divisor; |
||||
const int min_image_dim_size = 2; |
||||
CV_Assert(min(lowest_cols, lowest_rows) > min_image_dim_size); |
||||
|
||||
init(); |
||||
|
||||
datas[0] = data; |
||||
|
||||
calcBP(disp); |
||||
} |
||||
private: |
||||
void init() |
||||
{ |
||||
u.create(rows * rthis.ndisp, cols, rthis.msg_type); |
||||
d.create(rows * rthis.ndisp, cols, rthis.msg_type); |
||||
l.create(rows * rthis.ndisp, cols, rthis.msg_type); |
||||
r.create(rows * rthis.ndisp, cols, rthis.msg_type); |
||||
|
||||
if (rthis.levels & 1) |
||||
{ |
||||
//can clear less area
|
||||
u = zero; |
||||
d = zero; |
||||
l = zero; |
||||
r = zero; |
||||
} |
||||
|
||||
if (rthis.levels > 1) |
||||
{ |
||||
int less_rows = (rows + 1) / 2; |
||||
int less_cols = (cols + 1) / 2; |
||||
|
||||
u2.create(less_rows * rthis.ndisp, less_cols, rthis.msg_type); |
||||
d2.create(less_rows * rthis.ndisp, less_cols, rthis.msg_type); |
||||
l2.create(less_rows * rthis.ndisp, less_cols, rthis.msg_type); |
||||
r2.create(less_rows * rthis.ndisp, less_cols, rthis.msg_type); |
||||
|
||||
if ((rthis.levels & 1) == 0) |
||||
{ |
||||
u2 = zero; |
||||
d2 = zero; |
||||
l2 = zero; |
||||
r2 = zero; |
||||
} |
||||
} |
||||
|
||||
cv::ocl::stereoBP::load_constants(u.clCxt, rthis.ndisp, rthis.max_data_term, scale * rthis.data_weight, |
||||
scale * rthis.max_disc_term, scale * rthis.disc_single_jump); |
||||
|
||||
datas.resize(rthis.levels); |
||||
|
||||
cols_all.resize(rthis.levels); |
||||
rows_all.resize(rthis.levels); |
||||
|
||||
cols_all[0] = cols; |
||||
rows_all[0] = rows; |
||||
} |
||||
|
||||
void calcBP(oclMat &disp) |
||||
{ |
||||
using namespace cv::ocl::stereoBP; |
||||
|
||||
for (int i = 1; i < rthis.levels; ++i) |
||||
{ |
||||
cols_all[i] = (cols_all[i-1] + 1) / 2; |
||||
rows_all[i] = (rows_all[i-1] + 1) / 2; |
||||
|
||||
datas[i].create(rows_all[i] * rthis.ndisp, cols_all[i], rthis.msg_type); |
||||
datas[i].setTo(Scalar_<short>::all(0)); |
||||
|
||||
data_step_down_call(cols_all[i], rows_all[i], rows_all[i-1], |
||||
datas[i-1], datas[i], rthis.ndisp); |
||||
} |
||||
|
||||
oclMat mus[] = {u, u2}; |
||||
oclMat mds[] = {d, d2}; |
||||
oclMat mrs[] = {r, r2}; |
||||
oclMat mls[] = {l, l2}; |
||||
|
||||
int mem_idx = (rthis.levels & 1) ? 0 : 1; |
||||
|
||||
for (int i = rthis.levels - 1; i >= 0; --i) |
||||
{ |
||||
// for lower level we have already computed messages by setting to zero
|
||||
if (i != rthis.levels - 1) |
||||
level_up_messages_calls(mem_idx, cols_all[i], rows_all[i], rows_all[i+1], |
||||
mus, mds, mls, mrs, rthis.ndisp); |
||||
|
||||
calc_all_iterations_calls(cols_all[i], rows_all[i], rthis.iters, mus[mem_idx], |
||||
mds[mem_idx], mls[mem_idx], mrs[mem_idx], datas[i], |
||||
rthis.ndisp, scale * rthis.max_disc_term, |
||||
scale * rthis.disc_single_jump); |
||||
|
||||
mem_idx = (mem_idx + 1) & 1; |
||||
} |
||||
|
||||
if (disp.empty()) |
||||
disp.create(rows, cols, CV_16S); |
||||
|
||||
out = ((disp.type() == CV_16S) ? disp : (out.create(rows, cols, CV_16S), out)); |
||||
out = zero; |
||||
|
||||
output_call(u, d, l, r, datas.front(), out, rthis.ndisp); |
||||
|
||||
|
||||
if (disp.type() != CV_16S) |
||||
out.convertTo(disp, disp.type()); |
||||
|
||||
release_constants(); |
||||
} |
||||
|
||||
StereoBeliefPropagation &rthis; |
||||
|
||||
oclMat &u; |
||||
oclMat &d; |
||||
oclMat &l; |
||||
oclMat &r; |
||||
|
||||
oclMat &u2; |
||||
oclMat &d2; |
||||
oclMat &l2; |
||||
oclMat &r2; |
||||
|
||||
vector<oclMat>& datas; |
||||
oclMat &out; |
||||
|
||||
const Scalar zero; |
||||
const float scale; |
||||
|
||||
int rows, cols; |
||||
|
||||
vector<int> cols_all, rows_all; |
||||
}; |
||||
} |
||||
|
||||
void cv::ocl::StereoBeliefPropagation::operator()(const oclMat &left, const oclMat &right, oclMat &disp) |
||||
{ |
||||
::StereoBeliefPropagationImpl impl(*this, u, d, l, r, u2, d2, l2, r2, datas, out); |
||||
impl(left, right, disp); |
||||
} |
||||
|
||||
void cv::ocl::StereoBeliefPropagation::operator()(const oclMat &data, oclMat &disp) |
||||
{ |
||||
::StereoBeliefPropagationImpl impl(*this, u, d, l, r, u2, d2, l2, r2, datas, out); |
||||
impl(data, disp); |
||||
} |
||||
#endif /* !defined (HAVE_OPENCL) */ |
Loading…
Reference in new issue