使用python渲染jpg字节数组序列

时间:2018-10-23 20:20:06

标签: python turtle-graphics

我从网络收到了jpg序列,希望在屏幕上绘制它。

我想用乌龟画它,但是现在我只知道乌龟接受gif作为背景图片,而不是jpg。

#!/usr/bin/env python
import turtle

image = "demo.gif"
screen = turtle.Screen()

screen.addshape(image)
turtle.shape(image)

turtle.mainloop()

如何从字节数组到龟绘制jpg?还是其他更好的框架来显示视频序列?

1 个答案:

答案 0 :(得分:1)

opencv可以做到完美!

#!/usr/bin/env python

import cv2
import numpy as np
import time

def openfile(filename):
    fd = open("test.jpg","rb")
    frame = fd.read()
    frame = np.array(bytearray(frame))    
    fd.close()
    frame = cv2.imdecode(frame, 1)
    return frame

def openfile2(filename):
    frame = cv2.imread(filename)
    return frame

frame = openfile("test.jpg")
title = "jpeg"
cv2.namedWindow(title,cv2.WINDOW_AUTOSIZE);
cv2.imshow(title,frame)
cv2.waitKey(0)

cv2.destroyAllWindows()