Commit 26c48596 authored by Vladislav Vinogradov's avatar Vladislav Vinogradov

reduced code convert_to by using templates, merged with copyTo

parent a0b1107b
This diff is collapsed.
...@@ -114,8 +114,6 @@ void cv::gpu::GpuMat::copyTo( GpuMat& mat, const GpuMat& mask ) const ...@@ -114,8 +114,6 @@ void cv::gpu::GpuMat::copyTo( GpuMat& mat, const GpuMat& mask ) const
void cv::gpu::GpuMat::convertTo( GpuMat& dst, 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");
bool noScale = fabs(alpha-1) < std::numeric_limits<double>::epsilon() && fabs(beta) < std::numeric_limits<double>::epsilon(); bool noScale = fabs(alpha-1) < std::numeric_limits<double>::epsilon() && fabs(beta) < std::numeric_limits<double>::epsilon();
if( rtype < 0 ) if( rtype < 0 )
...@@ -124,11 +122,11 @@ void cv::gpu::GpuMat::convertTo( GpuMat& dst, int rtype, double alpha, double be ...@@ -124,11 +122,11 @@ void cv::gpu::GpuMat::convertTo( GpuMat& dst, int rtype, double alpha, double be
rtype = CV_MAKETYPE(CV_MAT_DEPTH(rtype), channels()); rtype = CV_MAKETYPE(CV_MAT_DEPTH(rtype), channels());
int sdepth = depth(), ddepth = CV_MAT_DEPTH(rtype); int sdepth = depth(), ddepth = CV_MAT_DEPTH(rtype);
/*if( sdepth == ddepth && noScale ) if( sdepth == ddepth && noScale )
{ {
copyTo(dst); copyTo(dst);
return; return;
}*/ }
GpuMat temp; GpuMat temp;
const GpuMat* psrc = this; const GpuMat* psrc = this;
......
...@@ -26,7 +26,7 @@ void CV_GpuMatOpConvertTo::run( int /* start_from */) ...@@ -26,7 +26,7 @@ void CV_GpuMatOpConvertTo::run( int /* start_from */)
{ {
const Size img_size(67, 35); 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[] = {CV_8U, CV_8S, CV_16U, CV_16S, CV_32S, CV_32F, CV_64F};
const int types_num = sizeof(types) / sizeof(int); 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"}; const char* types_str[] = {"CV_8U", "CV_8S", "CV_16U", "CV_16S", "CV_32S", "CV_32F", "CV_64F"};
...@@ -39,9 +39,6 @@ void CV_GpuMatOpConvertTo::run( int /* start_from */) ...@@ -39,9 +39,6 @@ void CV_GpuMatOpConvertTo::run( int /* start_from */)
{ {
for (int c = 1; c < 2 && passed; ++c) for (int c = 1; c < 2 && passed; ++c)
{ {
//if (i == j)
// continue;
const int src_type = CV_MAKETYPE(types[i], c); const int src_type = CV_MAKETYPE(types[i], c);
const int dst_type = types[j]; const int dst_type = types[j];
const double alpha = (double)rand() / RAND_MAX * 10.0; const double alpha = (double)rand() / RAND_MAX * 10.0;
...@@ -53,30 +50,34 @@ void CV_GpuMatOpConvertTo::run( int /* start_from */) ...@@ -53,30 +50,34 @@ void CV_GpuMatOpConvertTo::run( int /* start_from */)
Mat cpumatdst; Mat cpumatdst;
GpuMat gpumatdst; GpuMat gpumatdst;
//double cput = (double)getTickCount(); //TickMeter tm;
//tm.start();
//for(int i = 0; i < 50; ++i)
cpumatsrc.convertTo(cpumatdst, dst_type, alpha, beta); cpumatsrc.convertTo(cpumatdst, dst_type, alpha, beta);
//cput = ((double)getTickCount() - cput) / getTickFrequency(); //tm.stop();
//cout << "SRC_TYPE=" << types_str[i] << "C" << c << " DST_TYPE=" << types_str[j] << endl << "\tCPU FPS = " << 50.0/tm.getTimeSec() << endl;
//double gput = (double)getTickCount(); //tm.reset();
gpumatsrc.convertTo(gpumatdst, dst_type, alpha, beta);
//gput = ((double)getTickCount() - gput) / getTickFrequency();
/*cout << "convertTo time: " << endl; try
cout << "CPU time: " << cput << endl; {
cout << "GPU time: " << gput << endl;/**/ //tm.start();
//for(int i = 0; i < 50; ++i)
gpumatsrc.convertTo(gpumatdst, dst_type, alpha, beta);
//tm.stop();
//cout << "\tGPU FPS = " << 50.0/tm.getTimeSec() << endl;
}
catch(cv::Exception& e)
{
cout << "ERROR: " << e.err << endl;
passed = false;
break;
}
double r = norm(cpumatdst, gpumatdst, NORM_L1); double r = norm(cpumatdst, gpumatdst, NORM_INF);
if (r > 1) if (r > 1)
{ {
/*namedWindow("CPU"); cout << "FAILED: " << "SRC_TYPE=" << types_str[i] << "C" << c << " DST_TYPE=" << types_str[j] << " NORM = " << r << endl;
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; passed = false;
} }
......
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