1 Star 0 Fork 3

只是条咸鱼罢了/esp8266驱动oled播放视频

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
视频转bpm.py 1.97 KB
一键复制 编辑 原始数据 按行查看 历史
superddg123 提交于 2021-04-09 19:06 . update 视频转bpm.py.
import cv2 as cv
import numpy as np
vc = cv.VideoCapture(r'H:\工坊\视频\极乐净土.mp4')#打开视频
c = 0#累计帧数
timeF = 4#隔5帧截一次图,数字越小,播放越细腻30—4 24—3
def binary_image(image):#将图像处理为二值化的程序
gray = cv.cvtColor(image, cv.COLOR_RGB2GRAY) #把输入图像灰度化
h, w =gray.shape[:2]
m = np.reshape(gray, [1,w*h])
mean = m.sum()/(w*h)
#print("mean:",mean)
#ret, binary = cv.threshold(gray, mean, 255, cv.THRESH_BINARY)
ret, binary = cv.threshold(gray, mean, 255, cv.THRESH_OTSU)
return binary
def save_binary(dirt):#保存二值化图像的程序,用字符串传入文件位置
image = cv.imread(dirt)
image = binary_image(image)#二值化
image = cv.bitwise_not(image)#反相,根据视频内容来定需不需要反相
image = cv.resize(image,(88,64))#调整尺寸
cv.imwrite('1.pbm',image)#保存
def access_pixels(image):#相反操作
height, width, channels = image.shape
print("width:%s,height:%s,channels:%s" % (width, height, channels))
for row in range(height):
for list in range(width):
for c in range(channels):
pv = image[row, list, c]
image[row, list, c] = 255 - pv
return image
###########################################################
#此部分为循环导出视频帧
if vc.isOpened(): # 判断是否正常打开
rval, frame = vc.read()#返回一个元组,frame是帧对象
else:
rval = False
print(rval)
while rval: # 循环读取视频帧
rval, frame = vc.read()
if rval is True:
if (c % timeF == 0): # 每隔timeF帧进行存储操作
frame = binary_image(frame)#二值化
#frame = cv.bitwise_not(frame)#反相,根据视频内容来定需不需要反相
frame = cv.resize(frame,(128,64))#调整尺寸
cv.imwrite('jile/' + str(c) + '.pbm',frame)#保存
c = c + 1
#print(c)
cv.waitKey(0)
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/heytang/bad-apple.git
git@gitee.com:heytang/bad-apple.git
heytang
bad-apple
esp8266驱动oled播放视频
master

搜索帮助

0d507c66 1850385 C8b1a773 1850385