Advertisement
dan-masek

Untitled

Feb 4th, 2019
430
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.99 KB | None | 0 0
  1. import numpy as np
  2. import cv2
  3.  
  4. filename = '190204045325.bytearray'
  5.  
  6. height = 3024
  7. width = 4032
  8.  
  9. pixel_data = []
  10.  
  11. with open(filename, 'rb') as f:
  12.     for row in range(height):
  13.         for col_group in range(width / 4):
  14.             chunk = map(ord, list(f.read(5)))
  15.             p0 = (chunk[0] << 2) | ((chunk[4] >> 0) & 0x3)
  16.             p1 = (chunk[1] << 2) | ((chunk[4] >> 2) & 0x3)
  17.             p2 = (chunk[2] << 2) | ((chunk[4] >> 4) & 0x3)
  18.             p3 = (chunk[3] << 2) | ((chunk[4] >> 6) & 0x3)
  19.             pixel_data += [p0, p1, p2, p3]
  20.            
  21. img = np.array(pixel_data, np.uint16).reshape((height, width))
  22. img *= 0x40 # Full scale 16bit
  23.  
  24. cv2.imwrite('12345a.jpg', np.uint8(cv2.cvtColor(img, cv2.COLOR_BayerBG2BGR) / 256))
  25. cv2.imwrite('12345b.jpg', np.uint8(cv2.cvtColor(img, cv2.COLOR_BayerRG2BGR) / 256))
  26. cv2.imwrite('12345c.jpg', np.uint8(cv2.cvtColor(img, cv2.COLOR_BayerGB2BGR) / 256))
  27. cv2.imwrite('12345d.jpg', np.uint8(cv2.cvtColor(img, cv2.COLOR_BayerGR2BGR) / 256))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement