目的
- いくつかのデータ構造を学ぶ:Point、Scalar、Size、Circle、Rect、RotatedRect など。
Scalar は JavaScript における配列型である。Point、Size、Circle、Rect、RotatedRect は JavaScript におけるオブジェクト型である。
Point
Point を構築するには2通りの方法があり、いずれも同じである:
// The first way
let point = new cv.Point(x, y);
// The second way
let point = {x: x, y: y};
- 引数
-
| x | 点の x 座標。(原点は画像の左上隅) |
| y | 点の y 座標。 |
Scalar
Scalar を構築するには2通りの方法があり、いずれも同じである:
// The first way
let scalar = new cv.Scalar(R, G, B, Alpha);
// The second way
let scalar = [R, G, B, Alpha];
- 引数
-
| R | 赤チャンネルのピクセル値。 |
| G | 緑チャンネルのピクセル値。 |
| B | 青チャンネルのピクセル値。 |
| Alpha | アルファチャンネルのピクセル値。 |
Size
Size を構築するには2通りの方法があり、いずれも同じである:
// The first way
let size = new cv.Size(width, height);
// The second way
let size = {width : width, height : height};
- 引数
-
| width | サイズの幅。 |
| height | サイズの高さ。 |
Circle
Circle を構築するには2通りの方法があり、いずれも同じである:
// The first way
let circle = new cv.Circle(center, radius);
// The second way
let circle = {center : center, radius : radius};
- 引数
-
Rect
Rect を構築するには2通りの方法があり、いずれも同じである:
// The first way
let rect = new cv.Rect(x, y, width, height);
// The second way
let rect = {x : x, y : y, width : width, height : height};
- 引数
-
| x | 矩形の左上隅となる頂点の x 座標。 |
| y | 矩形の左上隅となる頂点の y 座標。 |
| width | 矩形の幅。 |
| height | 矩形の高さ。 |
RotatedRect
RotatedRect を構築するには2通りの方法があり、いずれも同じである:
// The first way
let rotatedRect = new cv.RotatedRect(center, size, angle);
// The second way
let rotatedRect = {center : center, size : size, angle : angle};
- 引数
-
| center | 矩形の重心。 |
| size | 矩形の幅と高さ。 |
| angle | 時計回りの回転角度。角度が 0、90、180、270 などのとき、矩形は正立した矩形となる。 |
rotatedRect から頂点を取得する方法を学ぶ:
関数 cv.RotatedRect.points(rotatedRect) を使用する
- 引数
-
let vertices = cv.RotatedRect.points(rotatedRect);
let point1 = vertices[0];
let point2 = vertices[1];
let point3 = vertices[2];
let point4 = vertices[3];
rotatedRect からバウンディング矩形を取得する方法を学ぶ:
関数 cv.RotatedRect.boundingRect(rotatedRect) を使用する
- 引数
-
let boundingRect = cv.RotatedRect.boundingRect(rotatedRect);