Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

first pic taken wont have the specified white balance, the second one will #12

Open
aguaviva opened this issue Sep 25, 2020 · 1 comment

Comments

@aguaviva
Copy link

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)
@aguaviva
Copy link
Author

Actually it was the sleep what made things work:

camera.whitebalance(3)
time.sleep(2)
takepic()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant