Skip to content

In-place flip of GpuMat produces image artifacs #17840

@jacobideum

Description

@jacobideum
System information (version)
  • OpenCV => 4.3.0
  • Operating System / Platform => Windows 64 Bit
  • Compiler => Visual Studio 2019/NVCC
Detailed description

When uploading an Mat to a GpuMat called x, using cv::cuda::resize to downscale x into a new GpuMat called y, and finally flipping that image along the vertical axis by passing y as both the src and dst argument of cv::cuda::flip, major image fragmentation is produced on the right side of the y.

Here's a code example:

#include <opencv2/opencv.hpp>
#include <opencv2/cudaarithm.hpp>
#include <opencv2/cudawarping.hpp>
#include <iostream>

using namespace cv;

const int kDownscaleFactor = 3;

int main(int argc, char** argv) {
	Mat image;
	image = imread("img.jpg", IMREAD_COLOR);

	cuda::GpuMat downscaled;
	cuda::GpuMat flipped;
	downscaled.upload(image);
	cuda::resize(downscaled, flipped, Size(image.size[0] / kDownscaleFactor, image.size[1] / kDownscaleFactor));
	cuda::flip(flipped, flipped, 1);
	flipped.download(image);

	namedWindow("Glitchy Image", WINDOW_AUTOSIZE);
	imshow("Glitchy Image", image);
	waitKey(0);

	return 0;
}

Capture

However, using a new GpuMat variable as the argument for the dst parameter of cv::cuda::flip (not the same one as src), this error is not produced.

Here is a zip file containing an executable demonstrating this error and the source code needed to reproduce it.

Steps to reproduce
  1. Upload a Mat object to the GPU into a GpuMat x.
  2. Downscale x into a GpuMat y by calling cv::cuda::resize(x, y, Size(...));
  3. Flip y along the vertical axis by calling cv::cuda::flip(y, y, 1); noting that y is passed as both the source and destination matrix to cv::cuda::flip.
  4. Calling y.download(...) and displaying the results demonstrates significant image fragmentation.
Issue submission checklist
  • I report the issue, it's not a question
  • I checked the problem with documentation, FAQ, open issues,
    answers.opencv.org, Stack Overflow, etc and have not found solution
  • I updated to latest OpenCV version and the issue is still there
  • There is reproducer code and related data files: videos, images, onnx, etc

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugcategory: gpu/cuda (contrib)OpenCV 4.0+: moved to opencv_contribconfirmedThere is stable reproducer / investigation complete

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions