1

I am trying to convert buffer image to opencv mat by mat.at(i,j),but it runs 20 ms .It's too slow.How to improve the speed ?or another method to convert buffer image to cv::Mat?

    Halide::Func gray;

    Halide::Var x, y;

    gray(x, y) = Halide::cast<uint8_t>( 0.299f * image(x, y, 0) +0.587f * image(x, y, 1) + 0.114f * image(x, y, 2));

    Halide::Var xi,yi;
    gray.tile(x,y,xi,yi,4,4).vectorize(xi,4).parallel(y);

    Halide::Buffer<uint8_t> output = gray.realize(image.width(), image.height());

    Mat h2m = Mat::zeros(image.height(),image.width(), CV_8UC1);

    for( int i=0;i<image.height();i++){
            for(int j=0;j<image.width();j++){
                    h2m.at<uchar>(i,j)=output(j,i); 
            }
    }
    imshow("gray",h2m);

1 Answer 1

3

Just wrap pointer to cv::Mat data:

Halide::Buffer<uint8_t> buf(img.data, width, height);

And realize your function inside it:

gray.realize(buf);
1
  • 1
    Thanks you very much!
    – tso2386710
    Aug 11, 2017 at 10:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.