フレーム内で見つかったすべての輪郭を塗りつぶされた円に変換する機会はありますか?
説明させてください、私のビデオには小さなオブジェクトがたくさんあり、オブジェクトがその形を変えるため、Mosse トラッキングを使用して検出するのは困難です。そこで、見つかったすべての輪郭を塗りつぶされた円に変更するという考えがありました。つまり、この画像で見つかったすべてのオブジェクトを変換します。
このようなものに:
私はpythonとOpencvを使用しています。
フレーム内で見つかったすべての輪郭を塗りつぶされた円に変換する機会はありますか?
説明させてください、私のビデオには小さなオブジェクトがたくさんあり、オブジェクトがその形を変えるため、Mosse トラッキングを使用して検出するのは困難です。そこで、見つかったすべての輪郭を塗りつぶされた円に変更するという考えがありました。つまり、この画像で見つかったすべてのオブジェクトを変換します。
このようなものに:
私はpythonとOpencvを使用しています。
塗りつぶされた円の輪郭を変換するには、次のような簡単な方法があります。
上記の手順をコーディングする方法の例 (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;
}
元の画像
円での結果