Ask Your Question
0

cv::WarpPerspective & cv::cuda::WarpPerspective issue

asked 2019-06-10 10:20:48 -0600

ADADAS gravatar image

updated 2019-06-11 02:13:59 -0600

Hi everyone

I encountered an issue using the warp perspective function. Up until today, i used the standard cv::warpPerspective function to create a Bird View of an image. I wanted to increase the performance of the algorithm so i shifted the calculation on the gpu using cuda::warperspective with exactly the same parameters. The output image is totally wrong, with the cuda function .... I don't understand where this error could come from ...

If you have any idea where the problem could come from, that would be awesome

GPU Image : image description

CPU Image : image description

The function doing the transform is presented below. The only change done to the code to create on of the image is the comment on the function used (either std cv::Warp or cv::cuda:warp)

The cv::Mat input image is a single channel image (L from Lab colorspace) which was transformed with a canny filter (using the gpu function as well)

static cv::Mat InversePerspectiveMapping(cv::Mat input, int w, int h, bool transform_order, bool display, int n) // w : width and h : height


cv::Mat output, M;  //create the output matrice

if (transform_order == true)    {M = cv::getPerspectiveTransform(src_pts, dst_pts); } // calculation of the transform matrix 
else                {M = cv::getPerspectiveTransform(dst_pts, src_pts); } // Calculation of the inverse transfrom matrix

//cv::warpPerspective( input, output, M, cv::Size(w,h), INTER_LINEAR , BORDER_CONSTANT, 0 );  

cv::cuda::GpuMat gpuInput = cv::cuda::GpuMat(input);
cv::cuda::warpPerspective( gpuInput, gpuInput, M, cv::Size(w,h), INTER_LINEAR , BORDER_CONSTANT, 0, Stream::Null() );  
gpuInput.download(output);
gpuInput.release();
imshow("left_IPM", output);
return output;

Thanks again for your help

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
1

answered 2019-06-13 08:21:01 -0600

ADADAS gravatar image

Hi

Well the solution was easy .. found it here

I needed to assign a gpuMat for the output. The code becomes :

static cv::Mat InversePerspectiveMapping(cv::Mat input, int w, int h, bool transform_order, bool display, int n) // w : width and h : height


cv::Mat output, M;  //create the output matrice

if (transform_order == true)    {M = cv::getPerspectiveTransform(src_pts, dst_pts); } // calculation of the transform matrix 
else                {M = cv::getPerspectiveTransform(dst_pts, src_pts); } // Calculation of the inverse transfrom matrix


cv::cuda::GpuMat gpuOutput; 
cv::cuda::GpuMat gpuInput = cv::cuda::GpuMat(input);

cv::cuda::warpPerspective( gpuInput, gpuOutput, M, cv::Size(w,h), INTER_LINEAR , BORDER_CONSTANT, 0, Stream::Null() );  

gpuOutput.download(output);
gpuOutput.release();
gpuInput.release();

imshow("left_IPM", output);
return output;
edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2019-06-10 10:20:48 -0600

Seen: 3,694 times

Last updated: Jun 13 '19