Search code examples
opencvmachine-learningarmcomputer-visionneon

convert arm_compute::Image to cv::Mat


I have a lot of code that is based on open cv but there are many ways in which the Arm Compute library improves performance, so id like to integrate some arm compute library code into my project. Has anyone tried converting between the two corresponding Image structures? If so, what did you do? Or is there a way to share a pointer to the underlying data buffer without needing to copy image data and just set strides and flags appropriately?


Solution

  • I was able to configure an arm_compute::Image corresponding to my cv::Mat properties, allocate the memory, and point it to the data portion of my cv:Mat.

    This way, I can process my image efficiently using arm_compute and maintain the opencv infrastructure I had for the rest of my project.

    // cv::Mat mat defined and initialized above
    arm_compute::Image image;
    
    image.allocator()->init(arm_compute::TensorInfo(mat.cols, mat.rows, Format::U8));
    image.allocator()->allocate();
    image.allocator()->import_memory(Memory(mat.data));