Make one Mario using Numpy and OpenCV

Work from the side! Data frame that gets angry

But it has a purpose. OpenCV uses Numpy's ndarray array to handle the data.

That means you can't reproduce it by throwing a one-dimensional array for gray and a three-dimensional array for color! I did a metamorphosis challenge that completely ignored the manners and rules, and broke each time. This time, the work has been completed successfully I will upload a code that is of no use to the world.

I drew an uncle plumber in a 12x12 array.

mario.py



import cv2
import numpy as np

val = 0
#Create an empty list(12*12 for all elements 0)
rchannel = [[val] * 12 for i in range(12)]
rchannel = np.array(rchannel)
gchannel = [[val] * 12 for i in range(12)]
gchannel = np.array(gchannel)
bchannel = [[val] * 12 for i in range(12)]
bchannel = np.array(bchannel)

#Hell's hand-made zone
rchannel[3,3:8] = 255
rchannel[4,2:11] = 255
rchannel[5,2:5] = 146
gchannel[5,2:5] = 41
bchannel[5,2:5] = 6
rchannel[5,5:7] = 248
gchannel[5,5:7] = 178
bchannel[5,5:7] = 108
rchannel[5,7] = 146
gchannel[5,7] = 41
bchannel[5,7] = 6
rchannel[5,8] = 248
gchannel[5,8] = 178
bchannel[5,8] = 108
rchannel[6,1] = 146
gchannel[6,1] = 41
bchannel[6,1] = 6
rchannel[6,2] = 248
gchannel[6,2] = 178
bchannel[6,2] = 108
rchannel[6,3] = 146
gchannel[6,3] = 41
bchannel[6,3] = 6
rchannel[6,4:7] = 248
gchannel[6,4:7] = 178
bchannel[6,4:7] = 108
rchannel[6,7] = 146
gchannel[6,7] = 41
bchannel[6,7] = 6
rchannel[6,8:11] = 248
gchannel[6,8:11] = 178
bchannel[6,8:11] = 108
rchannel[7,1] = 146
gchannel[7,1] = 41
bchannel[7,1] = 6
rchannel[7,2] = 248
gchannel[7,2] = 178
bchannel[7,2] = 108
rchannel[7,3:5] = 146
gchannel[7,3:5] = 41
bchannel[7,3:5] = 6
rchannel[7,5:8] = 248
gchannel[7,5:8] = 178
bchannel[7,5:8] = 108
rchannel[7,8] = 146
gchannel[7,8] = 41
bchannel[7,8] = 6
rchannel[7,9:11] = 248
gchannel[7,9:11] = 178
bchannel[7,9:11] = 108
rchannel[7,11] = 146
gchannel[7,11] = 41
bchannel[7,11] = 6
rchannel[8,1:3] = 146
gchannel[8,1:3] = 41
bchannel[8,1:3] = 6
rchannel[8,3:7] = 248
gchannel[8,3:7] = 178
bchannel[8,3:7] = 108
rchannel[8,7:11] = 146
gchannel[8,7:11] = 41
bchannel[8,7:11] = 6
rchannel[9,3:10] = 248
gchannel[9,3:10] = 178
bchannel[9,3:10] = 108
rchannel[10,2:4] = 255
bchannel[10,4] = 255
rchannel[10,5:9] = 255
rchannel[11,1:4] = 255
bchannel[11,4] = 255
rchannel[11,5:11] = 255

#Combine channels
data_map = np.stack((bchannel,gchannel,rchannel),-1)
#Change data type → Now it can be handled by OpenCV
data_map = np.array(data_map, dtype="uint8")
#Enlarged for easy visualization
data_map = cv2.resize(data_map, (400, 400),interpolation=cv2.INTER_NEAREST)

#display
cv2.imshow("show",data_map)
cv2.waitKey(0)
cv2.destroyAllWindows()

キャプチャ.JPG

May 2020 be a good year.

Recommended Posts

Make one Mario using Numpy and OpenCV
Make a Sato Yohei discriminator using OpenCV and TensorFlow
Head orientation estimation using Python and OpenCV + dlib
Connect multiple videos in one shot using OpenCV!
I tried object detection using Python and OpenCV
list and numpy
Create dummy data using Python's NumPy and Faker packages
Make Python segfault on one line without using ctypes
Python and numpy tips
RaspberryPi Zero and OpenCV
Try to make it using GUI and PyQt in Python
Shoot time-lapse from a PC camera using Python and OpenCV
[Python] Accessing and cropping image pixels using OpenCV (for beginners)