illid44n
illid44n

Reputation: 57

OpenCV | Mat to gpuMat Exception at memory location?

I'm having a problem trying to convert from cv::Mat to gpu::Mat. I'm using VS2012 Win7 x64.

this is the code:

#include "opencv2/imgproc/imgproc.hpp"
#include <opencv2/opencv.hpp>
#include "opencv2/highgui/highgui.hpp"
#include <opencv2\gpu\gpu.hpp>
#include "cv.h"
#include "cxcore.h"
#include <stdarg.h>
#include <stdlib.h>
#include <stdio.h>
#include <iostream>

using namespace cv;
using namespace cv::gpu;

int main () {

Mat src = cv::imread("pic1.jpg");
gpu::GpuMat d_src, d_dst;

d_src.upload(src);

gpu::bilateralFilter(d_src,d_dst, -1, 50, 7 );
gpu::Canny(d_dst, d_dst, 35, 200, 3);

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

I'm using so many includes because in the same file i have other functions declared.

This are the lib files i included:

opencv_core246d.lib
opencv_imgproc246d.lib
opencv_highgui246d.lib
opencv_ml246d.lib
opencv_video246d.lib
opencv_features2d246d.lib
opencv_calib3d246d.lib
opencv_objdetect246d.lib
opencv_contrib246d.lib
opencv_legacy246d.lib
opencv_flann246d.lib
opencv_nonfree246d.lib
opencv_photo246d.lib
opencv_stitching246d.lib
opencv_superres246d.lib
opencv_ts246d.lib

This is what i get when i try to compile

First-chance exception at 0x000007FEFDD29E5D in CVtest.exe: Microsoft C++ exception:      cv::Exception at memory location 0x000000000025F8D0.
First-chance exception at 0x000007FEFDD29E5D in CVtest.exe: Microsoft C++ exception: cv::Exception at memory location 0x000000000025F8D0.
Unhandled exception at at 0x000007FEFDD29E5D in CVtest.exe: Microsoft C++ exception: cv::Exception at memory location 0x000000000025F8D0.
The program '[6592] CVtest.exe' has exited with code -1073741510 (0xc000013a).

It shows whenever i try to change between Mat and gpuMat.

How may i fix this ?

Upvotes: 1

Views: 2877

Answers (1)

Dyrborg
Dyrborg

Reputation: 877

I had the same issue when uploading / downloading on my Windows computer using the GPU module on OpenCV with VS2010. I was using the precompiled 2.4.6 binaries that you could download on the OpenCV site.

You need to ensure that CUDA+OpenGL is enabled on your card (assuming you have a CUDA enabled GPU). First thing you need to do is run (or equivalent if using just C):

cout << cv::getBuildInformation() << endl;

This will tell you what you have enabled or not in your OpenCV build. It will print a lot of info but look for where it prints "Other third-party libraries":

Other third-party libraries:
    Use IPP:                     NO
    Use Eigen:                   NO
    Use TBB:                     NO
    Use OpenMP:                  NO
    Use GCD                      NO
    Use Concurrency              YES
    Use C=:                      NO
    Use Cuda:                    NO
    Use OpenCL:                  NO

If both Use Cuda and/or Use OpenCL says NO then your program will crash whenever you call GPU functions like upload and download.

To solve it your need to compile OpenCV with these technologies enabled. For Windows I followed this guide:

http://www.programmerfish.com/how-to-build-opencv-2-4-6-with-gpu-module-in-windows/#.UpuDQcRLNBm

After compiling a 2.4.7 version with OpenGL and CUDA support everything worked flawlessly for me.

Upvotes: 2

Related Questions