Help us understand the problem. What is going on with this article?

Python + OpenCVによるマスク画像の動的生成方法

マスク画像の生成を動的に生成する方法

下記では、100×100ピクセル画像に対し四角形のマスク範囲を描画している

test.py
import cv2

# マスク用単一色画像を作成
height = 100 # 生成画像の高さ
width = 100 # 生成画像の幅
imgMask = np.full((height, width, 1), 1, dtype=np.uint8)

# マスク範囲を四角形で描画
boxFromX = 20 #マスク範囲開始位置 X座標
boxFromY = 40 #マスク範囲開始位置 Y座標
boxToX = 80 #マスク範囲終了位置 X座標
boxToY = 60 #マスク範囲終了位置 Y座標
cv2.rectangle(imgMask, (boxFromX, boxFromY), (boxToX, boxToY),(255), cv2.FILLED)

# マスク結果画像を保存
cv2.imwrite("testMaskImg.png", imgMask)

上記で生成されたマスク画像
testMaskImg.png

Why do not you register as a user and use Qiita more conveniently?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away