import cv2 as cv
import numpy as np
if filename == "animated_image.webp"
image = np.full((128, 256, 4), (150, 150, 150, 255), dtype=np.uint8)
duration = 200
frames = []
durations = []
for i in range(10)
frame = image.copy()
cv.putText(frame, f
"Frame {i}", (30, 80), cv.FONT_HERSHEY_SIMPLEX, 1.5, (255, 100, 0, 255), 2)
frames.append(frame)
durations.append(duration)
animation_to_save.frames = frames
animation_to_save.durations = durations
if not success
print("Failed to load animation frames")
return
while True
for i, frame in enumerate(animation.frames)
if key_code == 27:
return
if __name__ == "__main__"
import sys
main(sys.argv[1]
if len(sys.argv) > 1
else "animated_image.webp")
CV_EXPORTS_W bool imreadanimation(const String &filename, CV_OUT Animation &animation, int start=0, int count=INT16_MAX)
從動畫影像檔案載入幀到 Animation 結構中。
CV_EXPORTS_W bool imwriteanimation(const String &filename, const Animation &animation, const std::vector< int > ¶ms=std::vector< int >())
將動畫儲存到指定檔案。
void putText(InputOutputArray img, const String &text, Point org, int fontFace, double fontScale, Scalar color, int thickness=1, int lineType=LINE_8, bool bottomLeftOrigin=false)
繪製文字字串。