This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

AM5718: OpenCV-OCL usage

Other Parts Discussed in Thread: AM5718

I am using the TI's AM5718 Soc for developing the cv project, while i am using the opencv3.1.0,the opencl support for opencv is not completely. I could find out the opencl's device by opencv-ocl code, while i use the device to processing the image,it tell me the device isn't setting up!Here the opencv-ocl code and the result of it! I want to know, how can i eable the DSP accelerate to be my opencl deivice and use it.

#include <iostream>
#include "opencv2/opencv.hpp"
#include "opencv2/core/ocl.hpp"
#include "opencv2/imgcodecs.hpp"
#include "opencv2/videoio/videoio.hpp"
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/imgproc/imgproc.hpp"

using namespace std;
using namespace cv;
using namespace cv::ocl;

#define DSP 1

int main()
{
    double t = 0.0;
    std::vector<cv::ocl::PlatformInfo> plats;
    cv::ocl::getPlatfomsInfo(plats);
    const cv::ocl::PlatformInfo *platform = &plats[0];
    cout << "Platform Name:" << platform->name().c_str() << endl;

    cv::ocl::Device c_dev;
    platform->getDevice(c_dev,0);
    cout << "Device name:" << c_dev.name().c_str() << endl;
    c_dev.set(0);
    cv::ocl::setUseOpenCL(true);

#if DSP
    cv::UMat Ori = cv::imread("/home/root/test.jpg").getUMat(cv::ACCESS_RW),Res;
    cout << "Use the OpenCL Deivice?" << cv::ocl::useOpenCL() << endl;

    t = (double)cv::getTickCount();
    cv::cvtColor(Ori,Res,cv::COLOR_RGB2GRAY);
    t = ((double)cv::getTickCount() - t) / cv::getTickFrequency();
    std::cout << "TI AM57x Accelerate Time Cost:" << t << "s" << std::endl;
    cv::imshow("Test",Ori);
    cv::imshow("Gray",Res);
#else
    Mat I = imread("/home/root/test.jpg"),gray;
    t = (double)cv::getTickCount();
    cv::cvtColor(I,gray,cv::COLOR_RGB2GRAY);
    t = ((double)cv::getTickCount() - t) / cv::getTickFrequency();
    std::cout << "CPU Time Cost:" << t << "s" << std::endl;
    cv::imshow("Ori",I);
    cv::imshow("Res",gray);
#endif

    for (;;)
    {
        int key = waitKey();
        if (key == 27/*ESC*/ || key == 'q' || key == 'Q')
            break;
    }
    return 0;
}

The result:

The Use the OpenCL Device?Show that the DSP Accelerate is not being using as a opencl device.

I want to know whether the opencv-ocl library can support the dsp to be a opencl-device?

Look forward to your reply,thanks!

  • Hello.

    Please confirm that you have your environment set up as instructed on http://software-dl.ti.com/processor-sdk-linux/esd/docs/latest/linux/Foundational_Components_OpenCV.html 

    Section 3.12.3 describes the DSP offload through OpenCL as well as OPENCV_OPENCL_DEVICE and other environment variables needed to be set.

    Best regards,

    Dave

  • Thanks a lot! I have fixed the problem by executing the binary file in the sh script link this:

    export TI_OCL_LOAD_KERNELS_ONCHIP=Y
    export TI_OCL_CACHE_KERNELS=Y
    export OPENCV_OPENCL_DEVICE='TI AM57:ACCELERATOR:TI Multicore C66 DSP'
    echo "OpenCL on, canny"
    ./ocl_demo
    export OPENCV_OPENCL_DEVICE='disabled'
    echo "OpenCL off, canny"
    ./ocl_demo

    It works; By the way, i try some opencv ocl api to accelerate my application, it greatly spped up the opencv's alg!

    But the some errors occur while i am using the cv::erode function:

    It shows that the bin file running failed while dynamic compiling the kernel code for cv::erode() function, the error information tell me to add the imglib.ae66,so i did this, It now can compile successful, but when i run this binaray file, it;s show that the opencl device is slower than cpu directly, shown below:

    Is there some tips i don‘t setting up? Or something wrong with my code?

    Here is slice of my code:

        cv::ocl::setUseOpenCL(true);
        cout << "Use the OpenCL Deivice?" << cv::ocl::useOpenCL() << endl;
    
        cv::UMat Ori = cv::imread("/home/root/test.jpg").getUMat(cv::ACCESS_RW),Res,Canny,MSeg,uelement;
        cv::Mat element = cv::getStructuringElement(cv::MORPH_ELLIPSE,cv::Size(3,3));
        element.copyTo(uelement);
    
        t = (double)cv::getTickCount();
        cv::cvtColor(Ori,Res,cv::COLOR_RGB2GRAY);
        // cv::GaussianBlur(Res, Res, Size(5, 5), 1.25);
        cv::threshold(Res,MSeg,120,255,cv::THRESH_BINARY);
        cv::erode(MSeg,MSeg,uelement);
        // cv::Canny(Res,Res,0,30);
        t = ((double)cv::getTickCount() - t) / cv::getTickFrequency();
        std::cout << "TI AM57x Accelerate Time Cost:" << t << "s" << std::endl;
        cv::imshow("Test",Ori);
        cv::imshow("Gray",MSeg);

    Thanks again!

  • Hello,thanks for your response,now i can use the T-API to accelerate my opencv algorithm.

    I want to know if all the opencv's algorithm is been optimized with openCL?If not,where can i get the list of the opencl-support algorithm.

    it's obviously the opencv's function erode seems that could not be accelerate by opencl,and the processing result is not equal to the result of CPU's result.

    Looking forward to your reply! Thanks again!

  • Hello.

    Please refer to http://software-dl.ti.com/processor-sdk-linux/esd/docs/latest/linux/Foundational_Components_OpenCV.html for information on the supported functions, specifically:

    3.12.2. OpenCV Modules Supported By TI

    and

    3.12.5.7. List of currently (PLSDK 3.1) DSP optimized OpenCV OpenCL kernels, using non-standard OpenCL extensions

    As this thread has been marked answered, I would like to close it as follow up questions will potentially be missed. For additional follow up, please do create an e2e thread. You can provide a link back to this one if related.

    Best regards,

    Dave