简体   繁体   中英

Display Image from File using GPU (C++ / OpenCV)

I'm following an example to use the GPU to manipulate and display an image from file with C++ / OpenCV (from here: http://on-demand.gputechconf.com/gtc/2013/webinar/opencv-gtc-express-shalini-gupta.pdf ). The code is:

#include <opencv2/opencv.hpp>
#include <opencv2/gpu/gpu.hpp>
#include <opencv2/gpu/gpumat.hpp>
using namespace cv;
int main()
{
    Mat src = imread("car1080.jpg", 0);
    if (!src.data) exit(1);
    gpu::GpuMat d_src(src);
    gpu::GpuMat d_dst;
    gpu::bilateralFilter(d_src, gpu::Canny(d_dst, d_dst, 35, 200, 3);
    Mat dst(d_dst);
    imshow("out.png", dst);
    return 0;
}

However, I keep getting an error stating d_dst is undefined for the gpu::GpuMat d_src(src) and gpu::GpuMat d_dst sections. From what I've read this is because I haven't included a file, a declaration or something else.

Below is a list of my additional dependencies:

opencv_calib3d249d.lib
opencv_contrib249d.lib
opencv_core249d.lib
opencv_features2d249d.lib
opencv_flann249d.lib
opencv_gpu249d.lib
opencv_highgui249d.lib
opencv_imgproc249d.lib
opencv_legacy249d.lib
opencv_ml249d.lib
opencv_nonfree249d.lib
opencv_objdetect249d.lib
opencv_photo249d.lib
opencv_stitching249d.lib
opencv_superres249d.lib
opencv_ts249d.lib
opencv_video249d.lib
opencv_videostab249d.lib

I'm new to all of this so I'm unsure whether I've missed an additional dependency, a header or need to install / configure some GPU component with Visual Studio 2012.

Any help would be greatly appreciated! Thanks!

UPDATE : Below is my new code which compiles fine; however, no image is displayed even when the imwrite line is replaced with imshow . EDIT I now realise that my code is getting stopped at the if (!src.data) exit(1); line presumably because the image file is not being read properly?

#include <stdio.h>
#include <direct.h>
#include "fstream"
#include "iostream"
#include <vector>
#include "opencv2/core/core.hpp"
#include "opencv2/core/gpumat.hpp"
#include "opencv2/core/opengl_interop.hpp"
#include "opencv2/gpu/gpu.hpp"
#include "opencv2/ml/ml.hpp"
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/contrib/contrib.hpp"
#include "opencv2/video/tracking.hpp"
#include "opencv2/imgproc/imgproc.hpp"

int main(){
Mat src = imread("car.jpg", 0);
if (!src.data) exit(1);

gpu::GpuMat d_src(src);
gpu::GpuMat d_dst;

gpu::bilateralFilter(d_src, d_dst,15, 80,80);

Mat dst(d_dst);
imwrite("out.png", dst);
return 0;
}

Note - I probably don't need all those #includes but oh well.

Try to include core.hpp. In my case it is located in opencv2/core/core.hpp

And you have to fix your function calls for bilateralFilter(...) and Canny(...). The argument number is wrong.

Somegthing like this:

int main(){
Mat src = imread("car.jpg", 0);
if (!src.data) exit(1);

gpu::GpuMat d_src(src);
gpu::GpuMat d_dst;

gpu::bilateralFilter(d_src, d_dst,15, 80,80);

Mat dst(d_dst);
imwrite("out.png", dst);
return 0;
}

You haven't mentioned anything about your development environment... (Win,Linux,Android,OpenCV version).

I work on a tegra board so things might be a little bit different for me.I tried out the example on my development environment. And it worked just fine.

在此处输入图片说明

在此处输入图片说明

cool hu!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM