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.

MaGe Linux Operations
MaGe Linux Operations
MaGe Linux Operations
Recreate Wuhan University’s Cherry Blossom Bloom with Python and OpenCV
Cherry blossoms at Wuhan University
Cherry blossoms at Wuhan University

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.

Wuhan University cherry blossom scene
Wuhan University cherry blossom scene

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 file

A 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.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

Computer VisionPythonImage ProcessingVideo GenerationOpenCVpillow
MaGe Linux Operations
Written by

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.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.