0

フレーム内で見つかったすべての輪郭を塗りつぶされた円に変換する機会はありますか?

説明させてください、私のビデオには小さなオブジェクトがたくさんあり、オブジェクトがその形を変えるため、Mosse トラッキングを使用して検出するのは困難です。そこで、見つかったすべての輪郭を塗りつぶされた円に変更するという考えがありました。つまり、この画像で見つかったすべてのオブジェクトを変換します。

ここに画像の説明を入力

このようなものに:

ここに画像の説明を入力

私はpythonとOpencvを使用しています。

4

1 に答える 1

0

塗りつぶされた円の輪郭を変換するには、次のような簡単な方法があります。

  1. 各輪郭を取得する
  2. 境界ボックスの輪郭を見つける
  3. 境界ボックスの中心を見つけ、円の中心になります
  4. 境界ボックスの対角線を見つけ、円の半径になります
  5. 指定された中心と半径で円を描きます。

上記の手順をコーディングする方法の例 (C++ ですが、Python に簡単に移植できます) の下に:

#include "opencv2/opencv.hpp"
using namespace cv;

int main(int, char**)
{
    Mat1b img = imread("path_to_image", IMREAD_GRAYSCALE);

    // This will enlarge the circles by a "factor"
    float factor = 2;

    // Find blobs and extract contours
    vector<vector<Point>> contours;
    findContours(img.clone(), contours, CV_RETR_LIST, CV_CHAIN_APPROX_NONE);

    Mat1b res(img.size(), uchar(0));

    for (int i = 0; i < contours.size(); ++i)
    {
        // Get the bounding box of the contours
        Rect bb = boundingRect(contours[i]);

        // Get the center of the bounding box
        // Will be the center of the circle
        Point center(bb.x + bb.width/2, bb.y + bb.height/2);

        // Get the length of the diagonal of the bounding box.
        // Will be the radius of the circle (eventually multiplied by a factor)
        int radius = sqrt(bb.width*bb.width + bb.height*bb.height) / 2;

        // Draw the circle
        circle(res, center, radius*factor, Scalar(255), CV_FILLED);
    }

    return 0;
}

元の画像

ここに画像の説明を入力

円での結果

ここに画像の説明を入力

于 2015-07-29T10:08:37.107 に答える