Exemple #1
0
    def run(self, app_config):
        self.led = machine.Pin(app_config['led'], machine.Pin.OUT)

        # Camera resilience - if we fail to init try to deinit and init again
        if app_config['camera'] == 'ESP32-CAM':
            camera.init(0, format=camera.JPEG)  #ESP32-CAM

        elif app_config['camera'] == 'M5CAMERA':
            camera.init(0,
                        d0=32,
                        d1=35,
                        d2=34,
                        d3=5,
                        d4=39,
                        d5=18,
                        d6=36,
                        d7=19,
                        href=26,
                        vsync=25,
                        reset=15,
                        sioc=23,
                        siod=22,
                        xclk=27,
                        pclk=21)  #M5CAMERA
        camera.framesize(self.framesize)

        mws = MicroWebSrv(routeHandlers=self.routeHandlers, webPath="www/")
        mws.Start(threaded=True)
        gc.collect()
Exemple #2
0
 def framesize(resolution):
     """ Configure the frame size """
     val = None
     if resolution == b"UXGA" or resolution == b"1600x1200":
         val = camera.FRAMESIZE_UXGA
     if resolution == b"SXGA" or resolution == b"1280x1024":
         val = camera.FRAMESIZE_SXGA
     if resolution == b"XGA" or resolution == b"1024x768":
         val = camera.FRAMESIZE_XGA
     if resolution == b"SVGA" or resolution == b"800x600":
         val = camera.FRAMESIZE_SVGA
     if resolution == b"VGA" or resolution == b"640x480":
         val = camera.FRAMESIZE_VGA
     if resolution == b"CIF" or resolution == b"400x296":
         val = camera.FRAMESIZE_CIF
     if resolution == b"QVGA" or resolution == b"320x240":
         val = camera.FRAMESIZE_QVGA
     if resolution == b"HQVGA" or resolution == b"240x176":
         val = camera.FRAMESIZE_HQVGA
     if resolution == b"QQVGA" or resolution == b"160x120":
         val = camera.FRAMESIZE_QQVGA
     if Camera.opened and val != None:
         print("Framesize %s" % useful.tostrings(resolution))
         camera.framesize(val)
     else:
         print("Framesize not set")
Exemple #3
0
    def _httpHandlerSetData(self, httpClient, httpResponse, routeArgs):
        self.saturation = int(routeArgs['saturation']) - 2
        self.brightness = int(routeArgs['brightness']) - 2
        self.contrast = int(routeArgs['contrast']) - 2
        self.quality = int(routeArgs['quality'])
        self.vflip = bool(routeArgs['vflip'])
        self.hflip = bool(routeArgs['hflip'])
        self.framesize = int(routeArgs['framesize'])

        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)

        data = {
            'saturation': self.saturation,
            'brightness': self.brightness,
            'contrast': self.contrast,
            'quality': self.quality,
            'vflip': self.vflip,
            'hflip': self.hflip,
            'framesize': self.framesize
        }
        self._newdata = True
        httpResponse.WriteResponseOk(headers=None,
                                     contentType="text/html",
                                     contentCharset="UTF-8",
                                     content=json.dumps(data))
Exemple #4
0
def cli(fs, q, d):
    camera.framesize(fs)
    camera.quality(q)
    while True:
        s = socket.socket()
        try:
            #s.setblocking(0)
            s.connect(("asmon.com.ar", 8081))
            #    s.sendall(b"GET /connect/espcam/hola HTTP/1.1\r\nHost: feelfree.softether.net\r\nAccept: application/json\r\n\r\n")

            img = next(pic)
            s.send(b'%s %d\r\n\r\n' % (hdr['POST'], len(img)))
            s.send(img)
            s.send(b'\r\n')
            result = s.recv(12)
            while (len(result) > 0):
                #print(result)
                print('\ngot result')
                break
        except Exception as e:
            ee = str(e)
            if ee != '':
                print('cam error: ' + ee)
        s.close()  # flash buffer and close socket
        del s
        gc.collect()
        time.sleep(d)
Exemple #5
0
def envia_foto(Bot, mensaje=''):
    global camara
    #------------------ejemplo envio de foto-------------------------------------------------------
    #     camera.init(0, format=camera.JPEG)
    try:
        camera.init(0, format=camera.JPEG)
    except OSError as exc:
        camera.deinit()
        Bot.send_message(Bot.canal, exc.args[0])
        print(exc.args)
        return

    Led = Pin(4, Pin.OUT)  # define flash
    Led.on()  #enciende flash
    # girar vertical
    camera.flip(0)
    # giro horizontal
    camera.mirror(0)

    camera.framesize(camara.tamanyo_imagen)
    #'FRAME_240X240'/4, 'FRAME_96X96'/0, 'FRAME_CIF'/6, 'FRAME_FHD'/14, 'FRAME_HD'/11, 'FRAME_HQVGA'/3, 'FRAME_HVGA'/7, 'FRAME_P_3MP'/16, 'FRAME_P_FHD'/20, 'FRAME_P_HD'/15, 'FRAME_QCIF'/2, 'FRAME_QHD'/18, 'FRAME_QQVGA'/1, 'FRAME_QSXGA'/21, 'FRAME_QVGA'/5, 'FRAME_QXGA'/17, 'FRAME_SVGA'/9, 'FRAME_SXGA'/12, 'FRAME_UXGA'/13, 'FRAME_VGA'/8, 'FRAME_WQXGA'/19, 'FRAME_XGA'/10

    # efectos especiales
    camera.speffect(camara.efecto_especial)
    # EFFECT_NONE (default) EFFECT_NEG EFFECT_BW EFFECT_RED EFFECT_GREEN EFFECT_BLUE EFFECT_RETRO

    # white balance
    camera.whitebalance(camara.balance_blancos)
    # The options are the following:
    # WB_NONE (default) WB_SUNNY WB_CLOUDY WB_OFFICE WB_HOME

    # saturation
    camera.saturation(camara.saturacion)
    # -2,2 (default 0). -2 grayscale

    # brightness
    camera.brightness(camara.brillo)
    # -2,2 (default 0). 2 brightness

    # contrast
    camera.contrast(camara.contraste)
    #-2,2 (default 0). 2 highcontrast

    # quality
    camera.quality(camara.calidad)
    # 10-63 lower number means higher quality
    bufer = camera.capture()
    print('captura realizada')
    Led.off()  #apaga flash
    with open('file.jpg', 'w') as k:
        k.write(bufer)
    bufer = None
    camera.deinit()
    Bot.envia_archivo_multipart(configuracion.Chat_Id, 'file.jpg', 'sendPhoto',
                                'photo', mensaje)
Exemple #6
0
async def port3(cs, rq):
    rqp = rq[1].split('/')
    if rqp[1] == 'apikey':  # Must have /apikey/<REQ>
        if rqp[2] == 'flash':  # /apikey/flash/<what>
            if rqp[3] == 'on':
                flash_light.on()
            else:
                flash_light.off()
            cs.send(b'%s' % hdr['OK'])
        elif rqp[2] == 'pix':
            w = int(rqp[3])
            if w > 0 and w < 13:
                camera.framesize(w)
            cs.send(b'%s' % hdr['OK'])
        elif rqp[2] == 'qua':
            w = int(rqp[3])
            if w > 9 and w < 64:
                camera.quality(w)
            cs.send(b'%s' % hdr['OK'])
        elif rqp[2] == 'con':
            w = int(rqp[3])
            if w > -3 and w < 3:
                camera.contrast(w)
            cs.send(b'%s' % hdr['OK'])
        elif rqp[2] == 'sat':
            w = int(rqp[3])
            if w > -3 and w < 3:
                camera.saturation(w)
            cs.send(b'%s' % hdr['OK'])
        elif rqp[2] == 'bri':
            w = int(rqp[3])
            if w > -3 and w < 3:
                camera.brightness(w)
            cs.send(b'%s' % hdr['OK'])
        elif rqp[2] == 'spe':
            w = int(rqp[3])
            if w >= 0 and w < 7:
                camera.speffect(w)
            cs.send(b'%s' % hdr['OK'])
        elif rqp[2] == 'wbl':
            w = int(rqp[3])
            if w >= 0 and w < 5:
                camera.whitebalance(w)
            cs.send(b'%s' % hdr['OK'])
        else:
            cs.send(b'%s' % hdr['OK'])
    else:
        loop.create_task(foo([7, 5]))
        cs.send(b'%s' % hdr['OK'])

    clean_up(cs)
