Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import numpy as np
- import cv2
- filename = '190204045325.bytearray'
- height = 3024
- width = 4032
- pixel_data = []
- with open(filename, 'rb') as f:
- for row in range(height):
- for col_group in range(width / 4):
- chunk = map(ord, list(f.read(5)))
- p0 = (chunk[0] << 2) | ((chunk[4] >> 0) & 0x3)
- p1 = (chunk[1] << 2) | ((chunk[4] >> 2) & 0x3)
- p2 = (chunk[2] << 2) | ((chunk[4] >> 4) & 0x3)
- p3 = (chunk[3] << 2) | ((chunk[4] >> 6) & 0x3)
- pixel_data += [p0, p1, p2, p3]
- img = np.array(pixel_data, np.uint16).reshape((height, width))
- img *= 0x40 # Full scale 16bit
- cv2.imwrite('12345a.jpg', np.uint8(cv2.cvtColor(img, cv2.COLOR_BayerBG2BGR) / 256))
- cv2.imwrite('12345b.jpg', np.uint8(cv2.cvtColor(img, cv2.COLOR_BayerRG2BGR) / 256))
- cv2.imwrite('12345c.jpg', np.uint8(cv2.cvtColor(img, cv2.COLOR_BayerGB2BGR) / 256))
- cv2.imwrite('12345d.jpg', np.uint8(cv2.cvtColor(img, cv2.COLOR_BayerGR2BGR) / 256))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement