Created
August 13, 2017 11:51
-
-
Save PeaceAndHiLight/ed8038d8159b155da8cf5bccdcb4c6da to your computer and use it in GitHub Desktop.
CreateImage Python
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# encoding:utf-8 | |
import cv2 | |
import numpy as np | |
width = 16 | |
height = 24 | |
# uint8で0埋めの配列を作る。 | |
# 幅16、高さ24のサイズ | |
# zeros(shape, type) shapeは配列の大きさ | |
# 配列の(行数、列数)になっている | |
# 画像はwidth,heightの慣習があるが、ココは逆なので気をつけること | |
imageArray = np.zeros((height, width, 3), np.uint8) | |
# これでサイズを確認できます | |
''' | |
size = imageArray.shape[:2] | |
print(size) | |
''' | |
# 0で埋められた配列を画像として保存します | |
cv2.imwrite("blank.bmp", imageArray); | |
# ここに | |
for h in range(0, height): | |
for w in range(0, width): | |
imageArray[h, w] = [128, 64, 32] | |
# これでimageArrayの中身を表示できる | |
''' | |
print(imageArray) | |
''' | |
cv2.imwrite("R32_G64_B128_16x24.bmp", imageArray) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Python3とOpenCV3とnumpyで適当な画像を作る方法
BGRの配列を作り、任意の画素値を設定すればよい。