Recreate Wuhan University’s Cherry Blossom Bloom with Python and OpenCV
This tutorial shows how to use Python, OpenCV, and Pillow to capture, process, and animate Wuhan University’s cherry blossom scenes, turning pixel data into a time‑lapse video with custom text overlays and frame‑by‑frame control.
Wuhan University launched a "Cherry Blossom Cloud Live" stream from March 16 to 25, inviting viewers to watch the blossoms online. A student, Zhu Yongchun, wrote a Python script that simulates the blooming process, and the code was later open‑sourced.
The script explains that each image consists of pixels, each represented by an RGB array (a, b, c) where values range from 0 to 255. More pixels yield higher resolution, while too few cause visible jagged edges.
Using OpenCV, frames are saved as JPEG files:
cv2.imwrite("pic/frame%d.jpg" % count, image) # save frame as JPEG fileA blank canvas is created with Pillow, a font is selected, and a nested loop writes colored text onto the canvas based on pixel values:
blank = Image.new("RGB", [len(img[0]), len(img)], "white")
drawObj = ImageDraw.Draw(blank)
font = ImageFont.truetype("C:/Windows/Fonts/msyhbd.ttc", size=n-1)
for i in range(0, len(img), n):
for j in range(0, len(img[i]), n):
text = "武汉加油"
drawObj.ink = img[i][j][0] + img[i][j][1]*256 + img[i][j][2]*256*256
drawObj.text([j, i], text[int(j/n) % len(text)], font=font)
print("完成处理——", i, j)
blank.save("new/" + pic + ".jpeg")Finally, the generated images are compiled into a video using OpenCV’s VideoWriter:
def picvideo(path, size):
fps = 24
file_path = "video/new.mp4"
fourcc = cv2.VideoWriter_fourcc('D','I','V','X')
video = cv2.VideoWriter(file_path, fourcc, fps, size)
for item in os.listdir(path):
if item.endswith('.jpg'):
img = cv2.imread(os.path.join(path, item))
video.write(img)
video.release()Running the script produces a time‑lapse video that visualizes the full cherry blossom opening process, which can be shared or streamed online.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
MaGe Linux Operations
Founded in 2009, MaGe Education is a top Chinese high‑end IT training brand. Its graduates earn 12K+ RMB salaries, and the school has trained tens of thousands of students. It offers high‑pay courses in Linux cloud operations, Python full‑stack, automation, data analysis, AI, and Go high‑concurrency architecture. Thanks to quality courses and a solid reputation, it has talent partnerships with numerous internet firms.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
