convert a program from c opencv to cuda

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

convert a program from c opencv to cuda

opencv-users mailing list
hello everybody,how can tell me if w can change a program from c opencv to cuda code and thank you in advance.
Reply | Threaded
Open this post in threaded view
|

Re: convert a program from c opencv to cuda

keghn
/*
Nvida GPUs on Linux Mint 17. A Ubuntu 14.04 clone.

compiled with:

nvcc pro.cu -o pro `pkg-config --cflags --libs opencv` -lopencv_gpu


*/
#include <iostream>
#include "opencv2/opencv.hpp"
#include "opencv2/core.hpp"
#include "opencv2/highgui.hpp"
#include "opencv2/cudaarithm.hpp"

using namespace cv;

int main (int argc, char* argv[])
{
    try
    {
//        cv::Mat src_host = cv::imread("file.png", cv::IMREAD_GRAYSCALE);
//        cv::Mat src_host = cv::imread("Fruit_Bat.jpg", cv::IMREAD_GRAYSCALE);
        cv::Mat src_host = cv::imread("Fruit_Bat.jpg", cv::IMREAD_GRAYSCALE);
//    VideoCapture cap(0); // open the default camera
    if(!cap.isOpened())  // check if we succeeded


        cv::cuda::GpuMat dst, src;
        src.upload(src_host);
        cv::cuda::threshold(src, dst, 128.0, 255.0, cv::THRESH_BINARY);
        cv::Mat result_host(dst);
        cv::imshow("Result", result_host);
        cv::waitKey();
    }
    catch(const cv::Exception& ex)
    {
        std::cout << "Error: " << ex.what() << std::endl;
    }
    return 0;
}