Skip to content

Instantly share code, notes, and snippets.

@bhive01
Last active December 17, 2018 16:30
Show Gist options
  • Save bhive01/56b915ccc5118619fc19c71733f51d34 to your computer and use it in GitHub Desktop.
Save bhive01/56b915ccc5118619fc19c71733f51d34 to your computer and use it in GitHub Desktop.
reading images from a see3cam CU40
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 = cv2.convertScaleAbs(im, 0.249023)
bRGGB = np.copy(bf8)
scale = math.sqrt(2)
dimx = int(rows/scale)
dimy = int(cols/scale)
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):
#set IR data with nearest Green
bRGGB[x+1, y] = im[x, y+1]
#set IR data into new array
IRbig[int(x/scale), int(y/scale)] = im[x+1,y]
IR[x//2, y//2] = im[x+1,y]
BGRim = cv2.cvtColor(bRGGB, cv2.COLOR_BayerRG2BGR)
cv2.imwrite('rawscaled.pgm', im)
cv2.imwrite('RGB.ppm', BGRim)
cv2.imwrite('RGB.tiff', BGRim)
cv2.imwrite('IR.tiff', IR)
cv2.imwrite('IRbig.tif', IRbig)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment