頂点列で表すPolygonを構成する長いエッジに対しエッジ分割し、頂点を追加する。

頂点列で表すPolygon図形を構成するエッジのうち、任意の長さ以上のエッジに対して分割し頂点を増やす処理。

Process of dividing vertices of arbitrary length and increasing vertex among edges constituting Polygon figure represented by vertex sequence.

(results sample picture)
@red points : Polygon points
@blue pattern : Filled polygon
before
before split edge
after
after split edge

(results split edge)
original_points
[[237.894 0. ]
[130.554 105.408]
[ 43.748 0.626]
[ 0. 42.589]
[129.559 189. ]
[280. 42.589]
[237.894 0. ]]

after split points
[[237.894 0. ]
[184.224 52.704 ]
[130.554 105.408 ]
[ 87.151 53.017 ]
[ 43.748 0.626 ]
[ 0. 42.589 ]
[ 64.7795 115.7945 ]
[129.559 189. ]
[179.706 140.19633333]
[229.853 91.39266667]
[280. 42.589 ]
[237.894 0. ]]

sample code

■polygon_points.txt
237.894 0.000
130.554 105.408
43.748 0.626
0.000 42.589
129.559 189.000
280.000 42.589
237.894 0.000

Add x-y vertex coordinates to empty numpy.ndarray

頂点座標を空のnumpy.ndarrayに追加する操作。
よくやるのでメモ。

—(sample code)—–

—(exec result)—–
[[-126 133]
[-126 131]
[-117 131]
[-117 134]]

—(memo)—-
initialize ndarray for x-y point list.
at first array is empty(no entry) and add_type is [x,y].
so initialize parameter is (0,2).

if append for ndarray, append element must ndarray.
we use only 1 axis, so axis = 0(axis memo)

Voronoi diagram(ボロノイ図)

voronoi diagram sample

opencvのHOGDescriptorとSVM(getDaimlerPeopleDetector)で人検出

getDaimlerPeopleDetectorを使っての人検出。getDefaultPeopleDetectorを使った人検出は
こちら。

■入力画像
HOGDescriptor_getDaimlerPeopleDetector input

■サンプルコード

■実行結果
HOGDescriptor_getDaimlerPeopleDetector output

誤検出はあるが、getDefaultPeopleDetectorでの検出に比べると漏れは少なくなる印象。

opencvのHOGDescriptorとSVMで人検出

HOGDescriptorは被探索画像を64 * 128 などの単位でスキャンし、8 * 8などのピクセルを移動させてHOG特徴量の抽出を行う。HOG特徴量は領域内の勾配方向ごとの勾配強度を計算してそれをヒストグラムにしたものらしい。画像中の輝度変化を抽出していることになる。

SVMは入力が正解か不正解を分類する分類器。大量のデータとラベルの組から正解ラベルのデータ、不正解ラベルのデータを学習し正解と不正解の境界線を引く。

opencvにはすでに学習済みの人識別器が同梱されており、これを使って人の検出を行ってみる。

■入力画像
HOGDescriptor_getDefaultPeopleDetector input

■サンプルコード

■実行結果
HOGDescriptor_getDefaultPeopleDetector input

検出漏れはあるが、とりあえず機能はしている様子。opencvの人認識器には今回試したgetDefaultPeopleDetector以外にgetDaimlerPeopleDetectorという認識器が同梱されている。これについては次回以降で実験してみる。

HOG Descriptor scans the search image by units such as 64 x 128, moves pixels such as 8 x 8, and extracts the HOG feature amount. It seems that the HOG feature quantity is calculated by calculating the gradient strength for each gradient direction in the region and making it a histogram. The luminance change in the image is extracted.

SVM is a classifier that classifies incorrect answers or incorrect answers. Learn the data of the correct label and the data of the incorrect label from the large amount of data and the set of labels and draw the boundary line between the correct answer and incorrect answer.
Opencv is already shipped with a learned person identifier, and try to detect people using it.

Results:Detection is insufficient, but it seems that it is functioning for the time being. In this time, we tried getDefaultPeopleDetector on human recognition device of opencv and recognition device called getDaimlerPeopleDetector is bundled. I will experiment about this next time.

opencvを使いHarrisコーナー検出で画像からコーナー部を抽出する

コーナー部の特徴量抽出をする方法としてMoravecの方法や、Harrisの方法というものがある。検出のためのアルゴリズムは難解で自分には理解できず。とりあえず実行テストした結果とコードを乗せる。しっかりとコーナー部分を抽出できていることがわかる。

■入力画像
corner detect sample input

■サンプルコード

■実行結果
detect corner by harris

opencvを使いcanny法で画像をエッジ変換する

■サンプルコード

■実行結果
canny test

opencvを使いハフ変換で画像から円を探す(HoughCircles)

HoughCircles(image, circles, method, dp, minDist, param1, param2, minRadius, maxRadius)

ハフ変換を用いて画像内から円を検出する

項目 内容
image 8ビット,シングルチャンネル,グレースケールの入力画像
circles 検出された円を出力するベクトル
method 現在のところCV_HOUGH_GRADIENT メソッドのみが実装
dp 画像分解能に対する投票分解能の比率の逆数
minDist 検出される円の中心同士の最小距離.このパラメータが小さすぎると,正しい円の周辺に別の円が複数誤って検出される
param1 手法依存の 1 番目のパラメータ. CV_HOUGH_GRADIENT の場合は, Canny() エッジ検出器に渡される2つの閾値の内,大きい方の閾値を表す
param2 手法依存の 2 番目のパラメータ. CV_HOUGH_GRADIENT の場合は,円の中心を検出する際の投票数の閾値を表す.これが小さくなるほど,より多くの誤検出が起こる可能性がある
minRadius 円の半径の最小値
maxRadius 円の半径の最大値

■入力画像
houghcircles test

■処理コード

■結果
houghcircles test

opencvを使い確率的ハフ変換で画像から直線を探す

ハフ変換は与えられたパラメータから全条件を計算し直線を求めるのに対し、確率的ハフ変換はある程度の当たりをつけて計算し、負荷を軽くする。

HoughLinesP(image, lines, double rho, double theta, int threshold, double minLineLength=0, double maxLineGap=0)

■入力画像
houghline test

■処理コード

■結果
houghline test

opencvを使いハフ変換で画像から直線を探す

ハフ変換は画像の中にある直線形状や円形状を検出する際に用いられる手法の一つ。opencvではHoughLinesという関数が用意されており、これを使うことで検出が容易となる(計算付加は指定するパラメータの精度により異なる)。

HoughLines(image, lines, rho, theta, threshold, srn, stn)
項目 内容
image 8ビット,シングルチャンネルの2値入力画像.この画像は関数により書き換えられる可能性がある
lines 検出された直線が出力されるベクトル.各直線は,2要素のベクトル (rho, theta) で表現される. rho は原点(画像の左上コーナー)からの距離, theta はラジアン単位で表される直線の回転角度
rho ピクセル単位で表される投票空間の距離分解能
theta ラジアン単位で表される投票空間の角度分解能
threshold 投票の閾値パラメータ.十分な票を得た直線のみが出力される
srn マルチスケールハフ変換において,距離分解能 rho の除数となる値.投票空間の粗い距離分解能は rho となり,細かい分解能は rho/srn となる.もし srn=0 かつ stn=0 の場合は,古典的ハフ変換が利用される.そうでない場合は,両方のパラメータが正値である必要がある
stn マルチスケールハフ変換において,角度分解能 theta の除数となる値

■入力画像
houghline test

■処理コード

■結果
houghline test