
Python + OpenCVのfillConvexPolyで複雑なポリゴンを描画する
2018-11-273 min read
目次
概要
Python + OpenCVのfillConvexPolyで複雑なポリゴンを描画するサンプルを紹介します。
サンプル
以下がサンプルになります。
import cv2
import numpy as np
if __name__ == "__main__" :
im = cv2.imread('img/lenna.png')
# 任意の描画したいポリゴンの頂点を与える
contours = np.array(
[
[200, 0],
[260, 160],
[400, 160],
[300, 240],
[400, 400],
[200, 320],
]
)
cv2.fillConvexPoly(im, points =contours, color=(255, 25, 255))
cv2.imshow('result', im)
cv2.waitKey(0)
cv2.destroyAllWindows()
このように複雑な形状に対してポリゴンを描画することができます。
↓

fillPolyと何が違うのか
fillConvexPolyの方がfillPolyよりも高速で動くそうです。
関数 fillConvexPoly は,塗りつぶされた凸ポリゴンを描きます.この関数は,関数 fillPoly よりも高速に動作します.また,凸ポリゴンだけでなく,その輪郭が水平なスキャンラインと2回以下しか交差しない(しかし,上下の境界線は水平でも良い)ようようなモノトーンポリゴンはすべて塗りつぶすことができます.http://opencv.jp/opencv-2svn/cpp/drawing_functions.html より引用
参考
Recommends
New Posts
Hot posts!
Date
Tags
Author