1 Star 0 Fork 2

qidouhai/Bad Apple STM32 OLED

forked from 青羽/bad-apple 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
VideoToBin.m 1.38 KB
一键复制 编辑 原始数据 按行查看 历史
青羽 提交于 2021-12-09 07:14 . update
clc;
clear;
% 定义常量
VIDEO_NAME = 'BadApple.mp4';
IMAGE_WIDTH = 128;
IMAGE_HEIGHT = 64;
PATH = './images/';
POSTFIX = '.bmp';
% numOfImages = 9480; % video.NumberOfFrames
% 处理视频
if exist(PATH, 'dir') == 0
mkdir(PATH);
end
video = VideoReader(VIDEO_NAME);
numOfImages = video.NumberOfFrames; % 9480
for i = 1 : numOfImages
frame = read(video, i);
frame = imresize(frame, [IMAGE_HEIGHT IMAGE_WIDTH]); % 调整大小为128x64
name = sprintf('%04d', i - 1);
path = [PATH, name, POSTFIX];
imwrite(frame, path); % 保存帧为BMP图片
end
% 读取并处理图片
imgs = zeros(numOfImages, IMAGE_WIDTH * IMAGE_HEIGHT);
for i = 1 : numOfImages
A = logical([]);
name = sprintf('%04d', i - 1);
path = [PATH, name, POSTFIX];
img = imread(path);
bw = imbinarize(img); % 和im2bw会有一点点不同
for j = 1 : 8
for k = 1 : 128
B = bw(1 + 8 * (j - 1) : 8 + 8 * (j - 1), k)';
A = [A, B];
end
end
imgs(i, :) = A;
end
% 编码
bin = uint8(zeros(numOfImages, IMAGE_WIDTH * IMAGE_HEIGHT / 8));
for i = 1 : numOfImages
for j = 1 : IMAGE_WIDTH * IMAGE_HEIGHT / 8
for k = 0 : 7
bin(i, j) = bin(i, j) + imgs(i, k + 1 + (j - 1) * 8) * 2^k;
end
end
end
% 保存为bin文件
bin = bin';
fp = fopen('BadApple.bin', 'wb');
fwrite(fp, bin, 'uint8');
fclose(fp);
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/qihai/bad-apple-stm32-oled.git
[email protected]:qihai/bad-apple-stm32-oled.git
qihai
bad-apple-stm32-oled
Bad Apple STM32 OLED
master

搜索帮助