uPyCam
uPyCam copied to clipboard
first pic taken wont have the specified white balance, the second one will
Repro case:
import gc
import machine
import time
import camera
class webcam():
def __init__(self):
self.saturation = 0
self.quality = 10
self.brightness = 0
self.contrast = 0
self.vflip = 0
self.hflip = 0
self.framesize = 8
self.led = machine.Pin(4, machine.Pin.OUT)
res = camera.init(0, format=camera.JPEG) #ESP32-CAM
camera.speffect(camera.EFFECT_NONE)
# WB_NONE (default) WB_SUNNY WB_CLOUDY WB_OFFICE WB_HOME
camera.whitebalance(camera.WB_OFFICE)
camera.saturation(self.saturation)
camera.brightness(self.brightness)
camera.contrast(self.contrast)
camera.quality(self.quality)
camera.flip(self.vflip)
camera.mirror(self.hflip)
camera.framesize(self.framesize)
def snap(self):
image = camera.capture()
return image
import uos
uos.mount(machine.SDCard(slot=2, width=1, sck=14, mosi=15, miso=2, cs=13), "/sd")
server = webcam()
def getTimestampStr():
rtc=machine.RTC()
y,m,d,w,h,m,s,_ = rtc.datetime()
return 'wb_%02d%02d%02d%02d' % (d,h,m,s)
def takepic():
image = server.snap()
time_str='/sd/%s.jpg' % getTimestampStr()
print(time_str)
print("sd:")
print(uos.listdir('/sd'))
with open(time_str, 'wb') as f:
f.write(image)
f.close()
gc.collect()
#set 'home' white balance
camera.whitebalance(3)
# this first pic wont ahve the correct white balance
takepic()
time.sleep(2)
#this one will be the good one!
takepic()
time.sleep(2)
camera.deinit()
uos.umount('/sd')
print("deep sleep...")
machine.deepsleep(5000)
Actually it was the sleep what made things work:
camera.whitebalance(3)
time.sleep(2)
takepic()