Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

cuda::meanShiftSegmentation - Assertion Failed Error

Hi. I'm new to using CUDA with OpenCV so this might be a very simple error but I'm kinda stuck. My code is the following:

#include <opencv2/opencv.hpp>
#include <opencv2/cudaimgproc.hpp>
#include <stdio.h>
#include <omp.h>
#include <string>
using namespace cv;

int main( int argc, char** argv )
{
    cuda::setDevice(0);
    Mat pictureBGR;
    Mat pictureSegment;
    cuda::GpuMat bgr;

    std::cout << cuda::getCudaEnabledDeviceCount() << std::endl;
    pictureBGR = imread("2.jpg"); //unos slike za pretragu
    if(!pictureBGR.data)
    {
        std::cout << "Error loading image!" << std::endl;
        return -1;
    }

    bgr.upload(pictureBGR);
    //cuda::cvtColor(bgr, bgr, COLOR_BGR2BGRA, CV_8UC4);

    TermCriteria criteria(CV_TERMCRIT_EPS, 0, 0.008);
    cuda::meanShiftSegmentation(bgr, bgr, 20, 20, 10, criteria);

    namedWindow("Display Image", CV_WINDOW_AUTOSIZE);
    imshow("Display Image", bgr);
    waitKey(0);
    return 0;
}

And i'm getting the following error:

Assertion failed (src.type() == CV_8UC4) in meanShiftSegmentation, file /home/zburazin/opencv-3.0.0/modules/cudaimgproc/src/mssegmentation.cpp, line 229
terminate called after throwing an instance of 'cv::Exception'
  what():  /home/zburazin/opencv-3.0.0/modules/cudaimgproc/src/mssegmentation.cpp:229: error: (-215) src.type() == CV_8UC4 in function meanShiftSegmentation

I understand that the meanShiftSegmentation only takes GpuMat of type 8UC4, but I am still to find a solution to convert it. Any ideas?

std::cout << cuda::getCudaEnabledDeviceCount() << std::endl; returns 1 btw.

cuda::meanShiftSegmentation - Assertion Failed Error

Hi. I'm new to using CUDA with OpenCV so this might be a very simple error but I'm kinda stuck. My code is the following:

#include <opencv2/opencv.hpp>
#include <opencv2/cudaimgproc.hpp>
#include <stdio.h>
#include <omp.h>
#include <string>
using namespace cv;

int main( int argc, char** argv )
{
    cuda::setDevice(0);
    Mat pictureBGR;
 Mat pictureSegment;
 cuda::GpuMat bgr;
 cuda::GpuMat convertedBgr;
cuda::GpuMat dstBgr;

std::cout << cuda::getCudaEnabledDeviceCount() << std::endl;
 pictureBGR = imread("2.jpg"); //unos slike za pretragu
 if(!pictureBGR.data)
 {
     std::cout << "Error loading image!" "Gre\u0161ka pri u\u010ditavanju slike!" << std::endl;
     return -1;
 }

 bgr.upload(pictureBGR);
    //cuda::cvtColor(bgr, bgr, COLOR_BGR2BGRA, CV_8UC4);

    cuda::cvtColor(bgr, convertedBgr, CV_BGR2BGRA);

TermCriteria criteria(CV_TERMCRIT_EPS, 0, 0.008);
    cuda::meanShiftSegmentation(bgr, bgr, 0.08);
cuda::meanShiftSegmentation(convertedBgr, dstBgr, 20, 20, 10, 3, criteria);
 dstBgr.download(pictureSegment);

namedWindow("Display Image", CV_WINDOW_AUTOSIZE);
 imshow("Display Image", bgr);
    pictureSegment);
waitKey(0);
    return 0;
}

And i'm getting the following error:

Assertion failed (src.type() == CV_8UC4) in meanShiftSegmentation, file /home/zburazin/opencv-3.0.0/modules/cudaimgproc/src/mssegmentation.cpp, line 229
terminate called after throwing an instance of 'cv::Exception'
  what():  /home/zburazin/opencv-3.0.0/modules/cudaimgproc/src/mssegmentation.cpp:229: error: (-215) src.type() == CV_8UC4 in function meanShiftSegmentation

I understand that the meanShiftSegmentation only takes GpuMat of type 8UC4, but I am still to find a solution to convert it. Any ideas?

std::cout << cuda::getCudaEnabledDeviceCount() << std::endl; returns 1 btw.