Skip to content

Instantly share code, notes, and snippets.

@bhive01
Last active March 22, 2018 22:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bhive01/0a0eefedc010515fe98d50db0a032ab7 to your computer and use it in GitHub Desktop.
Save bhive01/0a0eefedc010515fe98d50db0a032ab7 to your computer and use it in GitHub Desktop.
Using numpy scaling instead of openCV
import math
import numpy as np
import cv2
cam = cv2.VideoCapture(0)
cam.set(cv2.CAP_PROP_FRAME_WIDTH, 1280)
cam.set(cv2.CAP_PROP_FRAME_HEIGHT, 720)
cam.set(cv2.CAP_PROP_CONVERT_RGB, False) # turn off RGB conversion
# cam.set(cv2.CAP_PROP_FOURCC('Y', '1', '6', ''))
# get image
ret_val, im = cam.read()
# release camera
cam = cam.release()
# get dimensions of image for later processing
rows = im.shape[0]
cols = im.shape[1]
size = im.size
cv2.imwrite('raw.pgm', im)
# CU40 camera
# convert from 10 bit (1024 levels) to 8 bit (255) 255/104 = 0.249023
bf8 = np.array(np.asarray(im) * 0.249023, dtype = np.uint8)
bRGGB = np.copy(bf8)
IR = np.zeros([rows//2, cols//2], np.uint8)
#IRbig = np.zeros([dimx, dimy], np.uint8)
for x in range(0, rows, 2):
for y in range(0, cols, 2):
#replace IR data with nearest Green
bRGGB[x+1, y] = bf8[x+1,y]
#set IR data into new array
IR[x//2, y//2] = bf8[x, y+1]
BGRim = cv2.cvtColor(bRGGB, cv2.COLOR_BayerRG2BGR)
cv2.imwrite('rawscaled.pgm', bf8)
cv2.imwrite('RGB.ppm', BGRim)
cv2.imwrite('RGB.tiff', BGRim)
cv2.imwrite('IR.tiff', IR)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment