Commit 3f5dd5f1 authored by Vladislav Vinogradov's avatar Vladislav Vinogradov

added implementation GpuMat::convertTo and merged this with matrix_operations.cpp

parent 7bf29e14
......@@ -51,6 +51,7 @@ namespace cv
namespace gpu
{
typedef unsigned char uchar;
typedef signed char schar;
typedef unsigned short ushort;
typedef unsigned int uint;
......@@ -62,6 +63,8 @@ namespace cv
extern "C" void set_to_without_mask (const DevMem2D& mat, const double * scalar, int depth, int channels);
extern "C" void set_to_with_mask (const DevMem2D& mat, const double * scalar, const DevMem2D& mask, int depth, int channels);
extern "C" void convert_to(const DevMem2D& src, int sdepth, DevMem2D dst, int ddepth, size_t width, size_t height, double alpha, double beta);
}
}
}
......
This diff is collapsed.
......@@ -104,9 +104,31 @@ void cv::gpu::GpuMat::copyTo( GpuMat& /*m*/, const GpuMat&/* mask */) const
CV_Assert(!"Not implemented");
}
void cv::gpu::GpuMat::convertTo( GpuMat& /*m*/, int /*rtype*/, double /*alpha*/, double /*beta*/ ) const
void cv::gpu::GpuMat::convertTo( GpuMat& dst, int rtype, double alpha, double beta ) const
{
CV_Assert(!"Not implemented");
//CV_Assert(!"Not implemented");
bool noScale = fabs(alpha-1) < std::numeric_limits<double>::epsilon() && fabs(beta) < std::numeric_limits<double>::epsilon();
if( rtype < 0 )
rtype = type();
else
rtype = CV_MAKETYPE(CV_MAT_DEPTH(rtype), channels());
int sdepth = depth(), ddepth = CV_MAT_DEPTH(rtype);
/*if( sdepth == ddepth && noScale )
{
copyTo(dst);
return;
}*/
GpuMat temp;
const GpuMat* psrc = this;
if( sdepth != ddepth && psrc == &dst )
psrc = &(temp = *this);
dst.create( size(), rtype );
impl::convert_to(*psrc, sdepth, dst, ddepth, psrc->cols * psrc->channels(), psrc->rows, alpha, beta);
}
GpuMat& GpuMat::operator = (const Scalar& s)
......
......@@ -51,6 +51,7 @@
#endif
#include <iostream>
#include <limits>
#include "opencv2/gpu/gpu.hpp"
......
#include "gputest.hpp"
#include <string>
#include <iostream>
#include <fstream>
#include <iterator>
#include <limits>
#include <numeric>
using namespace cv;
using namespace std;
using namespace gpu;
class CV_GpuMatOpConvertTo : public CvTest
{
public:
CV_GpuMatOpConvertTo();
~CV_GpuMatOpConvertTo();
protected:
void run(int);
};
CV_GpuMatOpConvertTo::CV_GpuMatOpConvertTo(): CvTest( "GpuMatOperatorConvertTo", "convertTo" ) {}
CV_GpuMatOpConvertTo::~CV_GpuMatOpConvertTo() {}
void CV_GpuMatOpConvertTo::run( int /* start_from */)
{
const Size img_size(67, 35);
const int types[] = {CV_8U, CV_8S, CV_16U, CV_16S, CV_32S, CV_32F, CV_64F/**/};
const int types_num = sizeof(types) / sizeof(int);
const char* types_str[] = {"CV_8U", "CV_8S", "CV_16U", "CV_16S", "CV_32S", "CV_32F", "CV_64F"};
bool passed = true;
for (int i = 0; i < types_num && passed; ++i)
{
for (int j = 0; j < types_num && passed; ++j)
{
for (int c = 1; c < 2 && passed; ++c)
{
//if (i == j)
// continue;
const int src_type = CV_MAKETYPE(types[i], c);
const int dst_type = types[j];
const double alpha = (double)rand() / RAND_MAX * 10.0;
const double beta = (double)rand() / RAND_MAX * 10.0;
Mat cpumatsrc(img_size, src_type);
randu(cpumatsrc, Scalar::all(0), Scalar::all(10));
GpuMat gpumatsrc(cpumatsrc);
Mat cpumatdst;
GpuMat gpumatdst;
//double cput = (double)getTickCount();
cpumatsrc.convertTo(cpumatdst, dst_type, alpha, beta);
//cput = ((double)getTickCount() - cput) / getTickFrequency();
//double gput = (double)getTickCount();
gpumatsrc.convertTo(gpumatdst, dst_type, alpha, beta);
//gput = ((double)getTickCount() - gput) / getTickFrequency();
/*cout << "convertTo time: " << endl;
cout << "CPU time: " << cput << endl;
cout << "GPU time: " << gput << endl;/**/
double r = norm(cpumatdst, gpumatdst, NORM_L1);
if (r > 1)
{
/*namedWindow("CPU");
imshow("CPU", cpumatdst);
namedWindow("GPU");
imshow("GPU", gpumatdst);
waitKey();/**/
cout << "Failed:" << endl;
cout << "\tr = " << r << endl;
cout << "\tSRC_TYPE=" << types_str[i] << "C" << c << " DST_TYPE=" << types_str[j] << endl;/**/
passed = false;
}
}
}
}
ts->set_failed_test_info(passed ? CvTS::OK : CvTS::FAIL_GENERIC);
}
CV_GpuMatOpConvertTo CV_GpuMatOpConvertTo_test;
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment