我想用openCV阅读YUV视频。YUV视频为1920 * 1080,并使用YUV422格式(我已经尝试使用yuviewer读取此视频,并且可以正常工作)
我正在将Python3.6.4与带有OpenCV 3.3.1的Anaconda环境一起使用
首先我尝试了这个脚本/sf/answers/3347076981/但是这行
cv2.cvtColor(yuv, cv2.COLOR_YUV2BGR_Y422)
Run Code Online (Sandbox Code Playgroud)
给我这个错误。
File "read-yuv-video.py", line 29, in <module>
bgr = cv2.cvtColor(yuv, cv2.COLOR_YUV2BGR_UYVY)
cv2.error: C:\ci\opencv_1512688052760\work\modules\imgproc\src\color.cpp:11228: error: (-215) scn == 2 && depth == 0 in function cv::cvtColor
Run Code Online (Sandbox Code Playgroud)
当尝试从Y444或Y420转换为RGB或RGBA或GREY时,我也遇到此错误。我在Google或stackoverflow上找不到完全相同的错误。我试图重新安装opencv软件包,但没有成功。
在我下面的脚本中,除最后一个之外,所有cvtColor均有效。通过工作,我的意思是它显示图像但颜色错误。
import numpy as np
import cv2
# filename = r'C:\myPath\voile.yuv'
filename = r'C:\myPath\credits.yuv'
yuv_file = open(filename, 'rb')
frame_len = 1920 * 1080 * 3/2
shape = (int(1080 * 1.5), 1920)
raw = yuv_file.read(int(frame_len))
yuv = np.frombuffer(raw, dtype=np.uint8)
yuv = yuv.reshape(shape)
yuv = cv2.resize(yuv, …Run Code Online (Sandbox Code Playgroud) 这是重现错误的简单代码:
import os
os.environ["CUDA_VISIBLE_DEVICES"]="-1"
import numpy as np
from keras.models import Sequential
from keras.layers import Conv1D, Flatten, Dense
import tensorflow as tf
model_path = 'test.h5'
model = Sequential()
model.add(Conv1D(8,(5,), input_shape=(100,1)))
model.add(Flatten())
model.add(Dense(1))
model.compile(loss='mse', optimizer='adam')
model.save(model_path)
model = tf.keras.models.load_model(model_path, compile=False)
converter = tf.lite.TFLiteConverter.from_keras_model(model)
tflite_model = converter.convert()
interpreter = tf.lite.Interpreter(model_content=tflite_model)
interpreter.resize_tensor_input(interpreter.get_input_details()[0]['index'], (2,100,1))
interpreter.resize_tensor_input(interpreter.get_output_details()[0]['index'], (2,1))
interpreter.allocate_tensors()
Run Code Online (Sandbox Code Playgroud)
---------------------------------------------------------------------------
RuntimeError Traceback (most recent call last)
<ipython-input-3-ad8e2eea467f> in <module>
27 interpreter.resize_tensor_input(interpreter.get_output_details()[0]['index'], (2,1))
28
---> 29 interpreter.allocate_tensors()
<>/tensorflow/lite/python/interpreter.py in allocate_tensors(self)
240 def allocate_tensors(self):
241 self._ensure_safe()
--> 242 …Run Code Online (Sandbox Code Playgroud)