簡體   English   中英

Arm計算庫-Canny Edge從導入的opencv圖像返回不可用的數據

[英]Arm Compute Library - Canny Edge returns unusable data from imported opencv image

我正在使用arm計算庫鏈接將opencv應用程序轉換為更有效的代碼庫。

我想從一個OpenCV的墊子,我已經做成功完成數據導入

arm_compute::Image matACL;
matACL.allocator()->init(arm_compute::TensorInfo(mat.cols, mat.rows, arm_compute::Format::U8)); // Initialise tensor's dimensions
matACL.allocator()->import_memory(arm_compute::Memory(mat.data)); //Allocate the image without any padding.

//matACL.allocator()->import_memory(arm_compute::Memory(new cvMatData(mat.data)));

當心ACL 18.05及更高版本需要一個已實現的內存接口,我為此創建了要點 這是上面的注釋行。

我可以對圖像執行不同的操作(例如,閾值或高斯),並且可以在opencv窗口中看到正確的輸出,但是每當使用Canny邊緣檢測器時,我都會得到混亂的輸出圖像。 我已經在github上發布了一段時間,但是他們也找不到解決方案。

我已經像在NECannyEdge.cpp文件中一樣實現了canny edge霓虹燈,以更好地了解正在發生的事情。 我將結果數據復制到opencv Mat中,並像這樣保留指向它的指針。

這就是我將結果轉換回OpenCV Mat的方式:

ptr = (unsigned char*)malloc(mat.cols*mat.rows*sizeof(unsigned char));

for(unsigned int z = 0 ; z < 0 ; ++z)
{
    for (unsigned int y = 0; y < mat.rows; ++y)
    {
        memcpy(ptr + z * (mat.cols * mat.rows) + y * mat.cols, matACL.buffer() +
        matACL.info()->offset_element_in_bytes(Coordinates(0, y, z)), mat.cols * 
        sizeof(unsigned char));
    }
}

和一個替代方案:

Window output_window;
output_window.use_tensor_dimensions(shape, Window::DimY);
Iterator output_it(&matACL, output_window);
execute_window_loop(output_window,
[&](const Coordinates & id)
{
    memcpy(ptr + id.z() * (mat.cols * mat.rows) + id.y() * mat.cols, output_it.ptr(), mat.cols * sizeof(unsigned char));
}, output_it);

該圖像有時會顯示正確的Canny邊緣結果,但大多數情況下會顯示隨機的,可能未完成的數據。

輸出圖像

我檢查了是否可能是競態條件,但實現應該是單線程的,我無法弄清楚問題出在哪里。 有人有主意嗎?

如何成功使用opencv圖像中的數據在arm計算庫的canny邊緣檢測器中使用? 也許我在導入過程中錯過了一些步驟?

謝謝,問候

我發現哪里出了問題,並開發了此功能,該功能從ACL映像創建了OpenCV Mat:

void ACLImageToMat(arm_compute::Image &aCLImage, cv::Mat &cVImage, std::unique_ptr<uint8_t[]> &cVImageDataPtr)
{
    size_t width  = aCLImage.info()->valid_region().shape.x();
    size_t height = aCLImage.info()->valid_region().shape.y();

    cVImageDataPtr = std::make_unique < uint8_t[]>(width*height);
    auto ptr_src = aCLImage.buffer();


    arm_compute::Window input_window;
    input_window.use_tensor_dimensions(aCLImage.info()->tensor_shape());
    arm_compute::Iterator input_it(&aCLImage, input_window);
    int counter = 0;
    arm_compute::execute_window_loop(input_window,
        [&](const arm_compute::Coordinates & id)
        {
            *reinterpret_cast<uint8_t *>(cVImageDataPtr.get() + counter++) = ptr_src[aCLImage.info()->offset_element_in_bytes(id)];
        },
        input_it);


    cVImage = cv::Mat(cVImage.rows, cVImage.cols, CV_8UC1, cVImageDataPtr.get());
}

為了初始化Canny,我做了以下工作:

    arm_compute::Image matACL;
    matACL.allocator()->init(arm_compute::TensorInfo(eye.cols, eye.rows, arm_compute::Format::U8));
    matACL.allocator()->import_memory(arm_compute::Memory(eye.data));

    arm_compute::Image matACLCanny;
    matACLCanny.allocator()->init(arm_compute::TensorInfo(eye.cols, eye.rows, arm_compute::Format::U8));

    arm_compute::NECannyEdge canny {};
    canny.configure(&matACL, &matACLCanny, 300, 150, 3, 1, arm_compute::BorderMode::REPLICATE);

    matACLCanny.allocator()->allocate();

    canny.run();

重要的事情是在配置好邊緣檢測器之后調用輸出圖像的allocate功能。 不久前,我在ACL文檔中的某個地方找到了它,但是我不記得確切的位置了。

希望這對偶然在ACL和OpenCV之間轉換圖像的人有所幫助!

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM