Пример #1
0
def flash_off():
    lcd.display(4, "turning flash off...", 1)
    print "Switching flash off..."
    for cam in LEFTCAM, RIGHTCAM:
        cmd=PTPCAM + " --dev=" + cam + " --chdk='lua while(get_flash_mode()<2) do click(\"right\") end'"
        p = Popen(cmd, shell=True, stdout=PIPE, stderr=PIPE)
        sleep(SHORTPAUSE)
Пример #2
0
def set_iso():
    lcd.display(4, "setting ISO...", 1)
    for cam in LEFTCAM, RIGHTCAM:
        print "Setting ISO mode to 1 for camera", cam
        cmd=PTPCAM + " --dev=" + cam + " --chdk=\"lua set_iso_real(50)\""
        p = Popen(cmd, shell=True, stdout=PIPE, stderr=PIPE)
        sleep(SHORTPAUSE)
    lcd.display(4, "", 1)
Пример #3
0
def set_ndfilter():
    lcd.display(4, "setting ND filter...", 1)
    for cam in LEFTCAM, RIGHTCAM:
        print "Disabling neutral density filter for", cam, "-- see http://chdk.wikia.com/wiki/ND_Filter"
        cmd=PTPCAM + " --dev=" + cam + "--chdk=\"luar set_nd_filter(2)\""
        p = Popen(cmd, shell=True, stdout=PIPE, stderr=PIPE)
        sleep(SHORTPAUSE)
    lcd.display(4, "", 1)
Пример #4
0
def switch_to_record_mode():
    lcd.display(4, "switching mode...", 1)
    print "Switching cameras to record mode..."
    print "LEFTCAM is", LEFTCAM, "and RIGHTCAM is", RIGHTCAM
    for cam in LEFTCAM, RIGHTCAM:
        print "Switching camera", cam, "to record mode and sleeping 1 second..."
        cmd=PTPCAM + " --dev=" + cam + " --chdk='mode 1' > /dev/null 2>&1 && sleep 1s"
        p = Popen(cmd, shell=True, stdout=PIPE, stderr=PIPE)
    sleep(PAUSE)
def priceOrderer(price, mode):
    #this function takes in a unformated price, for example 199
    #and then returns it formated like: $1.99
    #It has 2 different modes, when mode is 0 a price of 080 would be converted to 80p
    #when mode is 1 it will be converted to $0.80
    tempPriceArray = list(price) #the price string is turned in to an array of characters as it allows me
    #to add a certain digit in the price string to a certain place, for example betweem a $ and a . easier
    finalPrice = "" #this is what is eventuly returned/displayed
    if mode != 1:
        if len(tempPriceArray) == 1:
            finalPrice = price
            finalPrice +="p"
        
        if len(tempPriceArray) == 2:
            finalPrice = price
            finalPrice += "p"
    if mode == 1:
        if len(tempPriceArray) == 1:
            finalPrice = "$"
            finalPrice += "0"
            finalPrice += "."

            finalPrice += "0"
            finalPrice += tempPriceArray[0]
        if len(tempPriceArray) == 2:
            finalPrice = "$"
            finalPrice += "0"
            finalPrice += "."

            finalPrice += tempPriceArray[0]
            finalPrice += tempPriceArray[1]     
            
    if len(tempPriceArray) == 3:

        finalPrice = "$"
        finalPrice += tempPriceArray[0]
        finalPrice += "."

        finalPrice += tempPriceArray[1]
        finalPrice += tempPriceArray[2]
        

    if len(tempPriceArray) == 4:
        finalPrice = "$"
        finalPrice += tempPriceArray[0]
        finalPrice += tempPriceArray[1]
        finalPrice += "."

        finalPrice += tempPriceArray[2]
        finalPrice += tempPriceArray[3]
        lcd.display("PRICE: "+finalPrice, 0)
        
        lcd.display("BACK: *", 1)    
    return finalPrice
def barcodeInput():
    lcd.display(" ", 0)
    lcd.display("BACK: * ENTER: #", 1)
    serialNumber = ""
    
    while True:
        print("inputing Now")
        key = keypad.getKey()#gets the what key is pressed one by one
        
        if key == "*":#this little bit here allows 2 things, if the user had accidently pressed the wrong key they can press *
        #to delete it
            if len(serialNumber) == 0:#or, if the everything has been deleted and they press * again it means they
            #want to go back so False is returned, so the function in use can handle that
                return False
            serialNumber = serialNumber[:-1]#subtracts 1 character from the barcode
            lcd.display(str(serialNumber), 0)#and displays the new barcode
            
        elif key == "#":#this is an enter key essentially
        #when the user presses this it means they have entered all the digits of the barcode
            return serialNumber 
            
        else:
            
            print("serialNumber")
            print(serialNumber)
            serialNumber += str(key)#adds the key that has been entered to the serial number
            lcd.display(str(serialNumber), 0)#prints the barcode as it is being entered, so the user can see
Пример #7
0
def set_zoom():
    lcd.display(4, "setting zoom...", 1)
    # TODO: make less naive about zoom setting (check before and after setting, ...)
    print "Setting zoom..."
    for cam in LEFTCAM, RIGHTCAM:
        print "Setting camera", cam, "zoom to 3..."
        lcd.display(4, "setting cam " + cam + " zoom", 1)
        # lua set_zoom() makes one camera shut down, looks like, so we're clicking:
        cmd=PTPCAM + " --dev=" + cam + " --chdk='lua while(get_zoom()<3) do click(\"zoom_in\") end'"
        p = Popen(cmd, shell=True, stdout=PIPE, stderr=PIPE)
        sleep(PAUSE)
        cmd=PTPCAM + " --dev=" + cam + " --chdk='lua while(get_zoom()>3) do click(\"zoom_out\") end'"
        p = Popen(cmd, shell=True, stdout=PIPE, stderr=PIPE)
        sleep(PAUSE)
    sleep(PAUSE)
def edit():
    
    print("At Edit")

    
    oldPrice, serialNumber = priceGet(True)
    print("PPringting stuff")
    print(oldPrice)
    print(serialNumber)

    

    
    if serialNumber == 0 and oldPrice == 0:
        print("WHY AM I NOT HERE")
        return 0
    
    
    lcd.display("OLD: "+oldPrice+" NEW:", 0)
    lcd.display("$0.00 ENTER: #", 1)
    price = ""
    exitLoop = False
    while exitLoop == False:
        key = keypad.getKey()
        if key == "#":
            exitLoop = True
        elif key == "*":
            if len(price) == 0:
                return 0
            price = price[:-1]
        else:
            price +=key
        print("Now printing price")
        print(price)
        print("Now printing fnalPrice")
        
        finalPrice = priceOrderer(price, 1)
        print(finalPrice)
        lcd.display(finalPrice+" ENTER: #", 1)
    model.edit(serialNumber, price)
    lcd.display("SUCCESS", 0)
    lcd.display(" ", 1)
    time.sleep(1)
    return 0
Пример #9
0
def shoot():
    global SHOTS
    lcd.display(3, "WAIT", 2)
    lcd.display(4, "shooting", 1)
    print "Shooting with cameras", LEFTCAM, "(left) and ", RIGHTCAM, " (right)"
    for cam in LEFTCAM, RIGHTCAM:
        cmd=PTPCAM + " --dev=" + cam + " --chdk='lua " + SHOTPARAMS + "'"
        p = Popen(cmd, shell=True, stdout=PIPE, stderr=PIPE)
        sleep(SHORTPAUSE * 2)
    sleep(SHORTPAUSE * 2) # necessary?
    lcd.display(4, "ready", 1)
    lcd.display(3, "TAP TO SHOOT", 2)
    SHOTS += 1
def priceGet(modulus):
    #this function can act as its own "menu", or it can be used by other "menus" to return theprice of an item, for example if I wanted 
    #to get the price of something i would use this menu, if I wanted to edit the price I would use the edit menu,
    #which would call this function to get the price to show you before you change it.
    #if modulus is true then it returns the price
    #otherwise it displays it on the screen and acts as its own menu
    
    
    print("At price get")
    #calls the barcodeInput function to get the serialNumber of the item whos price is wanted
    serialNumber = barcodeInput()
    if serialNumber == False: #false will be returned from the barcodeInput function if the user wants to go back
    #so, if priceGet is being used in a not modulus fashion it will return 0 to main, taking us back to the main menu
    #otherwise it will return 0, 0 to the menu that called it and that menu will decide what to do with it
    #specifically
        if modulus:
            return 0, 0
        else:
            return 0 #
    price = model.getPrice(serialNumber)#This searches the database for the serialNumber the user has inputed
    

    if price == False: #false will be returned if the barcode does not exist
        lcd.display("Barcode not", 0)
        lcd.display("recognised", 1)
        time.sleep(2)
        if modulus:
            print("Returning 0, 0")
            return 0, 0
        else:
            return 0
    price = str(price)
    finalPrice = priceOrderer(price, 0)#orders the returned price, uses mode 0 as in this case we would prefer 60p to $0.60
    
    if modulus == False:
        
        
        lcd.display("PRICE: "+finalPrice, 0) #displays the price
            
        lcd.display("BACK: *", 1)
        print(finalPrice)
        while True:#waits for the user to press *, so they can return to the main menu
            key = keypad.getKey()
            if key == "*":
                return 0
    if modulus == True: #or returns the price to the function that called it
        
        
        return finalPrice, serialNumber 
Пример #11
0
def download_from_cams():
    lcd.display(3, "downloading...", 1)
    TIMESTAMP=datetime.now().strftime("%Y%m%d%H%M")
    # gphoto2 processes end with -1 unexpected result even though everything seems to be fine -> hack: true gives exit status 0
    # ptpcam downloads with bad file creation date and permissions....
    for side in "left", "right":
        makedirs(SCANDIRPREFIX+TIMESTAMP+"/"+side)
        chown(SCANDIRPREFIX+TIMESTAMP+"/"+side, 1000, 1000)
        chmod(SCANDIRPREFIX+TIMESTAMP+"/"+side, 0755)
    chown(SCANDIRPREFIX+TIMESTAMP, 1000, 1000)
    chmod(SCANDIRPREFIX+TIMESTAMP, 0755)

    # previous attempts used gphoto, then ptpcam en masse; then tried listing
    # then downloading one at a time with ptpcam; now back to bulk, but waiting
    # an amount of time proportional to the number of files
    for pair in [LEFTCAM, "left"], [RIGHTCAM, "right"]:
        print "Downloading images from", pair[0], "..."
        chdir(SCANDIRPREFIX+TIMESTAMP+"/"+pair[1])
        cmd = PTPCAM + " --dev=" + pair[0] + " -L | grep 0x | wc -l"
        numfiles = cmdoutput(cmd)
        print "I see " + numfiles + " images on " + pair[0]
        lcd.display(4, numfiles + " files from " + pair[1], 1)
        cmd = PTPCAM + " --dev=" + pair[0] + " -G ; true"
        p = Popen(cmd, shell=True, stdout=PIPE, stderr=PIPE)
        sleeptime = DLFACTOR * int(numfiles)
        print "sleeping " + str(sleeptime) + " seconds"
        sleep(sleeptime)
    sleep(LONGPAUSE)

    # timestamp and perms are not set correctly on the files we get from the camera....
    counter = 0
    for root, dirs, files in walk(SCANDIRPREFIX+TIMESTAMP):
        for filename in files:
            thisfile = join(root, filename)
            utime(thisfile, None)
            chown(thisfile, 33, 33)
            chmod(thisfile, 0744)
            counter += 1
    print "Adjusted " + str(counter) + " files"
Пример #12
0
def delete_from_cams():
    lcd.display(3, "deleting from", 1)
    lcd.display(4, "cameras...", 1)
    for cam in LEFTCAM, RIGHTCAM:
        print "deleting existing images from SD card on " + cam
        cmd = PTPCAM + " --dev=" + cam + " -D; true"
        p = Popen(cmd, shell=True, stdout=PIPE, stderr=PIPE)
        sleep(SHORTPAUSE)
    lcd.display(4, "", 1)
def home():
    #This is the home menu, the program starts here
    #This menu is essentially a gateway to other menus and their functions
    
    while True:
        print("should not be here")
        lcd.display("PRICE: * NEW: 0", 0)
        lcd.display("EDIT: #", 1)
        #gets the users choice
        choice = keypad.getKey()
        #returns the value associated with the desired menu, so the main function can change to
        #that menu
        if choice == "*":
            return 1
        elif choice == "#":
            return 2
        elif choice == "0":
            return 3
        else:
            #this plays havoc with the LCD i have no idea why
            lcd.display("Invalid input", 0)
            lcd.display("Enter a * or #", 1)
            print("")
Пример #14
0
import sensor
import image
import lcd
import KPU as kpu
lcd.init()
lcd.rotation(2)
sensor.reset()
sensor.set_pixformat(sensor.RGB565)
sensor.set_framesize(sensor.QVGA)
sensor.set_windowing((224, 224))
sensor.set_vflip(0)
sensor.set_hmirror(0)
sensor.run(1)
lcd.clear()
lcd.draw_string(135, 0, "MobileNetDemo")
f = open('/sd/model/janken.txt', 'r')
labels = f.readlines()
f.close()
print(labels)
task = kpu.load("/sd/model/janken.kmodel")
while(True):
  img = sensor.snapshot()
  fmap = kpu.forward(task, img)
  plist = fmap[:]
  pmax = max(plist)
  max_index = plist.index(pmax)
  a = lcd.display(img, roi=(0, 0, 135, 135), oft=(0, 0))
  lcd.draw_string(135, 100, "%s     " % (labels[max_index].strip()))
  lcd.draw_string(135, 119, "%.2f" % (pmax))
a = kpu.deinit(task)
def findCubeCenter():
    """
    find the cube roi position
    """
    global roi
    sensor.set_auto_whitebal(False)
    sensor.set_contrast(2)

    cnt = 1
    LAB_THRESHOLD = (
        (0, 60, -40, 50, -40, 10),  # blue
        (0, 40, -50, 40, -60, 30),  # yellow orange red white
        (0, 50, -40, 15, -25, 70))
    #(0, 70, -25, 15, -60, 30)) # green

    CENTER_THRESHOLD = roi[2] / 3 / 2
    gain = 0
    while (True):

        if cnt > 12:
            sensor.set_auto_gain(gain)

        img = sensor.snapshot()

        if cnt % 60 == 0:
            cnt = 1
            gain += 10

        if (int(cnt / 24)) % 2 == 1:
            lab_threshold = LAB_THRESHOLD[int(cnt / 12) - 2]
            img = img.binary([lab_threshold])
            img = img.dilate(2)
            img = img.erode(2)

        lcd.display(img)

        center_roi = list(
            map(int, [
                roi[0] + roi[2] / 2 - CENTER_THRESHOLD * 2,
                roi[1] + roi[3] / 2 - CENTER_THRESHOLD * 2,
                CENTER_THRESHOLD * 4, CENTER_THRESHOLD * 4
            ]))
        squares = []
        for r in img.find_rects(roi=center_roi, threshold=500):
            if (isSquare(r)):
                squares.append(r)
                img = img.draw_rectangle(r.rect())
                for p in r.corners():
                    img = img.draw_circle(p[0], p[1], 5, color=(0, 255, 0))
                lcd.display(img)
                #time.sleep_ms(5000)
        if not squares:
            cnt += 1
            print(cnt)
        else:
            roi = findCenter(squares, roi, CENTER_THRESHOLD * math.sqrt(2))
            center_roi = list(
                map(int, [
                    roi[0] + roi[2] / 2 - CENTER_THRESHOLD * 2,
                    roi[1] + roi[3] / 2 - CENTER_THRESHOLD * 2,
                    CENTER_THRESHOLD * 4, CENTER_THRESHOLD * 4
                ]))
            img = img.draw_rectangle(center_roi)
            img = img.draw_rectangle(roi)

            lcd.display(img)

            sensor.reset()
            sensor.set_pixformat(sensor.RGB565)
            sensor.set_framesize(sensor.QQVGA)

            sensor.set_auto_whitebal(False)
            sensor.skip_frames(time=60)
            gain = sensor.get_gain_db()
            sensor.set_auto_gain(0, gain)
            sensor.skip_frames(time=60)
            sensor.set_auto_exposure(0, 80000)

            sensor.skip_frames(time=60)
            return 1
Пример #16
0
## Copyright (c) 2019 aNoken
## https://anoken.jimdo.com/
## https://github.com/anoken/purin_wo_motto_mimamoru_gijutsu
## This Code is Miaxpy

import sensor,lcd,image
import KPU as kpu
lcd.init()
lcd.rotation(2)
sensor.reset()
sensor.set_pixformat(sensor.RGB565)
sensor.set_framesize(sensor.QVGA)
sensor.set_windowing((224, 224))
task = kpu.load("mnist.kmodel")
sensor.run(1)
while True:
    img = sensor.snapshot()
    lcd.display(img)              
    img1=img.to_grayscale(1)     
    img2=img1.resize(28,28)       
    a=img2.invert()                
    a=img2.strech_char(1)           
    lcd.display(img2,oft=(120,32))
    a=img2.pix_to_ai();           
    fmap=kpu.forward(task,img2)	
    plist=fmap[:]                 
    pmax=max(plist)               
    max_index=plist.index(pmax)	
    lcd.draw_string(0,0,"%d: %.3f"%(max_index,pmax),lcd.WHITE,lcd.BLACK)
Пример #17
0
from Maix import utils
from Maix import GPIO
from machine import UART
from board import board_info
from fpioa_manager import *

time.sleep(
    0.5)  # Delay for few seconds - EVERYTHING must be under 410 lines of code
lcd.init()
lcd.clear((255, 206, 0))
lcd.display(
    image.Image("/sd/oc.jpg").draw_rectangle(0,
                                             0,
                                             320,
                                             30,
                                             color=(0, 0, 0),
                                             fill=True).draw_string(
                                                 50,
                                                 1,
                                                 "GATEBOT BOOTUP",
                                                 color=(5, 250, 0),
                                                 scale=2))
but_stu = 1
fm.register(board_info.LED_R, fm.fpioa.GPIO0)
fm.register(board_info.LED_G, fm.fpioa.GPIO1)
fm.register(board_info.LED_B, fm.fpioa.GPIO2)
led_r = GPIO(GPIO.GPIO0, GPIO.OUT)
led_r.value(1)
led_g = GPIO(GPIO.GPIO1, GPIO.OUT)
led_g.value(1)
led_b = GPIO(GPIO.GPIO2, GPIO.OUT)
led_b.value(1)
def newItem():
    serialNumber = ""
    temp = True
    temp = barcodeInput()
    if temp == False:
        return 0
    serialNumber += temp
    print("Now printing serial number")
    print(serialNumber)
    if serialNumber == False:
        return 0
    
    exitLoop = False
    price = ""
    lcd.display("PRICE: $0.00", 0)
    lcd.display("BACK: * ENTER: #", 1)
    while exitLoop == False:
        key = keypad.getKey()
        if key == "#":
            exitLoop = True
        elif key == "*":
            if len(price) == 0:
                return 0
            price = price[:-1]
        else:
            price +=key
        print("Now printing price")
        print(price)
        print("Now printing fnalPrice")
        
        finalPrice = priceOrderer(price, 1)
        print(finalPrice)
        lcd.display("PRICE: "+finalPrice, 0)
        lcd.display("BACK: * ENTER: #", 1)
    result = model.newItem(serialNumber, price)
    if result:
        lcd.display("SUCCESS", 0)
        lcd.display("", 1)
    else:
        lcd.display("ITEM ALLREADY", 0)
        lcd.display("EXISTS", 1)
    return 0    
Пример #19
0
    sensor.set_pixformat(sensor.RGB565)
    sensor.set_framesize(sensor.QVGA) #QVGA=320x240
    sensor.run(1)

#################################
#main
#################################
show_logo()
initialize_camera()

task = kpu.load(0x300000)
anchor = (1.889, 2.5245, 2.9465, 3.94056, 3.99987, 5.3658, 5.155437, 6.92275, 6.718375, 9.01025)
a = kpu.init_yolo2(task, 0.5, 0.3, 5, anchor)

try:
    while(True):
        img = sensor.snapshot()
        code = kpu.run_yolo2(task, img)
        if code:
            for i in code:
                print(i)
                a = img.draw_rectangle(i.rect())
	    time.sleep(0.2)
	    play_sound("/sd/hyokkori.wav")
	    pic = sensor.snapshot()
	    lcd.display(pic)
	    time.sleep(5)
        a = lcd.display(img)
except KeyboardInterrupt:
    kpu.deinit(task)
    sys.exit()
Пример #20
0
from Maix import MIC_ARRAY as mic
import lcd

lcd.init()
mic.init()

while True:
    imga = mic.get_map()
    b = mic.get_dir(imga)
    a = mic.set_led(b,(0,0,255))
    imgb = imga.resize(160,160)
    imgc = imgb.to_rainbow(1)
    a = lcd.display(imgc)
mic.deinit()


import video,time
from Maix import GPIO
from board import board_info
from fpioa_manager import fm

fm.register(34,  fm.fpioa.I2S0_OUT_D1)
fm.register(35,  fm.fpioa.I2S0_SCLK)
fm.register(33,  fm.fpioa.I2S0_WS)

v = video.open("/sd/badapple.avi")
print(v)
v.volume(50)
while True:
    if v.play() == 0:
        print("play end")
Пример #21
0
import KPU as kpu
lcd.init()
sensor.reset()
sensor.set_pixformat(sensor.RGB565)
sensor.set_framesize(sensor.QVGA)
sensor.set_windowing((224, 224))
sensor.set_vflip(1)
sensor.run(1)
lcd.clear()
lcd.draw_string(100, 96, "MobileNet Demo")
lcd.draw_string(100, 112, "Loading labels...")
f = open('labels.txt', 'r')
labels = f.readlines()
f.close()
task = kpu.load(0x200000)
clock = time.clock()
while (True):
    img = sensor.snapshot()
    clock.tick()
    fmap = kpu.forward(task, img)
    fps = clock.fps()
    plist = fmap[:]
    pmax = max(plist)
    max_index = plist.index(pmax)
    a = lcd.display(img, oft=(0, 0))
    lcd.draw_string(
        0, 224, "%.2f:%s                            " %
        (pmax, labels[max_index].strip()))
    print(fps)
a = kpu.deinit(task)
Пример #22
0
# refer to http://blog.sipeed.com/p/680.html
import sensor, image, lcd, time
import KPU as kpu
lcd.init()
lcd.clear()
try:
    img = image.Image("/sd/startup.jpg")
    lcd.display(img)
except:
    lcd.draw_string(lcd.width() // 2 - 100,
                    lcd.height() // 2 - 4, "Error: Cannot find startup.jpg",
                    lcd.WHITE, lcd.RED)

sensor.reset()
sensor.set_pixformat(sensor.RGB565)
sensor.set_framesize(sensor.QVGA)
sensor.set_windowing((224, 224))
sensor.set_vflip(1)
sensor.run(1)
f = open('/sd/labels.txt', 'r')
labels = f.readlines()
f.close()
task = kpu.load(
    '/sd/b7e12bad85da152339158e734570a2a2_cd51f50726f11976c1aefe0403b6edd8.smodel'
)
lcd.clear(0xFFFF)
clock = time.clock()
while (True):
    img = sensor.snapshot()
    clock.tick()
    fmap = kpu.forward(task, img)
Пример #23
0
def __main__():
    while True:
        print("----")
        inputLine = " "
        currentCard = None
        currentCustomer = None
        currentDrink = None
        button = 0
        calc = ''
        while inputLine != "":
            inputLine = ser.readline()
            print(inputLine)
            checkDrink = re.search(r"b\' [0-9]", str(inputLine)[:4])
            checkLine = True

            while checkLine:

                if (str(inputLine)[:12] == "b\'Card UID: "):
                    CardUID = str(inputLine)[12:23]
                if (str(inputLine) == "b\'1\\r\\n\'"):
                    button = 1
                if (str(inputLine)[:5] == "b\' 74"):

                    currentCustomer = CardUID
                    #               CalcBAC(currentCustomer)
                    calc += 'a'

                    print(currentCustomer)

                elif (checkDrink is not None
                      and str(inputLine)[:4] == checkDrink.group(0)):

                    currentDrink = str(inputLine)[3:50]
                    drink = DB.read_data('drinks', currentDrink)
                    print(currentDrink)
                    calc += 'a'

                elif (str(inputLine) == "b\'\'"):
                    pass


#                print("no input detected...")

#process the line depending on what fields are available

                if (currentCustomer != None and currentDrink != None):
                    ## TODO: send drink to customer DB entry
                    print("send drink")
                    person = DB.read_data('patrons', CardUID)
                    if (person.get("gender") == "Male"):
                        BODY_WATER = 0.58
                    elif (person.get("gender") == "Female"):
                        BODY_WATER = 0.49
                    # Declare constnts
                    METABOLISM = 0.017
                    SWEDISH_FACTOR = 1.2
                    WATER_BLOOD = 0.806
                    CONVERT_TO_PERCENT = 10.0
                    # run the calculations
                    bac = (
                        ((WATER_BLOOD *
                          (float(drink.get("percent std. drink")) +
                           float(person.get("stdDrink"))) * SWEDISH_FACTOR) /
                         (BODY_WATER * float(person.get("weight"))) -
                         (METABOLISM *
                          (int(person.get("initDrink").strftime("%H")) -
                           int(datetime.datetime.now().strftime("%H")))) *
                         CONVERT_TO_PERCENT))

                    if (int(person.get("Budget")) - int(drink.get("price")) <=
                            0):
                        lcd.display('lack of funds!')
                        print("lack of funds!")
                    else:
                        if bac > .09:
                            lcd.display("take a break!")
                            print("lack of time!")
                        else:
                            DB.add_data(
                                'patrons', CardUID, {
                                    "stdDrink":
                                    float(drink.get("percent std. drink")) +
                                    float(person.get("stdDrink")),
                                    "Budget":
                                    int(person.get("Budget")) -
                                    int(drink.get("price"))
                                })
                            lcd.display("Cheers!")
                            print("cheers!")
                    # clear fields
                    currentCard = None
                    currentCustomer = None
                    currentDrink = None

                elif (currentCard != None):
                    ## TODO: check if entry in DB
                    # if entry found: pass

                    newUser = Customer()
                    newUser.processData(inputLine)
                    newUser.printData()

                    #temp            db.add_data("Patrons", newUser)
                    # clear fields
                    newUser = None
                    currentCard = None
                    currentCustomer = None
                    currentDrink = None

                while button == 1:
                    newUser1 = Customer.Customer()
                    DL = input()
                    print(DL)
                    newUser1.processData(DL)
                    newUser1.printData()
                    DB.add_data('patrons', CardUID, newUser1.serializeData())

                    button = 0
                checkLine = False
Пример #24
0
    displayimg.draw_rectangle(areaM, thickness=2, color=(0, 255, 0))
    displayimg.draw_rectangle(areaL, thickness=2, color=(0, 255, 0))
    displayimg.draw_rectangle(areaR, thickness=2, color=(0, 255, 0))
    displayimg.draw_rectangle(areaU, thickness=2, color=(255, 0, 0))

    if findRectsPixels(areaL) >= 1500:
        print("PixelsL: " + str(findRectsPixels(areaL)) +
              " Övergångsställe vänster")
        #uart_A.write("Övergångsställe vänster"))
    else:
        print("PixelsL: " + str(findRectsPixels(areaL)))
    if findRectsPixels(areaR) >= 1500:
        print("PixelsR: " + str(findRectsPixels(areaR)) +
              " Övergångsställe höger")
        #uart_A.write("Övergångsställe höger"))
    else:
        print("PixelsR: " + str(findRectsPixels(areaR)))

    if findRectsPixels(areaU) >= 1300:
        print("PixelsR: " + str(findRectsPixels(areaU)) +
              " Övergångsställe Rakt Fram")
        #uart_A.write("Övergångsställe rakt fram"))
    else:
        print("PixelsU: " + str(findRectsPixels(areaU)))
        findMiddleRects(areaM)
        drawMidLine(areaM)
    #img.draw_line(int(width/2),0,int(width/2),height)
    #displayimg.draw_rectangle(0,0,40,height,thickness=2, color=(0,255,0))

    lcd.display(displayimg)
Пример #25
0
# Histogram Equalization
#
# This example shows off how to use histogram equalization to improve
# the contrast in the image.

import sensor, image, time, lcd

# Init LCD
lcd.init(freq=15000000)

sensor.reset()
sensor.set_pixformat(sensor.RGB565)
sensor.set_framesize(sensor.QVGA)
#sensor.set_windowing((128, 96))    #set to 224x224 input
sensor.skip_frames(time = 2000)
sensor.run(1)
#
clock = time.clock()

while(True):
    clock.tick()
    #img = sensor.snapshot()
    img = sensor.snapshot().histeq()
    #img = img.gaussian(1)           # Blur
    print(clock.fps())
    lcd.display(img.resize(320,240))
Пример #26
0
# FPS clock
clock = time.clock()

while(True):
    clock.tick()

    # Capture an image
    image = sensor.snapshot()

    # Capture FIR data
    #   ta: Ambient temperature
    #   ir: Object temperatures (IR array)
    #   to_min: Minimum object temperature
    #   to_max: Maximum object temperature
    ta, ir, to_min, to_max = fir.read_ir()

    # Draw IR data on the framebuffer
    fir.draw_ir(image, ir)

    # Draw ambient, min and max temperatures.
    image.draw_string(0, 0, "Ta: %0.2f"%ta, color = (0xFF, 0x00, 0x00))
    image.draw_string(0, 8, "To min: %0.2f"%to_min, color = (0xFF, 0x00, 0x00))
    image.draw_string(0, 16, "To max: %0.2f"%to_max, color = (0xFF, 0x00, 0x00))

    # Display image on LCD
    lcd.display(image)

    # Print FPS.
    print(clock.fps())
Пример #27
0
fft_points = 512
hist_x_num = 128

lcd.init()
# close WiFi
fm.register(8, fm.fpioa.GPIO0)
wifi_en = GPIO(GPIO.GPIO0, GPIO.OUT)
wifi_en.value(0)
fm.register(20, fm.fpioa.I2S0_IN_D0)
fm.register(30, fm.fpioa.I2S0_WS)  # 30 on dock/bit Board
fm.register(32, fm.fpioa.I2S0_SCLK)  # 32 on dock/bit Board

rx = I2S(I2S.DEVICE_0)
rx.channel_config(rx.CHANNEL_0, rx.RECEIVER, align_mode=I2S.STANDARD_MODE)
rx.set_sample_rate(sample_rate)
img = image.Image(size=(128, 128))
img = img.to_grayscale()

while True:
    audio = rx.record(sample_points)
    fft_res = FFT.run(audio.to_bytes(), fft_points)
    fft_amp = FFT.amplitude(fft_res)
    img_tmp = img.cut(0, 0, 128, 127)
    img.draw_image(img_tmp, 0, 1)
    for i in range(hist_x_num):
        img[i] = fft_amp[i]
    del (img_tmp)
    imgc = img.to_rainbow(1)
    lcd.display(imgc)
    del (imgc)
    fft_amp.clear()
Пример #28
0
    if crossing2:
        for b in crossing2:
            #print(b[2]*b[3])
            if b[2] * b[3] > 2001:
                crossings.append(b)
                tmp = img.draw_rectangle(b[0:4], color=(255, 136, 0))
            else:
                tmp = img.draw_rectangle(b[0:4], color=(0, 136, 255))
                lines.append(b)
                tmp = bw_img.draw_rectangle(b[0:4], color=(255))

    line = bw_img.get_regression([(100, 256) if BINARY_VISIBLE else THRESHOLD],
                                 area_threshold=300,
                                 robust=True)

    #if line:
    #    img.draw_line(line.line(), color = (120, 255, 3), thickness = 5)

    if len(crossings) > 2:
        print("4-vägskorsning")
    elif len(crossings) == 1:
        print("T-korsning")
    elif len(lines) > 3:
        print("Raksträcka")
    else:
        print("sväng")
    #print(blank.compress_for_ide(), end="")
    lcd.display(bw_img)
    #print(clock.fps())
Пример #29
0
def outer_loop():
    lcd.clear()

    global SHOTS
    # debounce code from http://www.cl.cam.ac.uk/projects/raspberrypi/tutorials/robot/buttons_and_switches/
    lcd.display(2, "TURN ON CAMERAS,", 1)
    lcd.display(3, "TAP PEDAL TO START", 1)
    print "Starting outer foot pedal loop..."
    prev_input = 0
    firstloop = 1
    # start = time()
    while True:
        try:
            input = GPIO.input(PIN)
            if ((not prev_input) and input):
                if (firstloop != 1):
                    print("Button pressed")
                    lcd.display(2, "starting up", 2)
                    lcd.display(3, "PLEASE WAIT", 2)
                    detect_cams()
                    # delete_from cams confuses ptpcam -> do that at the end
                    switch_to_record_mode()
                    set_zoom()
                    flash_off()
                    set_iso()
                    set_ndfilter()
                    SHOTS = 0
                    inner_loop()
                    # start = time()
                    lcd.display(2, "TURN ON CAMERAS,", 1)
                    lcd.display(3, "TAP PEDAL TO START", 1)
                    print "Rejoining outer foot pedal loop..."
                firstloop = 0
            prev_input = input
            # slight pause to debounce
            sleep(DEBOUNCEPAUSE)
        except KeyboardInterrupt:
            lcd.clear()
            lcd.display(2, "GOODBYE", 2)
            sleep(PAUSE)
            lcd.clear()
            print "Quitting."
            sys.exit()
        text = marquee.next()
        lcd.display(1, text, 1)
Пример #30
0
'''
实验名称:LCD
版本: v1.0
日期: 2019.12
作者: 01Studio
说明:编程实现LCD显示信息。需要将01Studio.bmp文件发送到开发板。
'''

import lcd, image, utime

lcd.init()  #初始化LCD
lcd.clear(lcd.WHITE)  #清屏白色

#显示字符
lcd.draw_string(110, 120, "Hello 01Studio!", lcd.BLACK, lcd.WHITE)  #显示字符

utime.sleep(2)  #延时2秒

#显示图像,记得先将01Studio.bmp文件发送到开发板
lcd.rotation(1)  #由于图像默认是240*320,因此顺时钟旋转90°。
lcd.display(image.Image("01Studio.bmp"))
Пример #31
0
# CorgiDude GPIO | From AiDude.io, aiiotshop.com/p/58
import image, lcd, time
from Dude import dude,PORT

lcd.init()
lcd.rotation(1)

dude.BeginADC(PORT.INPUT2)
dude.BeginAHT(PORT.INPUT2)

while(True):
    img = image.Image(size=(240,240))
    #read sensor
    adc = dude.AnalogRead(PORT.INPUT2,2)
    temp,humid = dude.ReadAHT(PORT.INPUT2)

    img.draw_rectangle(0,0,240,240, fill=True, color=(int(adc/3.5*255),0,0))
    img.draw_string(5,5, "T=%2.2f" % temp,color=(0,255,0),scale=3)
    img.draw_string(5,35, "H=%2.2f" % humid,color=(0,255,0),scale=3)
    img.draw_string(5,65, "ADC=%2.2f" % adc,color=(0,255,0),scale=3)

    '''
    if dude.DigitalRead(PORT.INPUT1,4) == 1:
        img.draw_rectangle(0,0,240,240, fill=True, color=(0,0,255))
    '''
    lcd.display(img)
    time.sleep(0.1)
Пример #32
0
classes = [
    'aeroplane', 'bicycle', 'bird', 'boat', 'bottle', 'bus', 'car', 'cat',
    'chair', 'cow', 'diningtable', 'dog', 'horse', 'motorbike', 'person',
    'pottedplant', 'sheep', 'sofa', 'train', 'tvmonitor'
]
task = kpu.load(0x500000)
anchor = (1.889, 2.5245, 2.9465, 3.94056, 3.99987, 5.3658, 5.155437, 6.92275,
          6.718375, 9.01025)
a = kpu.init_yolo2(task, 0.5, 0.3, 5, anchor)
while (True):
    clock.tick()
    fps = clock.fps()
    img = sensor.snapshot()
    lcd.draw_string(2, 2, ("%2.1ffps" % (fps)), lcd.RED, lcd.WHITE)
    code = kpu.run_yolo2(task, img)
    print(clock.fps())
    if code:
        for i in code:
            if classes[i.classid()] == 'car':
                a = img.draw_rectangle(i.rect())
                a = lcd.display(img)
                for i in code:
                    lcd.draw_string(i.x(), i.y(), classes[i.classid()],
                                    lcd.RED, lcd.WHITE)
                    lcd.draw_string(i.x(),
                                    i.y() + 12, '%f1.3' % i.value(), lcd.RED,
                                    lcd.WHITE)
    else:
        a = lcd.display(img)
a = kpu.deinit(task)
sensor.set_framesize(sensor.LCD)
sensor.skip_frames(time=5000)
clock = time.clock()
lcd.init()

# Only blobs that with more pixels than "pixel_threshold" and more area than "area_threshold" are
# returned by "find_blobs" below. Change "pixels_threshold" and "area_threshold" if you change the
# camera resolution. "merge=True" merges all overlapping blobs in the image.

def map_g_to_temp(g):
    return ((g * (max_temp_in_celsius - min_temp_in_celsius)) / 255.0) + min_temp_in_celsius

while(True):
    clock.tick()
    img = sensor.snapshot()
    blob_stats = []
    blobs = img.find_blobs(threshold_list, pixels_threshold=200, area_threshold=200, merge=True)
    # Collect stats into a list of tuples
    for blob in blobs:
        blob_stats.append((blob.x(), blob.y(), map_g_to_temp(img.get_statistics(thresholds=threshold_list,
                                                                                roi=blob.rect()).mean())))
    img.to_rainbow(color_palette=sensor.PALETTE_IRONBOW) # color it
    # Draw stuff on the colored image
    for blob in blobs:
        img.draw_rectangle(blob.rect())
        img.draw_cross(blob.cx(), blob.cy())
    for blob_stat in blob_stats:
        img.draw_string(blob_stat[0], blob_stat[1] - 10, "%.2f C" % blob_stat[2], mono_space=False)
    lcd.display(img)
    print("FPS %f - Lepton Temp: %f C" % (clock.fps(), sensor.ioctl(sensor.IOCTL_LEPTON_GET_FPA_TEMPERATURE)))
Пример #34
0
def speaker(pin, melody, noteDurations):
    if melody == 0:
        tim = Timer(Timer.TIMER2, Timer.CHANNEL0, mode=Timer.MODE_PWM)
        tim.stop()
        noteDuration = int(noteDurations * 1000)
        time.sleep_ms(noteDuration)
        return

    listmelody = [
        0,
        131,
        147,
        165,
        175,
        196,
        220,
        247,  #3, 1 - 7
        262,
        294,
        330,
        349,
        392,
        440,
        494,  #4, 8 - 14
        523,
        587,
        659,
        698,
        784,
        880,
        988,  #5, 15 - 21
        139,  # C#3, 22
        156,  # Eb3, 23
        185,  # F#3, 24
        208,  # G#3, 25
        233,  # Bb3, 26
        277,  # C#4, 27
        311,  # Eb4, 28
        370,  # F#4, 29
        415,  # G#4, 30
        466,  # Bb4, 31
        555,  # C#5, 32
        622,  # Eb5, 33
        740,  # F#5, 34
        831,  # G#5, 35
        932,  # Bb5, 36
        1047,
        1175,
        1319,
        1397,
        1568,
        1760,
        1976,  #6, 37 - 43
        2093,
        2349,
        2637,
        2794,
        3136,
        3520,
        3951,  #7, 44 - 50
        1109,  # C#6, 52
        1245,  # Eb6, 53
        1480,  # F#6, 54
        1661,  # G#6, 55
        1865,  # Bb6, 56
        2217,  # C#7, 57
        2489,  # Eb6, 58
        2960,  # F#6, 59
        3322,  # G#6, 60
        3729  # Bb6, 61
    ]

    listnoteDurations = noteDurations
    # to calculate the note duration, take one second
    # divided by the note type.
    #e.g. quarter note = 1000 / 4, eighth note = 1000/8, etc.
    noteDuration = int(listnoteDurations * 1000)
    lcd.display(image.Image('music.jpg'))
    #lcd.draw_string(5, 15, 'Note is playing', lcd.RED, lcd.WHITE)
    tone(pin, listmelody[melody], noteDuration)
    lcd.display(image.Image('logo.jpg'))
Пример #35
0
                       thickness=2,
                       fill=False)

    #画圆:蓝色不填充。
    img.draw_circle(60, 120, 30, color=(0, 0, 255), thickness=2, fill=False)

    #画箭头:白色。
    img.draw_arrow(150,
                   120,
                   250,
                   120,
                   color=(255, 255, 255),
                   size=20,
                   thickness=2)

    #画十字交叉。
    img.draw_cross(60, 200, color=(255, 255, 255), size=20, thickness=2)

    #写字符。
    img.draw_string(150,
                    200,
                    "Hello 01Studio!",
                    color=(255, 255, 255),
                    scale=2,
                    mono_space=False)

    lcd.display(img)  # Display on LCD
    print(clock.fps()
          )  # Note: MaixPy's Cam runs about half as fast when connected
    # to the IDE. The FPS should increase once disconnected.
Пример #36
0
# Example 1 - LCD Shield Demo
#
# Note: To run this example you will need a LCD Shield for your OpenMV Cam.
#
# The LCD Shield allows you to view your OpenMV Cam's frame buffer on the go.

import sensor, image, lcd

sensor.reset() # Initialize the camera sensor.
sensor.set_pixformat(sensor.RGB565) # or sensor.GRAYSCALE
sensor.set_framesize(sensor.QQVGA2) # Special 128x160 framesize for LCD Shield.
lcd.init() # Initialize the lcd screen.

while(True):
    lcd.display(sensor.snapshot()) # Take a picture and display the image.
    if but_a.value() == 0 and but_a_pressed == 0:
        for i in range(768):
            master_data[i] = cap_data[i]
        but_a_pressed = 1
    if but_a.value() == 1 and but_a_pressed == 1:
        but_a_pressed = 0
    if but_b.value() == 0 and but_b_pressed == 0:
        view_mode += 1
        but_b_pressed = 1
    if but_b.value() == 1 and but_b_pressed == 1:
        but_b_pressed = 0
    lcd.draw_string(0, 0, "%.0f " % (dist), lcd.RED, lcd.BLACK)
    if view_mode == 0:
        img2 = img.resize(110, 110)
        img3 = kpu_dat.resize(110, 110)
        lcd.display(img2, oft=(0, 16))
        lcd.display(img3, oft=(130, 16))

    elif view_mode == 1:
        for row in range(32):
            for col in range(24):
                kpu_dat2[24 * row + col] = int(master_data[row * 24 + col] *
                                               100)
        img2 = kpu_dat2.resize(110, 110)
        img3 = kpu_dat.resize(110, 110)

        if dist < 200:
            img2.draw_rectangle(2, 2, 108, 108, color=(255), thickness=5)
        else:
            img2.draw_rectangle(2, 2, 108, 108, color=(100), thickness=5)
Пример #38
0
        sensor.set_vflip(1)
        sensor.run(1)
        sensor.skip_frames()

    def get_image():
        if obj.is_init == False:
            obj.init()
            obj.is_init = True
        return sensor.snapshot()


if __name__ == "__main__":

    import KPU as kpu
    import gc

    kpu.memtest()

    lcd.init(freq=15000000)

    print('ram total : ' + str(gc.mem_free() / 1024) + ' kb')
    kpu.memtest()

    clock = time.clock()
    while (True):
        clock.tick()
        lcd.display(obj.get_image())
        print(clock.fps())
        print('ram total : ' + str(gc.mem_free() / 1024) + ' kb')
        kpu.memtest()
Пример #39
0
import network, socket, time, utime, sensor, image, lcd, os
from machine import UART
from Maix import GPIO
from maix_motor import Maix_motor
from fpioa_manager import fm
import ujson

lcd.display(image.Image('logo.jpg'))
msg = 'Open Code&Robots APP, enter your WiFi credentials and scan the resulting QR code with MARK camera'
num_rows = len(msg) // 28
for i in range(num_rows + 3):
    lcd.draw_string(5, i * 15, msg[i * 28:i * 28 + 28], lcd.RED, lcd.WHITE)
time.sleep(2)

########## config ################
WIFI_SSID = 0
WIFI_PASSWD = 0
server_ip = 0
server_port = 3456
pan_angle = 90
tilt_angle = 90
bullet = 90

fm.register(25, fm.fpioa.GPIOHS25)  #cs
fm.register(8, fm.fpioa.GPIOHS8)  #rst
fm.register(9, fm.fpioa.GPIOHS9)  #rdy
print("Use hardware SPI for other maixduino")
fm.register(28, fm.fpioa.SPI1_D0, force=True)  #mosi
fm.register(26, fm.fpioa.SPI1_D1, force=True)  #miso
fm.register(27, fm.fpioa.SPI1_SCLK, force=True)  #sclk
##################################
Пример #40
0
import sensor, lcd

sensor.reset()
sensor.set_pixformat(sensor.RGB565)
sensor.set_framesize(sensor.QVGA)
sensor.run(1)
sensor.skip_frames()
lcd.init(freq=15000000)

while (True):
    #lcd.display(sensor.snapshot().invert())
    lcd.display(sensor.snapshot().invert())
Пример #41
0
#机械臂初始化指令
uart.write("M20 G90 G01 F5000\n")
uart.write("M3S0\n")
#mirobot_finish_moving()
#print('ok')

#标定
if keyvalue == 0:

    uart.write('X220Y0' + 'z' + str(high_z) + '\n')  #下降到预备位置
    #mirobot_finish_moving()
    #time.sleep(3000)
    img.draw_string(10, 110, "put,and key")  #提示放物块
    img = sensor.snapshot()
    lcd.display(img)  # lcd显示
    keytime = 0
    while 1:
        while Key.value() == 0:
            keytime += 1
            time.sleep(1)
        if keytime > 8000:
            print('rst')
            #重启
            break
        elif keytime > 1000:
            #校准相对位置
            while 1:
                find = 0
                img = sensor.snapshot()
                for blob in img.find_blobs(thresholds,
    clock.tick()
    img = sensor.snapshot()
    blob = img.find_blobs([thresholds[threshold_index]], area_threshold=300)
    if blob: #如果找到了目标颜色
        uart.write("6")
        TEXT1 = 1
        TS = TEXT1
        for b in blob:
            #迭代找到的目标颜色区域
            img.draw_rectangle(b[0:4]) # rect
            img.draw_cross(b[5], b[6]) # cx, cy
    if TEXT1 == 3:
        img.draw_string(120, 100, "NO MASK!!!!")
        img.draw_string(120, 115, "WEAR MASK!!!")
        uart.write("5")
        lcd.display(img)
    lcd.display(img)

    if uart.any():
        c=uart.readline()
        print(c[0])

    #c= '1'
    if c[0]== 49:
        print("gh")
        led1.on()
        y.start_face_rendering()
        sensor.reset()
        sensor.set_pixformat(sensor.RGB565)
        sensor.set_framesize(sensor.QVGA)
    if c[0]== 50:
Пример #43
0
btnA_status = 1
btnB_status = 1

lcd.init()
lcd.rotation(2)  #Rotate the lcd 180deg
lcd.draw_string(5, 5, "K210 VGA image auto save v1.1", lcd.GREEN, lcd.BLACK)
Zeit_base = time.ticks_ms()

try:
    while (condition):
        clock.tick()  # Update the FPS clock.
        #Zeit_jetzt=time.ticks_ms()      # get millisecond counter
        img = sensor.snapshot()  # Take a picture and return the image.
        img_s = img.resize(240, 180)
        lcd.display(img_s)

        if but_a.value() == 0 and btnA_status == 1:
            if led_w.value() == 1:
                led_w.value(0)
                auto_save = True
                lcd.draw_string(5, 5, "Auto save enabled!", lcd.RED, lcd.BLACK)
            else:
                led_w.value(1)
                auto_save = False
                lcd.draw_string(5, 5, "Auto save disabled!", lcd.ORANGE,
                                lcd.BLACK)

            btnA_status = 0
        if but_a.value() == 1 and btnA_status == 0:
            btnA_status = 1
Пример #44
0
def run():
    while 1:
        img = sensor.snapshot()
        lcd.display(img)
        pass
Пример #45
0
time.sleep(1)

count = 0
while (corgi85.wifi_check() == 0):
    print("WIFI Connecting")
    time.sleep(1)

print("\n\nWIFI Connected")

print("\n\nSet line Token:", token)
corgi85.LINE_setToken(token)  #set line Token

print("\n\nsend line image")
img = sensor.snapshot()  # camera capture image
lcd.display(img)  # lcd  display image
corgi85.LINE_notifyPicture(
    img, "CorgiDude LINE notify Picture")  # send image to line noti
time.sleep(3)

print("\n\nsend message to line noti: Hello From CorgiDude")
corgi85.LINE_notify("Hello From CorgiDude")
time.sleep(3)

print("\n\nsend line sticker")
corgi85.LINE_notifySticker(
    1, 1)  # detail : https://devdocs.line.me/files/sticker_list.pdf
time.sleep(3)

print("\n\nsend line sticker & message")
corgi85.LINE_notifySticker_text(
Пример #46
0
def inner_loop():
    global SHOTS
    lcd.clear()

    lcd.display(2, "", 1)
    lcd.display(3, "TAP TO SHOOT", 2)
    lcd.display(4, "ready", 1)
    print "Starting inner foot pedal loop..."
    start = time()
    prev_input = 0
    firstloop = 1
    while True:
        input = GPIO.input(PIN)
        if ((not prev_input) and input):
            if (firstloop != 1):
                print("Button pressed")
                shoot()
                SHOTS += 1
                lcd.display(2, str(SHOTS / 2), 1)
                start = time()
            firstloop = 0
        prev_input = input
        #slight pause to debounce
        sleep(DEBOUNCEPAUSE)

        # check that a camera hasn't turned off
        # can we do this more quickly?  it's interfering with the pedal.
        #cmdoutput("lsusb | grep Canon | wc -l") == "2"                                      # 1.16 sec
        #cmdoutput(PTPCAM + " -l | grep 0x | wc -l") == "2"                                  # 0.42 sec
        #cmdoutput("gphoto2 --auto-detect|grep usb|sed -e 's/.*Camera *//g' | wc -l") == "2" # 0.36 sec
        #cmdoutput("gphoto2 --auto-detect | grep Camera | wc -l") == "2"                     # 0.34 sec, still too long
        if camera_count(BRAND) == 2:                                       # 0.58 sec from command line, faster inside the program? yes!
            pass
        else:
            print "Number of camera devices does not equal 2. Try again."
            for cam in LEFTCAM, RIGHTCAM:
                cmd=PTPCAM + " --dev=" + cam + " --chdk='lua play_sound(3)'"
                p = Popen(cmd, shell=True, stdout=PIPE, stderr=PIPE)
            lcd.display(2, "A CAMERA IS OFF.", 1)
            lcd.display(3, "RESTARTING...", 1)
            lcd.display(4, "", 1)
            sleep(PAUSE)
            return

        now = time()
        if now - start > TMOUT:
            lcd.display(2, "", 1)
            lcd.display(3, "TIMEOUT", 2)
            lcd.display(4, "", 1)
            print "Foot pedal not pressed for", TMOUT, "seconds."
            download_from_cams()
            delete_from_cams()
            print "Quitting inner loop"
            return
        text = marquee.next()
        lcd.display(1, text, 1)
Пример #47
0
                a = img.draw_string(50,
                                    180,
                                    "Not registered!",
                                    color=(255, 0, 0),
                                    scale=3)
            if start_processing:  # 如果检测到按键
                print("key_pressed")
                record_ftr = feature
                record_ftrs.append(record_ftr)
                print(feature)
                with open("ftrs.txt", 'a') as f:
                    f.write(feature + '\n|||||\n')
                record_names.append("NA")
                with open("names.txt", 'a') as f:
                    f.write("NA\n")
                start_processing = False
                fpath = "image/" + str(len(record_names)) + ".jpg"
                img_face.save(fpath)  # 将人脸照片保存到sd卡

            break

    fps = clock.fps()  #计算帧率
    #print("%2.1f fps"%fps) #打印帧率
    a = lcd.display(img)  #刷屏显示
    gc.collect()
    # kpu.memtest()

#kpu.deinit(task_fe)
#kpu.deinit(task_ld)
#kpu.deinit(task_fd)
Пример #48
0
def detect_cams():
    lcd.display(4, "detecting cameras...", 1)
    global LEFTCAM, RIGHTCAM, LEFTCAMLONG, RIGHTCAMLONG, GPHOTOCAM1, GPHOTOCAM2
    #CAMS = cmdoutput("gphoto2 --auto-detect|grep usb| wc -l")
    CAMS = camera_count(BRAND)
    if CAMS == 2:
        GPHOTOCAM1 = cmdoutput("gphoto2 --auto-detect|grep usb|sed -e 's/.*Camera *//g'|head -n1")
        GPHOTOCAM2 = cmdoutput("gphoto2 --auto-detect|grep usb|sed -e 's/.*Camera *//g'|tail -n1")
        print GPHOTOCAM1, "is gphotocam1"
        print GPHOTOCAM2, "is gphotocam2"
    
        GPHOTOCAM1ORIENTATION=cmdoutput("gphoto2 --port " + GPHOTOCAM1 + " --get-config /main/settings/ownername|grep Current|sed -e's/.*\ //'")
        GPHOTOCAM2ORIENTATION=cmdoutput("gphoto2 --port " + GPHOTOCAM2 + " --get-config /main/settings/ownername|grep Current|sed -e's/.*\ //'")
        print "gphotocam1orientation is", GPHOTOCAM1ORIENTATION
        print "gphotocam2orientation is", GPHOTOCAM2ORIENTATION

        CAM1=cmdoutput("echo " + GPHOTOCAM1 + "|sed -e 's/.*,//g'")
        CAM2=cmdoutput("echo " + GPHOTOCAM2 + "|sed -e 's/.*,//g'")
        print "Detected 2 camera devices:", GPHOTOCAM1, "and", GPHOTOCAM2
    else: 
        print "Number of camera devices does not equal 2. Giving up."
        lcd.display(4, "", 1)
        lcd.display(2, "CAMERAS OFF.", 1)
        lcd.display(3, "RESTARTING...", 1)
        sleep(PAUSE)
        restart_program()

    if GPHOTOCAM1ORIENTATION == "left":
        LEFTCAM=cmdoutput("echo " + GPHOTOCAM1 + "|sed -e 's/.*,//g'")
        LEFTCAMLONG=GPHOTOCAM1
    elif GPHOTOCAM1ORIENTATION == "right":
        RIGHTCAM=cmdoutput("echo " + GPHOTOCAM1 + "|sed -e 's/.*,//g'")
        RIGHTCAMLONG=GPHOTOCAM1
    else:
        lcd.display(2, "OWNER NAME NOT SET.", 1)
        lcd.display(3, "RESTARTING...", 1)
        sleep(PAUSE)
        print GPHOTOCAM1, "owner name is neither set to left or right. Please configure that before continuing."
        restart_program()

    if GPHOTOCAM2ORIENTATION == "left":
        LEFTCAM=cmdoutput("echo " + GPHOTOCAM2 + "|sed -e 's/.*,//g'")
        LEFTCAMLONG=GPHOTOCAM2
    elif GPHOTOCAM2ORIENTATION == "right":
        RIGHTCAM=cmdoutput("echo " + GPHOTOCAM2 + "| sed -e 's/.*,//g'")
        RIGHTCAMLONG=GPHOTOCAM2
    else:
        lcd.display(2, "OWNER NAME NOT SET.", 1)
        lcd.display(3, "RESTARTING...", 1)
        sleep(PAUSE)
        print GPHOTOCAM1, "owner name is neither set to left or right. Please configure that before continuing."
        restart_program()
Пример #49
0
sensor.reset()
sensor.set_pixformat(sensor.RGB565)
sensor.set_framesize(sensor.QVGA)
sensor.run(1)

path = "save/"
ext=".jpg"
cnt=0
img_read = image.Image()

#os.mkdir("save")
print(os.listdir())

while True:
    if is_button_b == 1:
        lcd.display(img_read)

    else :
        img=sensor.snapshot()
        lcd.display(img)

    if but_a.value() == 0 and is_button_a == 0:
        print("save image")
        cnt+=1
        fname=path+str(cnt)+ext
        print(fname)
        img.save(fname, quality=95)
        is_button_a=1

    if but_a.value() == 1 and is_button_a == 1:
        is_button_a=0