0

How can I use Mat's pointer to create the GPUMat entity?

The following of my implementation is wrong.

#include<opencv2/opencv.hpp>

#include "opencv2/gpu/gpu.hpp"
//using namespace cv;
int main()
{
    //Mat img = imread();
    cv::Mat mSource = cv::imread("C:\\New Folder\\1.jpg");
    cv::gpu::GpuMat gpuInput(mSource.rows, mSource.cols, CV_32FC1, mSource.data, cv::Mat::AUTO_STEP);       

    cv::gpu::GpuMat  mGTarget;
    cv::gpu::resize(gpuInput, mGTarget, cv::Size(0, 0), 0.5, 0.5);

    cv::Mat mTarget;
    mGTarget.download(mTarget);

    cv::imwrite("C:\\New Folder\\5.jpg", mTarget);
}
talonmies
  • 70,661
  • 34
  • 192
  • 269
md612
  • 300
  • 2
  • 5
  • 20

1 Answers1

2

Use the GpuMat::upload and GpuMat::download functions. The upload function takes a cv::Mat as parameter and uploads the host data to device.

GpuMat gpuInput;
gpuInput.upload(mSource);
zindarod
  • 6,328
  • 3
  • 30
  • 58
  • @md612 Why exactly do you want to do that? – zindarod Oct 17 '17 at 09:43
  • I have one similiar application which has the same problem -- https://stackoverflow.com/questions/46658100/how-to-turn-opencv-gpumat-into-cudeviceptr/46663438?noredirect=1#comment80275867_46663438. – md612 Oct 17 '17 at 09:45
  • @md612 The decoded frame is most probably single channel YUV frame, and you're providing `CV_8UC3` as image type. You've to make sure what is the type of the decoded frame. – zindarod Oct 17 '17 at 10:42