簡體   English   中英

OpenCV FAST 算法僅在圖像的一部分上創建傾斜的關鍵點

[英]OpenCV FAST Algorithm creating skewed keypoints on only part of an image

我正在嘗試使用 OpenCV 的FAST角點檢測算法來獲取球圖像的輪廓(不是我的最終項目,我將其用作簡單示例)。 出於某種原因,它僅適用於輸入 Mat 的三分之一,並在整個圖像上拉伸關鍵點。 我不確定這里會出現什么問題,使 FAST 算法不適用於整個 Mat。

代碼:

void featureDetection(const Mat& imgIn, std::vector<KeyPoint>& pointsOut)   { 
    int fast_threshold = 20;
    bool nonmaxSuppression = true;
    FAST(imgIn, pointsOut, fast_threshold, nonmaxSuppression);
}

int main(int argc, char** argv) {

    Mat out = imread("ball.jpg", IMREAD_COLOR);

    // Detect features 
    std::vector<KeyPoint> keypoints;
    featureDetection(out.clone(), keypoints);
    Mat out2 = out.clone();

    // Draw features (Normal, missing right side)
    for(KeyPoint p : keypoints) {
        drawMarker(out, Point(p.pt.x / 3, p.pt.y), Scalar(0, 255, 0));
    }

    imwrite("out.jpg", out, std::vector<int>(0));
    
    // Draw features (Stretched)
    for(KeyPoint p : keypoints) {
        drawMarker(out2, Point(p.pt.x, p.pt.y), Scalar(127, 0, 255));
    }

    imwrite("out2.jpg", out2, std::vector<int>(0));
}

輸入圖像

球.jpg

輸出 1( keypoint.x 乘以因子 1/3,但缺少右側

出.jpg

輸出 2(坐標不變

輸出2.jpg

我在 MinGW 上使用 OpenCV 4.5.4。

大多數關鍵點檢測器使用灰度圖像作為輸入。 如果您將 bgr 圖像的內存解釋為灰度,您將擁有 3 倍的像素數。 如果算法使用每行的寬度偏移,Y 軸仍然可以,大多數算法都這樣做(因為這在使用 subimaging 或 padding 時很有用)。

我不知道這是錯誤還是功能,FAST 不檢查通道數,如果給出了錯誤的通道數,也不會拋出異常。

您可以通過帶有標志 cv::COLOR_BGR2GRAY 的 cv::cvtColor 將圖像轉換為灰度

暫無
暫無

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

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