meanShiftFiltering_GPU output parameters changed to CV_8UC4. This is a start for moving from 3 channel to C4 images within GPU module.
This commit is contained in:
parent
2154a0ce63
commit
ec7e937481
modules/gpu
tests/gpu/src
@ -347,7 +347,8 @@ namespace cv
|
|||||||
CV_EXPORTS void remap(const GpuMat& src, const GpuMat& xmap, const GpuMat& ymap, GpuMat& dst);
|
CV_EXPORTS void remap(const GpuMat& src, const GpuMat& xmap, const GpuMat& ymap, GpuMat& dst);
|
||||||
|
|
||||||
// Does mean shift filtering on GPU.
|
// Does mean shift filtering on GPU.
|
||||||
CV_EXPORTS void meanShiftFiltering_GPU(const GpuMat& src, GpuMat& dst, int sp, int sr, TermCriteria criteria = TermCriteria(TermCriteria::MAX_ITER + TermCriteria::EPS, 5, 1));
|
CV_EXPORTS void meanShiftFiltering_GPU(const GpuMat& src, GpuMat& dst, int sp, int sr,
|
||||||
|
TermCriteria criteria = TermCriteria(TermCriteria::MAX_ITER + TermCriteria::EPS, 5, 1));
|
||||||
|
|
||||||
// Does coloring of disparity image: [0..ndisp) -> [0..240, 1, 1] in HSV.
|
// Does coloring of disparity image: [0..ndisp) -> [0..240, 1, 1] in HSV.
|
||||||
// Supported types of input disparity: CV_8U, CV_16S.
|
// Supported types of input disparity: CV_8U, CV_16S.
|
||||||
|
@ -163,7 +163,8 @@ namespace imgproc
|
|||||||
{
|
{
|
||||||
texture<uchar4, 2> tex_meanshift;
|
texture<uchar4, 2> tex_meanshift;
|
||||||
|
|
||||||
extern "C" __global__ void meanshift_kernel( unsigned char* out, int out_step, int cols, int rows, int sp, int sr, int maxIter, float eps )
|
extern "C" __global__ void meanshift_kernel( unsigned char* out, int out_step, int cols, int rows,
|
||||||
|
int sp, int sr, int maxIter, float eps )
|
||||||
{
|
{
|
||||||
int x0 = blockIdx.x * blockDim.x + threadIdx.x;
|
int x0 = blockIdx.x * blockDim.x + threadIdx.x;
|
||||||
int y0 = blockIdx.y * blockDim.y + threadIdx.y;
|
int y0 = blockIdx.y * blockDim.y + threadIdx.y;
|
||||||
@ -224,10 +225,8 @@ namespace imgproc
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
int base = (blockIdx.y * blockDim.y + threadIdx.y) * out_step + (blockIdx.x * blockDim.x + threadIdx.x) * 3 * sizeof(uchar);
|
int base = (blockIdx.y * blockDim.y + threadIdx.y) * out_step + (blockIdx.x * blockDim.x + threadIdx.x) * 4 * sizeof(uchar);
|
||||||
out[base+0] = c.x;
|
*(uchar4*)(out + base) = c;
|
||||||
out[base+1] = c.y;
|
|
||||||
out[base+2] = c.z;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -236,7 +235,7 @@ namespace cv { namespace gpu { namespace impl
|
|||||||
{
|
{
|
||||||
extern "C" void meanShiftFiltering_gpu(const DevMem2D& src, DevMem2D dst, int sp, int sr, int maxIter, float eps)
|
extern "C" void meanShiftFiltering_gpu(const DevMem2D& src, DevMem2D dst, int sp, int sr, int maxIter, float eps)
|
||||||
{
|
{
|
||||||
dim3 grid(1, 1, 1);
|
dim3 grid(1, 1, 1);
|
||||||
dim3 threads(32, 16, 1);
|
dim3 threads(32, 16, 1);
|
||||||
grid.x = divUp(src.cols, threads.x);
|
grid.x = divUp(src.cols, threads.x);
|
||||||
grid.y = divUp(src.rows, threads.y);
|
grid.y = divUp(src.rows, threads.y);
|
||||||
|
@ -119,18 +119,18 @@ void cv::gpu::meanShiftFiltering_GPU(const GpuMat& src, GpuMat& dst, int sp, int
|
|||||||
if( src.depth() != CV_8U || src.channels() != 4 )
|
if( src.depth() != CV_8U || src.channels() != 4 )
|
||||||
CV_Error( CV_StsUnsupportedFormat, "Only 8-bit, 4-channel images are supported" );
|
CV_Error( CV_StsUnsupportedFormat, "Only 8-bit, 4-channel images are supported" );
|
||||||
|
|
||||||
dst.create( src.size(), CV_8UC3 );
|
dst.create( src.size(), CV_8UC4 );
|
||||||
|
|
||||||
float eps;
|
|
||||||
if( !(criteria.type & TermCriteria::MAX_ITER) )
|
if( !(criteria.type & TermCriteria::MAX_ITER) )
|
||||||
criteria.maxCount = 5;
|
criteria.maxCount = 5;
|
||||||
|
|
||||||
int maxIter = std::min(std::max(criteria.maxCount, 1), 100);
|
int maxIter = std::min(std::max(criteria.maxCount, 1), 100);
|
||||||
|
|
||||||
|
float eps;
|
||||||
if( !(criteria.type & TermCriteria::EPS) )
|
if( !(criteria.type & TermCriteria::EPS) )
|
||||||
eps = 1.f;
|
eps = 1.f;
|
||||||
|
|
||||||
eps = (float)std::max(criteria.epsilon, 0.0);
|
eps = (float)std::max(criteria.epsilon, 0.0);
|
||||||
|
|
||||||
impl::meanShiftFiltering_gpu(src, dst, sp, sr, maxIter, eps);
|
impl::meanShiftFiltering_gpu(src, dst, sp, sr, maxIter, eps);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,82 +1,110 @@
|
|||||||
/*M///////////////////////////////////////////////////////////////////////////////////////
|
/*M///////////////////////////////////////////////////////////////////////////////////////
|
||||||
//
|
//
|
||||||
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
|
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
|
||||||
//
|
//
|
||||||
// By downloading, copying, installing or using the software you agree to this license.
|
// 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,
|
// If you do not agree to this license, do not download, install,
|
||||||
// copy or use the software.
|
// copy or use the software.
|
||||||
//
|
//
|
||||||
//
|
//
|
||||||
// Intel License Agreement
|
// Intel License Agreement
|
||||||
// For Open Source Computer Vision Library
|
// For Open Source Computer Vision Library
|
||||||
//
|
//
|
||||||
// Copyright (C) 2000, Intel Corporation, all rights reserved.
|
// Copyright (C) 2000, Intel Corporation, all rights reserved.
|
||||||
// Third party copyrights are property of their respective owners.
|
// Third party copyrights are property of their respective owners.
|
||||||
//
|
//
|
||||||
// Redistribution and use in source and binary forms, with or without modification,
|
// Redistribution and use in source and binary forms, with or without modification,
|
||||||
// are permitted provided that the following conditions are met:
|
// are permitted provided that the following conditions are met:
|
||||||
//
|
//
|
||||||
// * Redistribution's of source code must retain the above copyright notice,
|
// * Redistribution's of source code must retain the above copyright notice,
|
||||||
// this list of conditions and the following disclaimer.
|
// this list of conditions and the following disclaimer.
|
||||||
//
|
//
|
||||||
// * Redistribution's in binary form must reproduce the above copyright notice,
|
// * Redistribution's in binary form must reproduce the above copyright notice,
|
||||||
// this list of conditions and the following disclaimer in the documentation
|
// this list of conditions and the following disclaimer in the documentation
|
||||||
// and/or other materials provided with the distribution.
|
// and/or other materials provided with the distribution.
|
||||||
//
|
//
|
||||||
// * The name of Intel Corporation may not be used to endorse or promote products
|
// * The name of Intel Corporation may not be used to endorse or promote products
|
||||||
// derived from this software without specific prior written permission.
|
// derived from this software without specific prior written permission.
|
||||||
//
|
//
|
||||||
// This software is provided by the copyright holders and contributors "as is" and
|
// 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
|
// any express or implied warranties, including, but not limited to, the implied
|
||||||
// warranties of merchantability and fitness for a particular purpose are disclaimed.
|
// 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,
|
// In no event shall the Intel Corporation or contributors be liable for any direct,
|
||||||
// indirect, incidental, special, exemplary, or consequential damages
|
// indirect, incidental, special, exemplary, or consequential damages
|
||||||
// (including, but not limited to, procurement of substitute goods or services;
|
// (including, but not limited to, procurement of substitute goods or services;
|
||||||
// loss of use, data, or profits; or business interruption) however caused
|
// loss of use, data, or profits; or business interruption) however caused
|
||||||
// and on any theory of liability, whether in contract, strict liability,
|
// and on any theory of liability, whether in contract, strict liability,
|
||||||
// or tort (including negligence or otherwise) arising in any way out of
|
// 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.
|
// the use of this software, even if advised of the possibility of such damage.
|
||||||
//
|
//
|
||||||
//M*/
|
//M*/
|
||||||
|
|
||||||
#include "gputest.hpp"
|
#include "gputest.hpp"
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
#include <opencv2/opencv.hpp>
|
#include <opencv2/opencv.hpp>
|
||||||
#include <opencv2/gpu/gpu.hpp>
|
#include <opencv2/gpu/gpu.hpp>
|
||||||
|
|
||||||
class CV_GpuMeanShift : public CvTest
|
class CV_GpuMeanShift : public CvTest
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
CV_GpuMeanShift();
|
CV_GpuMeanShift();
|
||||||
protected:
|
protected:
|
||||||
void run(int);
|
void run(int);
|
||||||
};
|
};
|
||||||
|
|
||||||
CV_GpuMeanShift::CV_GpuMeanShift(): CvTest( "GPU-MeanShift", "MeanShift" ){}
|
CV_GpuMeanShift::CV_GpuMeanShift(): CvTest( "GPU-MeanShift", "MeanShift" ){}
|
||||||
|
|
||||||
void CV_GpuMeanShift::run(int )
|
void CV_GpuMeanShift::run(int)
|
||||||
{
|
{
|
||||||
int spatialRad = 30;
|
int spatialRad = 30;
|
||||||
int colorRad = 30;
|
int colorRad = 30;
|
||||||
|
|
||||||
cv::Mat img = cv::imread(std::string(ts->get_data_path()) + "meanshift/cones.png");
|
cv::Mat img = cv::imread(std::string(ts->get_data_path()) + "meanshift/cones.png");
|
||||||
cv::Mat img_template = cv::imread(std::string(ts->get_data_path()) + "meanshift/con_result.png");
|
cv::Mat img_template = cv::imread(std::string(ts->get_data_path()) + "meanshift/con_result.png");
|
||||||
|
|
||||||
cv::Mat rgba;
|
if (img.empty() || img_template.empty())
|
||||||
cvtColor(img, rgba, CV_BGR2BGRA);
|
{
|
||||||
|
ts->set_failed_test_info(CvTS::FAIL_MISSING_TEST_DATA);
|
||||||
cv::gpu::GpuMat res;
|
return;
|
||||||
|
}
|
||||||
cv::gpu::meanShiftFiltering_GPU( cv::gpu::GpuMat(rgba), res, spatialRad, colorRad );
|
|
||||||
|
cv::Mat rgba;
|
||||||
res.convertTo(res, img_template.type());
|
cvtColor(img, rgba, CV_BGR2BGRA);
|
||||||
|
|
||||||
double norm = cv::norm(res, img_template, cv::NORM_INF);
|
cv::gpu::GpuMat res;
|
||||||
if (norm >= 0.5) std::cout << "MeanShift norm = " << norm << std::endl;
|
cv::gpu::meanShiftFiltering_GPU( cv::gpu::GpuMat(rgba), res, spatialRad, colorRad );
|
||||||
ts->set_failed_test_info((norm < 0.5) ? CvTS::OK : CvTS::FAIL_GENERIC);
|
if (res.type() != CV_8UC4)
|
||||||
}
|
{
|
||||||
|
ts->set_failed_test_info(CvTS::FAIL_INVALID_OUTPUT);
|
||||||
|
return;
|
||||||
CV_GpuMeanShift CV_GpuMeanShift_test;
|
}
|
||||||
|
|
||||||
|
cv::Mat result;
|
||||||
|
res.download(result);
|
||||||
|
|
||||||
|
uchar maxDiff = 0;
|
||||||
|
for (int j = 0; j < result.rows; ++j)
|
||||||
|
{
|
||||||
|
const uchar* res_line = result.ptr<uchar>(j);
|
||||||
|
const uchar* ref_line = img_template.ptr<uchar>(j);
|
||||||
|
|
||||||
|
for (int i = 0; i < result.cols; ++i)
|
||||||
|
{
|
||||||
|
for (int k = 0; k < 3; ++k)
|
||||||
|
{
|
||||||
|
const uchar& ch1 = res_line[result.channels()*i + k];
|
||||||
|
const uchar& ch2 = ref_line[img_template.channels()*i + k];
|
||||||
|
uchar diff = abs(ch1 - ch2);
|
||||||
|
if (maxDiff < diff)
|
||||||
|
maxDiff = diff;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (maxDiff > 0)
|
||||||
|
ts->printf(CvTS::CONSOLE, "\nMeanShift maxDiff = %d\n", maxDiff);
|
||||||
|
ts->set_failed_test_info((maxDiff == 0) ? CvTS::OK : CvTS::FAIL_GENERIC);
|
||||||
|
}
|
||||||
|
|
||||||
|
CV_GpuMeanShift CV_GpuMeanShift_test;
|
@ -58,22 +58,28 @@ CV_GpuStereoBP::CV_GpuStereoBP(): CvTest( "GPU-StereoBP", "StereoBP" ){}
|
|||||||
|
|
||||||
void CV_GpuStereoBP::run(int )
|
void CV_GpuStereoBP::run(int )
|
||||||
{
|
{
|
||||||
cv::Mat img_l = cv::imread(std::string(ts->get_data_path()) + "stereobp/aloe-L.png");
|
cv::Mat img_l = cv::imread(std::string(ts->get_data_path()) + "stereobp/aloe-L.png");
|
||||||
cv::Mat img_r = cv::imread(std::string(ts->get_data_path()) + "stereobp/aloe-R.png");
|
cv::Mat img_r = cv::imread(std::string(ts->get_data_path()) + "stereobp/aloe-R.png");
|
||||||
cv::Mat img_template = cv::imread(std::string(ts->get_data_path()) + "stereobp/aloe-disp.png", 0);
|
cv::Mat img_template = cv::imread(std::string(ts->get_data_path()) + "stereobp/aloe-disp.png", 0);
|
||||||
|
|
||||||
cv::gpu::GpuMat disp;
|
if (img_l.empty() || img_r.empty() || img_template.empty())
|
||||||
cv::gpu::StereoBeliefPropagation bpm(64, 8, 2, 25, 0.1f, 15, 1, CV_16S);
|
{
|
||||||
|
ts->set_failed_test_info(CvTS::FAIL_MISSING_TEST_DATA);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
bpm(cv::gpu::GpuMat(img_l), cv::gpu::GpuMat(img_r), disp);
|
cv::gpu::GpuMat disp;
|
||||||
|
cv::gpu::StereoBeliefPropagation bpm(64, 8, 2, 25, 0.1f, 15, 1, CV_16S);
|
||||||
|
|
||||||
//cv::imwrite(std::string(ts->get_data_path()) + "stereobp/aloe-disp.png", disp);
|
bpm(cv::gpu::GpuMat(img_l), cv::gpu::GpuMat(img_r), disp);
|
||||||
|
|
||||||
disp.convertTo(disp, img_template.type());
|
//cv::imwrite(std::string(ts->get_data_path()) + "stereobp/aloe-disp.png", disp);
|
||||||
|
|
||||||
double norm = cv::norm(disp, img_template, cv::NORM_INF);
|
disp.convertTo(disp, img_template.type());
|
||||||
if (norm >= 0.5) std::cout << "StereoBP norm = " << norm << std::endl;
|
|
||||||
ts->set_failed_test_info((norm < 0.5) ? CvTS::OK : CvTS::FAIL_GENERIC);
|
double norm = cv::norm(disp, img_template, cv::NORM_INF);
|
||||||
|
if (norm >= 0.5) std::cout << "StereoBP norm = " << norm << std::endl;
|
||||||
|
ts->set_failed_test_info((norm < 0.5) ? CvTS::OK : CvTS::FAIL_GENERIC);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user