単一チャンネルの空白の画像に円、線、長方形を描くコードを書いています。その後、画像の輪郭を見つけて、すべての輪郭を正しく取得しています。しかし、輪郭を見つけた後、ソース画像が歪んでいます。なぜこれが起こっているのですか?誰でも私がそれを解決するのを助けることができます。そして、私のコードは以下のようになります。
using namespace cv;
using namespace std;
int main()
{
Mat dst = Mat::zeros(480, 480, CV_8UC1);
Mat draw= Mat::zeros(480, 480, CV_8UC1);
line(draw, Point(100,100), Point(150,150), Scalar(255,0,0),1,8,0);
rectangle(draw, Rect(200,300,10,15), Scalar(255,0,0),1, 8,0);
circle(draw, Point(80,80),20, Scalar(255,0,0),1,8,0);
vector<vector<Point> > contours;
vector<Vec4i> hierarchy;
findContours( draw, contours, hierarchy,CV_RETR_CCOMP, CV_CHAIN_APPROX_SIMPLE );
for( int i = 0; i< contours.size(); i++ )
{
Scalar color( 255,255,255);
drawContours( dst, contours, i, color, 1, 8, hierarchy );
}
imshow( "Components", dst );
imshow( "draw", draw );
waitKey(0);
}
ソース画像
輪郭を見つけた後の歪んだソース