Skip to content

Instantly share code, notes, and snippets.

@PeaceAndHiLight
Created August 13, 2017 11:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save PeaceAndHiLight/ed8038d8159b155da8cf5bccdcb4c6da to your computer and use it in GitHub Desktop.
Save PeaceAndHiLight/ed8038d8159b155da8cf5bccdcb4c6da to your computer and use it in GitHub Desktop.
CreateImage Python
# 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)
@PeaceAndHiLight
Copy link
Author

PeaceAndHiLight commented Aug 13, 2017

Python3とOpenCV3とnumpyで適当な画像を作る方法
BGRの配列を作り、任意の画素値を設定すればよい。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment