Skip to content

Instantly share code, notes, and snippets.

@matael
Created February 26, 2013 08:20
Show Gist options
  • Select an option

  • Save matael/5036934 to your computer and use it in GitHub Desktop.

Select an option

Save matael/5036934 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python2
#-*- coding:utf8 -*-
import cv2
import numpy as np
# instanciate CAM object
cam = cv2.VideoCapture(0)
# get one image for test processing
_,f = cam.read()
# get total width
l = f.shape[1]
# create mask
bandwidth = int(l*0.05) # 5% of total width
mask_left = np.zeros((f.shape[0],f.shape[1],1), np.uint8)
mask_right = np.zeros((f.shape[0],f.shape[1],1), np.uint8)
for i in mask_left: # toute la hauteur
for j in xrange(bandwidth):
i[j] = 1
for i in mask_right: # toute la hauteur
for j in xrange(bandwidth):
i[l-j-1] = 1
val_left = cv2.mean(f, mask=mask_left)
val_right = cv2.mean(f, mask=mask_right)
cv2.rectangle(f, (0,0), (bandwidth,f.shape[0]), color=val_left, thickness=-1)
cv2.rectangle(f, (l-bandwidth,0), (l,f.shape[0]), color=val_right, thickness=-1)
cv2.imwrite('test1.png', f)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment