Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import Image;
- import cv;
- import subprocess
- import ImageStat
- import time
- camcapture = cv.CreateCameraCapture(0)
- cv.SetCaptureProperty(camcapture,cv.CV_CAP_PROP_FRAME_WIDTH, 128)
- cv.SetCaptureProperty(camcapture,cv.CV_CAP_PROP_FRAME_HEIGHT, 128);
- if not camcapture:
- print "Error opening WebCAM"
- sys.exit(1)
- while 1:
- #Determine environmental brightness.
- frame = cv.QueryFrame(camcapture)
- cv.SaveImage("./new.bmp",frame)
- im =Image.open("./new.bmp").convert('L')
- stat = ImageStat.Stat(im)
- stat = stat.mean[0]
- brightval = hex(int((255 - (stat*1.5)))) #Do the Math, Drop decimals, -> Hex.
- currentval=subprocess.Popen("setpci -s 00:02.0 F4.B",shell=True,stdout=subprocess.PIPE).stdout.read()
- if abs(int(brightval,16) - int(currentval,16)) > 30:
- print int(brightval,16)
- command = "setpci -s 00:02.0 F4.B=" + str(brightval)
- subprocess.Popen(command,shell=True)
- else:
- time.sleep(5)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement