Пример #1
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))
Пример #2
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)
Пример #3
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)
Пример #4
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)
Пример #5
0
def setup_cam(logger):
    QUALITY = 40
    try:
        camera.init(0)
    except OSError as e:
        # TODO: there should be a safeguard here to prevent constant restart
        time.sleep(2)
        logger.error(
            "unable to initialize camera. restarting.\n err: {}".format(e))
        machine.reset()
    else:
        logger.debug("Camera initialized")
        camera.quality(QUALITY)
        logger.debug("Camera quality set to {}".format(QUALITY))
        return camera
Пример #6
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
Пример #7
0
@author: douglas
"""

#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Thu Mar 25 19:47:48 2021

@author: douglas
"""

from time import sleep
import camera

camera.init(0, format=camera.JPEG, framesize=camera.FRAME_SVGA)
camera.quality(40)


def server():
    import socket
    import utime
    loop_t = 100

    header= 'HTTP/1.0 200 OK\n'\
            'Content-type: application/octet-stream\n' \
            'Cache-Control: no-cache\n' \
            'Connection: close\n\n\n' \


    bund1 = "--boundarydncross\n" \
           "Content-Type: image/jpeg\n" \
Пример #8
0
while True:
    cr = camera.init()
    print("Camera ready?: ", cr)
    if cr:
        break
    time.sleep(2)
    wifiConnectCount += 1
    if wifiConnectCount >= 5:
        break

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
    # setup networking
    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:
            break
    if wifiConnectCount >= 5:
        print("WIFI not ready. Can't continue!")
    else:
        pic = frame_gen()
Пример #9
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)
Пример #10
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")
Пример #11
0
 def quality(val=None):
     """ Configure the compression """
     if Camera.opened:
         # print("Quality %d"%val)
         return camera.quality(val)
     return None