Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error with 'out1.to_pixels(score.data, ncnn::Mat::PIXEL_GRAY)' #18

Open
7Ston1 opened this issue Feb 21, 2024 · 2 comments
Open

Error with 'out1.to_pixels(score.data, ncnn::Mat::PIXEL_GRAY)' #18

7Ston1 opened this issue Feb 21, 2024 · 2 comments

Comments

@7Ston1
Copy link

7Ston1 commented Feb 21, 2024

Hello, Linyi. Thank you very much for this outstanding work. However, I recently discovered a issue during testing. The code 'out1.to_pixels(score.data, ncnn::Mat::PIXEL_GRAY);' doesn't seem to work while the format 'ncnn::Mat::PIXEL_BGR' can work well. I noticed that you tried to use 'memcpy()' to solve the problem. Do you know why cause this?

@ffff349
Copy link

ffff349 commented Jun 28, 2024

我也发现的这个问题,导致我的特征点出不来

@deepConnectionism
Copy link

@7Ston1 这个问题是因为 输入的是 bgr 三通道图像,你需要修改:

void FeatureTracker::let_net(const cv::Mat& image_bgr) {
    last_desc = desc.clone();

    // 将 BGR 图像转换为灰度图像
    cv::Mat img_gray;
    cv::cvtColor(image_bgr, img_gray, cv::COLOR_BGR2GRAY);

    // 调整灰度图像大小
    cv::Mat img_resized;
    cv::resize(img_gray, img_resized, cv::Size(LET_WIDTH, LET_HEIGHT));

    // 创建 NCNN 提取器
    ncnn::Extractor ex = net.create_extractor();
    ex.set_light_mode(true);

     // 将灰度图像转换为 NCNN Mat 格式
    in = ncnn::Mat::from_pixels(img_resized.data, ncnn::Mat::PIXEL_GRAY, img_resized.cols, img_resized.rows);
    in.substract_mean_normalize(mean_vals_gray, norm_vals_gray);

    // 提取特征
    ex.input("input", in);
    ex.extract("score", out1);
    ex.extract("descriptor", out2);

    // 逆归一化处理
    out1.substract_mean_normalize(mean_vals_inv_gray, norm_vals_inv_gray);
    out2.substract_mean_normalize(mean_vals_inv_gray, norm_vals_inv_gray);

    // 将 NCNN Mat 转换为 OpenCV Mat
    memcpy((uchar*)score.data, out1.data, LET_HEIGHT*LET_WIDTH*sizeof(float));
    cv::Mat desc_tmp(LET_HEIGHT, LET_WIDTH, CV_8UC3);
    out2.to_pixels(desc_tmp.data, ncnn::Mat::PIXEL_BGR);
    desc = desc_tmp.clone();
    
    // // 保存描述子图像
    // cv::imwrite("desc.png", desc);
}

此外,你需要使用 灰度模型

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants