简体   繁体   English

使用GPU(C ++ / OpenCV)从文件显示图像

[英]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 ). 我正在举一个使用GPU来通过C ++ / OpenCV处理和显示文件图像的示例(来自此处: 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. 不过,我不断收到一个错误,说明d_dst是不确定的gpu::GpuMat d_src(src)gpu::GpuMat d_dst部分。 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. 我是所有这些的新手,因此不确定我是否错过了其他依赖项,标头,还是需要使用Visual Studio 2012安装/配置某些GPU组件。

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 . 但是,即使用imshow代替了imwrite行,也不会显示图像。 EDIT I now realise that my code is getting stopped at the if (!src.data) exit(1); 编辑现在我意识到我的代码在if (!src.data) exit(1);停止了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. 注意-我可能不需要所有这些#includes但是好吧。

Try to include core.hpp. 尝试包括core.hpp。 In my case it is located in opencv2/core/core.hpp 就我而言,它位于opencv2 / core / core.hpp中

And you have to fix your function calls for bilateralFilter(...) and Canny(...). 而且您必须修复对bilateralFilter(...)和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). 您还没有提到有关您的开发环境的任何信息(Win,Linux,Android,OpenCV版本)。

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! 酷!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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