Attention! This forum will be made read-only by Dec-20. Please migrate to Most of existing active users should've received invitation by e-mail.
Ask Your Question

OpenCV Error: Gpu API call

asked 2016-02-03 09:16:16 -0500

alexrn gravatar image


I am using openCV for my first time, and I'm having some problems. The matter is that I want to use the CUDA functionallity, but it gives me an error:

OpenCV Error: Gpu API call (NCV Assertion Failed: NcvStat=25, file=/home/alex/Downloads/opencv-3.0.0/modules/cudalegacy/src/cuda/, line=2421) in NCVDebugOutputHandler, file /home/alex/Downloads/opencv-3.0.0/modules/cudaobjdetect/src/cascadeclassifier.cpp, line 156
terminate called after throwing an instance of 'cv::Exception'
  what():  /home/alex/Downloads/opencv-3.0.0/modules/cudaobjdetect/src/cascadeclassifier.cpp:156: error: (-217) NCV Assertion Failed: NcvStat=25, file=/home/alex/Downloads/opencv-3.0.0/modules/cudalegacy/src/cuda/, line=2421 in function NCVDebugOutputHandler

What I'm trying to do is only to measure the time that CUDA lasts to process my image, here is the code:

#include "opencv2/objdetect/objdetect.hpp"
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/imgproc/imgproc.hpp"
#include "opencv2/cudaobjdetect.hpp"
#include "opencv2/cudaimgproc.hpp"
#include "opencv2/cudawarping.hpp"

#include <iostream>
#include <time.h>

using namespace std;
using namespace cv;

int main(){

    vector<Rect> faces;
    Mat image = imread("image.jpg");
    Mat imageGray;
    cuda::GpuMat imageGPU(image);
    String s = "cuda.xml";

    Ptr<cuda::CascadeClassifier> _faceCascade = cuda::CascadeClassifier::create("cuda.xml");

    cuda::GpuMat objectBuffer;
    clock_t t_ini, t_fin;
    double secs;

    t_ini = clock();
    _faceCascade->detectMultiScale(imageGPU, objectBuffer);
    t_fin = clock();

    _faceCascade->convert(objectBuffer, faces);

    secs = (double)(t_fin - t_ini) / CLOCKS_PER_SEC;
    cout << secs * 1000 << "milliseconds" << endl;

    for (int i = 0; i < int(faces.size()); i++){
        cv::rectangle(image, faces[i], Scalar(255));

    imshow("Result", image);

    return 0;


I'm working with Eclipse and CUDA 7.5


edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted

answered 2017-03-14 23:16:30 -0500

NCVStat error codes can be found in NCV.hpp, particularly 25 = NCV_HAAR_XML_LOADING_EXCEPTION. This means there was a problem loading the xml. This could be that the path to the xml is incorrect, or that the program does not have read access to the file. I would suggest confirming those to be non-issues, and if that fails, provide the source for cuda.xml (I did search for it in opencv/data) so users on this forum may test it.

edit flag offensive delete link more
Login/Signup to Answer

Question Tools

1 follower


Asked: 2016-02-03 09:16:16 -0500

Seen: 1,088 times

Last updated: Feb 03 '16