У меня есть видеофайл в формате .bin с разрешением кадра width = 1280 и height = 672. Я преобразовал эти двоичные данные в формат RGB, затем перемасштабировал (width = 900 & height = 600) и через окно просмотра wxImage отображается.
def ret_frame(self, e, frame_num):
self.total_frames, f
#Reading a frame size data
self.uyvy_size = self.img_height * self.img_width * 2
assert (frame_num <= self.total_frames and frame_num >= 1), "frame number not in range"
f.seek(self.uyvy_size * (frame_num - 1), os.SEEK_SET)
uyvy = np.fromfile(f, count=self.uyvy_size, dtype=np.uint8)
#String each uyvy component into a separate numpy array
u = uyvy[::4].astype(dtype=np.float32)
y1 = uyvy[1::4].astype(dtype=np.float32)
v = uyvy[2::4].astype(dtype=np.float32)
y2 = uyvy[3::4].astype(dtype=np.float32)
#Logic to convert uyvy into rgb
r1 = ((y1 + ((1.4065) * (v - 128))) * 0.85).astype(dtype=np.uint8)
g1 = (((y1 - ((0.3455) * (u - 128)) - (0.7169 * (v - 128)))) * 0.85).astype(dtype=np.uint8)
b1 = (((y1 + ((1.7790) * (u - 128)))) * 0.85).astype(dtype=np.uint8)
r1[r1 > 255] = 255
g1[r1 > 255] = 255
b1[r1 > 255] = 255
r1[r1 < 0] = 0
g1[r1 < 0] = 0
b1[r1 < 0] = 0
r2 = (((y2 + ((1.4065) * (v - 128)))) * 0.85).astype(dtype=np.uint8)
g2 = (((y2 - ((0.3455) * (u - 128)) - (0.7169 * (v - 128)))) * 0.85).astype(dtype=np.uint8)
b2 = (((y2 + ((1.7790) * (u - 128)))) * 0.85).astype(dtype=np.uint8)
r2[r2 > 255] = 255
g2[r2 > 255] = 255
b2[r2 > 255] = 255
r2[r2 < 0] = 0
g2[r2 < 0] = 0
b2[r2 < 0] = 0
img = np.dstack((r1, g1, b1, r2, g2, b2))
self.image = wx.Image(self.img_width, self.img_height, img)
#OpenCV show is used to clear the buffer otherwise after showing some frame ,the framework crashes
dummy_img = np.zeros((0, 0, 3))
cv2.imshow("asdf", 0)
#Rescaling the image into smaller size image
self.image = self.image.Rescale(900, 600, wx.IMAGE_QUALITY_HIGH)
self.imageCtrl.SetBitmap(wx.Bitmap(self.image))