Exemple #7
0
def start():
    global cr
    wc = 0
    while True:
        cr = camera.init(0, format=camera.JPEG)
        print("Camera ready?: ", cr)
        if cr:
            camera.framesize(7)
            break
        time.sleep(2)
        wc += 1
        if wc >= 5:
            break
    return cr
Exemple #8
0
def start():
    global cr
    wc = 0
    while True:
        try:
            cr = camera.init(0, format=camera.JPEG)
        except:
            print('error initiating camera')
        print("Camera ready?: ", cr)
        if cr:
            camera.framesize(camera.FRAME_VGA)
            camera.quality(10)
            break
        time.sleep(2)
        wc += 1
        if wc >= 5:
            break
    return cr
for i in range(0, len(knownSsid)):
    for j in range(0, len(localNetworks)):
        print("Compare {} with {}".format(knownSsid[i], redes[j][0]))
        if (knownSsid[i] == redes[j][0]):
            print("Connecting to {}".format(knownSsid[i]))
            sta_if.connect(knownSsid[i], knownPasswd[i])
            while sta_if.isconnected() == False:
                pass
            print('Connection successful')
            ssid = knownSsid[i]
            ssidmode = True
            print(sta_if.ifconfig())
            break
# check framesize modes in https://github.com/shariltumin/esp32-cam-micropython
camera.init()
camera.framesize(5)
buf = camera.capture()
camera.deinit()

# there is no need to save right now, but, if you want to save file, use followigng code
# newFile = open("ESP32-CAM.jpg", "wb")
# newFile.write(buf)
# newFile.close()

# Create base64 string from image bytearray
bufBase64 = ubinascii.b2a_base64(buf)

# gather some free memory
gc.collect()

myScriptID = 'putYourScriptIdHere'
Exemple #10
0
def port3(cs, rq):
    rqp = rq[1].split('/')
    if rqp[1] == 'apikey':  # Must have /apikey/<REQ>
        if rqp[2] == 'flash':  # /apikey/flash/<what>
            if rqp[3] == 'on':
                flash_light.on()
            else:
                flash_light.off()
            cs.send(b'%s' % hdr['OK'])
        elif rqp[2] == 'fmt':
            w = int(rqp[3])
            if w >= 0 and w <= 2:
                camera.pixformat(w)
            cs.send(b'%s' % hdr['OK'])
        elif rqp[2] == 'pix':
            w = int(rqp[3])
            if w > 0 and w < 13:
                camera.framesize(w)
            cs.send(b'%s' % hdr['OK'])
        elif rqp[2] == 'qua':
            w = int(rqp[3])
            if w > 9 and w < 64:
                camera.quality(w)
            cs.send(b'%s' % hdr['OK'])
        elif rqp[2] == 'con':
            w = int(rqp[3])
            if w > -3 and w < 3:
                camera.contrast(w)
            cs.send(b'%s' % hdr['OK'])
        elif rqp[2] == 'sat':
            w = int(rqp[3])
            if w > -3 and w < 3:
                camera.saturation(w)
            cs.send(b'%s' % hdr['OK'])
        elif rqp[2] == 'bri':
            w = int(rqp[3])
            if w > -3 and w < 3:
                camera.brightness(w)
            cs.send(b'%s' % hdr['OK'])
        elif rqp[2] == 'ael':
            w = int(rqp[3])
            if w > -3 and w < 3:
                camera.aelevels(w)
            cs.send(b'%s' % hdr['OK'])
        elif rqp[2] == 'aev':
            w = int(rqp[3])
            if w >= 0 and w <= 1200:
                camera.aecvalue(w)
            cs.send(b'%s' % hdr['OK'])
        elif rqp[2] == 'agc':
            w = int(rqp[3])
            if w >= 0 and w <= 30:
                camera.agcgain(w)
            cs.send(b'%s' % hdr['OK'])
        elif rqp[2] == 'spe':
            w = int(rqp[3])
            if w >= 0 and w < 7:
                camera.speffect(w)
            cs.send(b'%s' % hdr['OK'])
        elif rqp[2] == 'wbl':
            w = int(rqp[3])
            if w >= 0 and w < 5:
                camera.whitebalance(w)
            cs.send(b'%s' % hdr['OK'])
        else:
            cs.send(b'%s' % hdr['none'])
    else:
        cs.send(b'%s' % hdr['err'])
    clean_up(cs)
