我尝试通过获取每个像素值进行转换,然后将其转换为字节格式,然后将其写为.wav文件。但是输出文件无法播放。我做错了什么?
import cv2
import numpy
from tkinter.filedialog import askopenfilename
file_path = askopenfilename(initialdir="C:/Users/Batman/Documents/Programming/tkinter/",
filetypes =(("jpg", "*.jpg"),("All Files","*.*")),
title = "Choose a file."
)
img=cv2.imread(file_path,1)
cv2.imshow('original',img)
height, width, channels = img.shape
s = b''
for x in range(height):
for y in range(width):
for z in range(3):
int_num=int(img[x][y][z])
s = s+ bytes([int_num])
file = open("sbytes.wav", 'wb')
file.write(s)
file.close()
cv2.waitKey(0)