Exemple #11
0
import machine
from machine import Pin
import camera
import time

flash = Pin(4, Pin.OUT)
flash.value(1)
time.sleep(1)
flash.value(0)

uos.mount(machine.SDCard(), "/sd")  #mount the SD card
camera.init()
camera.quality(10)
camera.framesize(9)
count = 0
while True:
    if count == 2200:
        print("Completed")
        break
    flash.value(1)
    pic = camera.capture()
    flash.value(0)
    file = open("/sd/pics/" + str(count) + ".jpg", "wb")
    file.write(pic)
    file.close()
    print(count, " done")
    count += 1
    time.sleep(1)

print("done")
Exemple #12
0
sta_if = network.WLAN(network.STA_IF)
sta_if.active(True)
if len(conf['password'])>7:
    sta_if.connect(conf['wifi'],conf['password'])
else:
    sta_if.connect(conf['wifi'])


try:
    camera.init(0, format=camera.JPEG)
except Exception as e:
    camera.deinit()
    camera.init(0, format=camera.JPEG)
    
if conf['pixel'] =='1':
    camera.framesize(camera.FRAME_QQVGA)
elif conf['pixel'] =='2':
    camera.framesize(camera.FRAME_240X240)
elif conf['pixel'] =='3':
    camera.framesize(camera.FRAME_QVGA)
elif conf['pixel'] =='4':
    camera.framesize(camera.FRAME_VGA)
elif conf['pixel'] =='5':
    camera.framesize(camera.FRAME_SVGA)
elif conf['pixel']=='6':
    camera.framesize(camera.FRAME_HD)
else:
    camera.framesize(camera.FRAME_240X240)


ret_q="""
Exemple #13
0
wc = 0
while True:
    cr = camera.init()
    print("Camera ready?: ", cr)
    if cr:
        break
    time.sleep(2)
    wc += 1
    if wc >= 5:
        break

if not cr:
    print("Camera not ready. Can't continue!")
else:
    camera.framesize(7)
    camera.quality(10)
    wifi.connect('1255', '12551255')
    print(green + 'Connection successful\n' + normal)

    sleep(2)

    pic = frame_gen()
    flash_light = Pin(04, Pin.OUT)
    #socks = sockets()
    #ports = [port1, port2, port3, port4, port4]  # 81, 82, 83, 80

    # th(srv, (3,))
    # th(srv, (2,))
    # th(srv, (3,))
    # th(srv, (2,))
Exemple #14
0
while True:
    cr = camera.init()
    print("Camera ready?: ", cr)
    if cr:
        print("Camera ready Success!")
        break
    time.sleep(2)

if not cr:
    print("Camera not ready. Can't continue!")
else:
    # reconfigure camera
    # camera.speffect(2) # black and white
    camera.quality(10)  # increase quality from 12 (default) to 10
    camera.framesize(4)  # 1~11分辨率
    #1=160x120 2=160x128 3=176 x 144 4=240 x 176 5=320 x 240 6=400x296
    #7=640x480 8=800x600 9=1024x768 10=1280x1024 11 =1600x1200
    # setup networking
    global config
    wifi = WIFI.STA.Sta(config['WIFI_SSID'], config['WIFI_PASSWORD'])
    wifi.connect()
    wifi.wait()
    wifiConnectCount = 0
    while not wifi.wlan.isconnected():
        print("WIFI not ready. Wait...")
        time.sleep(2)
        wifiConnectCount += 1
        if wifiConnectCount >= 5:
            print("WIFI not ready. Can't continue!")
            break