示例#1
0
def camp():
    # send 3d set to compute - without display
    #num = request.args.get('number')
    send_start()
    camera = init_camera()
    camera.resolution =(160,160)
    #camera.framerate_range =(10,10)
    cam_settings = CameraSettings(camera)
    init_3d_camera(cam_settings)
    size = request.args.get('size', None)
    if size:
        camera.resolution =(int(size),int(size))
    set_dias(False)
    set_flash(FLASH_LEVEL)
    warm_up()
    fd1 = BytesIO()
    camera.capture(fd1, format='jpeg', use_video_port=True, quality=JPEG_QUALITY)
    fd1.truncate()
    fd1.seek(0)
    (fd2, fd3) = get_picture_set(camera)
    send_picture([fd1,fd2,fd3], 1)
    camera.close()
    led_off()
    send_stop()
    res = { "device": DEVICEID }
    return res
示例#2
0
def get_picture_set(camera):
    # used by /3d
    if _DEBUG:
        print ("Flash", get_exposure_info(camera))
    set_flash(False)
    set_dias(DIAS_LEVEL)
    fd2 = BytesIO()
    sleep(CAPTURE_DELAY)
    if _DEBUG:
        print ("Dias", get_exposure_info(camera))
    camera.capture(fd2, format='jpeg', use_video_port=True, quality=JPEG_QUALITY)
    fd2.truncate()
    fd2.seek(0)
    fix_exposure(camera)
    set_dias(False)
    sleep(CAPTURE_DELAY)
    if _DEBUG:
        print ("Dark", get_exposure_info(camera))
    fd3 = BytesIO()
    camera.capture(fd3, format='jpeg', use_video_port=True, quality=JPEG_QUALITY)
    fd3.truncate()
    fd3.seek(0)
    auto_exposure(camera)
    #set_flash(FLASH_LEVEL)
    return (fd2, fd3)
示例#3
0
def get_pictures(camera, no_pictures=NUMBER_PICTURES, picture_interval=PICTURE_INTERVAL):
    # return a picture for MPEG and send Captured Images to  compute server
    # used by /3d
    fd1 = BytesIO()
    i=1
    pic_no = 1
    start = datetime.now()
    if picture_interval==0:
        pic_modolu=1
    else:
        pic_modolu = int(picture_interval*10)
    if _DEBUG:
        print("pic_modulo", pic_modolu)
    try:
        while True:
            camera.capture(fd1, format='jpeg', use_video_port=True, quality=JPEG_QUALITY)
            fd1.truncate()
            fd1.seek(0)
            pic = fd1.read()
            yield (b'--frame\r\n'
                b'Content-Type: image/jpeg\r\n\r\n' + pic + b'\r\n')
            fd1.seek(0)
            if i % pic_modolu == 0:
                if _TIMING:
                    time_start = perf_counter()
                start = datetime.now()
                #set_flash(FLASH_LEVEL)
                #sleep(CAPTURE_DELAY)
                fdlist = get_picture_infoset(camera)
                if _TIMING:
                    time_info = perf_counter()
                    print(f" get_picture_infoset time {(time_info-time_start)}")
                fd1.seek(0)
                fdlist.append(['color.jpg', fd1])
                post_file_objects_bg("scan3d", fdlist, post_data={'pictureno': pic_no})
                if _TIMING:
                    time_post = perf_counter()
                    print(f" post files time {(time_post-time_info)}")
                fd1.seek(0)
                pic_no = pic_no+1
                if pic_no>no_pictures:
                    break
                set_flash(FLASH_LEVEL)
                sto = datetime.now()
                if _DEBUG:
                    print (" Pictureset time", sto-start)
                if _TIMING:
                    time_end = perf_counter()
                    print(f"Loop time {(time_end-time_start)}")
            i=i+1
    finally:
        stop = datetime.now()
        if _DEBUG:
            print(f"Closing: {i/((stop-start).total_seconds()):2.1f} Billeder/sek")
        camera.close()
        led_off()
        send_stop()
示例#4
0
def get_test_pictures(camera, mode="comp"):
    # return a picture for MPEG and send Captured Images to  compute server
    # but changing exposure
    fd1 = BytesIO()
    i=1
    pic_no = 1
    if mode=="comp":
        compensation = -15
    if mode=="zoom":
        zoom = 0.2
    start = datetime.now()
    if PICTURE_INTERVAL==0:
        pic_modolu=1
    else:
        pic_modolu = int(PICTURE_INTERVAL*10)
    if _DEBUG:
        print("pic_modulo", pic_modolu)
    try:
        while True:
            sleep(CAPTURE_DELAY)
            camera.capture(fd1, format='jpeg', use_video_port=True, quality=JPEG_QUALITY)
            fd1.truncate()
            fd1.seek(0)
            pic = fd1.read()
            yield (b'--frame\r\n'
                b'Content-Type: image/jpeg\r\n\r\n' + pic + b'\r\n')
            fd1.seek(0)
            if i % pic_modolu == 0:
                set_flash(FLASH_LEVEL)
                sleep(CAPTURE_DELAY)
                fdlist = get_picture_infoset(camera)
                fd1.seek(0)
                fdlist.append(['color.jpg', fd1])
                #print(fdlist)
                post_file_objects("scan3d", fdlist, post_data={'pictureno': pic_no})
                fd1.seek(0)
                pic_no = pic_no+1
                if mode=='comp':
                    compensation = compensation+1
                    camera.exposure_compensation = compensation
                if mode=='zoom':
                    zoom = zoom + 0.05
                    rec = myzoom(zoom)
                    camera.zoom = rec
                if pic_no>20:
                    break
                set_flash(FLASH_LEVEL)
            i=i+1
            #sleep(0)
    finally:
        stop = datetime.now()
        if _DEBUG:
            print(f"Closing: {i/((stop-start).total_seconds()):2.1f} Billeder/sek")
        camera.close()
        led_off()
        send_stop()
示例#5
0
def cam():
    set_flash(FLASH_LEVEL)
    send_api_request("start2d", url=COMPUTE_SERVER)
    camera = init_camera()
    camera.resolution = (640, 480)
    #camera.framerate_range =(10,25)
    size = request.args.get('size', None)
    if size:
        camera.resolution = (int(size), int(size))
    warm_up()
    return Response(get_pictures(camera),
                    mimetype='multipart/x-mixed-replace; boundary=frame')
示例#6
0
def light():
    dias = get_dias()
    flash = get_flash()
    if request.method == 'POST':
        print(request.form)
        dias = float(request.form['dias'])
        flash = float(request.form['flash'])
        set_dias(dias)
        set_flash(flash)
    return render_template('light.html',
                           header="Light",
                           dias=dias,
                           flash=flash)
示例#7
0
def test():
    mycamera = init_camera()
    mycamera.resolution = (640, 480)
    warm_up()
    settings = CameraSettings(mycamera)
    dias = None
    flash = None
    if request.method == 'POST':
        print(request.form)
        settings.contrast = int(request.form['contrast'])
        settings.brightness = int(request.form['brightness'])
        settings.saturation = int(request.form['saturation'])
        settings.iso = int(request.form['iso'])
        settings.exposure_compensation = int(
            request.form['exposure_compensation'])
        settings.exposure_mode = request.form['exposure_mode']
        settings.awb_mode = request.form['awb_mode']
        settings.sharpness = int(request.form['sharpness'])
        settings.meter_mode = request.form['meter_mode']
        settings.drc_strength = request.form['drc_strength']
        settings.resolution = request.form['resolution']
        settings.shutter_speed = int(request.form['shutter_speed']) * 1000
        dias = request.form.get('dias')
        flash = request.form.get('flash')
    #print ("Flash", flash)
    #print ("Dias", dias)
    fd = capture_picture(mycamera)
    exposure1 = Markup(
        get_exposure_info(mycamera) + "<br>" + get_white_balance(mycamera))
    img1 = base64.b64encode(fd.getvalue()).decode()
    settings.set()
    mysettings = "Camera: " + settings.str()
    if flash:
        set_flash(True)
    if dias:
        set_dias(True)
    warm_up()
    fd2 = capture_picture(mycamera)
    exposure2 = Markup(
        get_exposure_info(mycamera) + "<br>" + get_white_balance(mycamera) +
        " " + mysettings)
    img2 = base64.b64encode(fd2.getvalue()).decode()
    mycamera.close()
    set_flash(False)
    set_dias(False)
    return render_template('calibrate.html',
                           header="Calibrate",
                           img1=img1,
                           img2=img2,
                           exposure1=exposure1,
                           exposure2=exposure2)
示例#8
0
def test():
    server_up = send_start()
    if not server_up:
        return '{"result": 0, "reason": "no connection to compute server"}'
    camera = init_camera()
    camera.resolution =(160,160)
    camera.framerate_range =(10,10)
    cam_settings = CameraSettings(camera)
    mode = ''
    mode = request.args.get('mode', None)
    init_3d_camera(cam_settings)
    # start
    set_dias(False)
    set_flash(FLASH_LEVEL)
    warm_up()
    return Response(get_test_pictures(camera, mode=mode),mimetype='multipart/x-mixed-replace; boundary=frame')
示例#9
0
def get_pictures(camera):
    number_pictures = NUMBER_PICTURES
    fd1 = BytesIO()
    i = 1
    pic_no = 1
    #sleep(CAPTURE_DELAY)
    start = datetime.now()
    if PICTURE_INTERVAL == 0:
        pic_modolu = 1
    else:
        pic_modolu = int(PICTURE_INTERVAL * 10)
    if _DEBUG:
        print("pic modolu", pic_modolu)
    try:
        while True:
            camera.capture(fd1, format='jpeg', use_video_port=True)
            fd1.truncate()
            fd1.seek(0)
            pic = fd1.read()
            yield (b'--frame\r\n'
                   b'Content-Type: image/jpeg\r\n\r\n' + pic + b'\r\n')
            fd1.seek(0)
            if i % pic_modolu == 0:
                #send_api_request_bg('save2d', url=COMPUTE_SERVER)
                params = {'pictureno': pic_no}
                post_file_object("save2d", fd1, post_data=params)
                #send_picture(fd1, pic_no)
                fd1.seek(0)
                pic_no = pic_no + 1
            i = i + 1
            if pic_no > number_pictures:
                break
            sleep(0)
    finally:
        stop = datetime.now()
        print(
            f"Vi lukker og slukker {i/((stop-start).total_seconds()):2.1f} Billeder/sek"
        )
        print(get_exposure_info(camera))
        camera.close()
        set_flash(False)
        send_api_request('stop2d', url=COMPUTE_SERVER)
示例#10
0
def get_picture_infoset(camera):
    # get picture and exposure info
    # used by /3d
    st1 = perf_counter()
    if TESTINFO:
        flash_exp = get_exposure_info_dict(camera)
    if _DEBUG:
        print ("Flash", get_exposure_info(camera))
    set_flash(False)
    set_dias(DIAS_LEVEL)
    fd2 = BytesIO()
    sleep(CAPTURE_DELAY)
    if TESTINFO:
        dias_exp = get_exposure_info_dict(camera)
    if _DEBUG:
        print ("Dias", get_exposure_info(camera))
    camera.capture(fd2, format='jpeg', use_video_port=True, quality=JPEG_QUALITY)
    fd2.truncate()
    fd2.seek(0)
    fix_exposure(camera)
    set_dias(False)
    sleep(CAPTURE_DELAY)
    if TESTINFO:
        dark_exp = get_exposure_info_dict(camera)
    if _DEBUG:
        print ("Dark", get_exposure_info(camera))
    fd3 = BytesIO()
    camera.capture(fd3, format='jpeg', use_video_port=True, quality=JPEG_QUALITY)
    fd3.truncate()
    fd3.seek(0)
    auto_exposure(camera)
    if TESTINFO:
        info = { "color": flash_exp, "dias": dias_exp, "nolight": dark_exp }
        #print(info)
        fdinfo = StringIO(json.dumps(info, indent=4))
        fileobj = [ ("dias.jpg",fd2),("nolight.jpg", fd3),("pict_info.json", fdinfo)]
    else:
        fileobj = [ ("dias.jpg",fd2),("nolight.jpg", fd3)]
    end = perf_counter()
    if _TIMING:
        print(f"Get_picture_infoset { end-st1 }")
    return fileobj
示例#11
0
def cam():
    # send 3d set to compute
    no_pictures = request.args.get('no_pictures', NUMBER_PICTURES, type=int)
    picture_interval = request.args.get('picture_interval', PICTURE_INTERVAL, type=float)
    server_up = send_start()
    if not server_up:
        return '{"result": 0, "reason": "no connection to compute server"}'
    camera = init_camera()
    camera.resolution =(160,160)
    camera.framerate_range =(10,10)
    cam_settings = CameraSettings(camera)
    init_3d_camera(cam_settings)
    size = request.args.get('size', None)
    if size:
        camera.resolution =(int(size),int(size))
    # start
    set_dias(False)
    set_flash(FLASH_LEVEL)
    warm_up()
    return Response(get_pictures(camera, no_pictures=no_pictures, picture_interval=picture_interval),mimetype='multipart/x-mixed-replace; boundary=frame')
示例#12
0
def cam3dias():
    # send a serie of pictures
    send_start()
    camera = init_camera()
    camera.resolution =(160,160)
    camera.framerate_range =(10,10)
    cam_settings = CameraSettings(camera)
    init_3d_camera(cam_settings)
    size = request.args.get('size', None)
    if size:
        camera.resolution =(int(size),int(size))
    print (get_exposure_info(camera))
    set_dias(False)
    set_flash(True)
    print (get_exposure_info(camera))
    warm_up()
    print (get_exposure_info(camera))
    warm_up()
    print (get_exposure_info(camera))
    warm_up()
    print (get_exposure_info(camera))

    return Response(get_dias(camera, 10),mimetype='multipart/x-mixed-replace; boundary=frame')
示例#13
0
def camera():
    sleeptime = 1.5
    os.makedirs("/tmp/calib", mode=0o777, exist_ok=True)
    mycamera = init_camera()
    #mycamera.resolution =(2592,1944)
    set_dias(0)
    set_flash(0)
    warm_up()
    if _DEBUG:
        print(get_camera_settings(mycamera))
    #normal
    mycamera.capture('/tmp/calib/color.png', use_video_port=False)
    if _DEBUG:
        print("Color", get_exposure_info(mycamera))
    mycamera.capture('/tmp/calib/color.jpg', use_video_port=False)
    write_picture_info("/tmp/calib/color.json",
                       get_picture_info_json(mycamera))
    #dias
    set_dias(1)
    sleep(sleeptime)
    mycamera.capture('/tmp/calib/dias.png', use_video_port=False)
    if _DEBUG:
        print("Dias:", get_exposure_info(mycamera))
    mycamera.capture('/tmp/calib/dias.jpg', use_video_port=False)
    write_picture_info("/tmp/calib/dias.json", get_picture_info_json(mycamera))
    #full flash
    set_dias(0)
    set_flash(1)
    sleep(sleeptime)
    mycamera.capture('/tmp/calib/flash.png', use_video_port=False)
    if _DEBUG:
        print("Flash", get_exposure_info(mycamera))
    mycamera.capture('/tmp/calib/flash.jpg', use_video_port=False)
    write_picture_info("/tmp/calib/flash.json",
                       get_picture_info_json(mycamera))
    fix_exposure(mycamera)
    #dark
    set_flash(0)
    sleep(sleeptime)
    mycamera.capture('/tmp/calib/nolight.png', use_video_port=False)
    if _DEBUG:
        print("NoLight", get_exposure_info(mycamera))
    mycamera.capture('/tmp/calib/nolight.jpg', use_video_port=False)
    write_picture_info("/tmp/calib/nolight.json",
                       get_picture_info_json(mycamera))
    auto_exposure(mycamera)
    #low flash
    set_dias(0)
    set_flash(0.1)
    sleep(sleeptime)
    mycamera.capture('/tmp/calib/flash01.png', use_video_port=False)
    if _DEBUG:
        print("Flash01", get_exposure_info(mycamera))
    mycamera.capture('/tmp/calib/flash01.jpg', use_video_port=False)
    write_picture_info("/tmp/calib/flash01.json",
                       get_picture_info_json(mycamera))
    fix_exposure(mycamera)
    set_flash(0)
    sleep(sleeptime)
    mycamera.capture('/tmp/calib/nolight01.png', use_video_port=False)
    mycamera.close()
    filelist = [
        '/tmp/calib/color.png',
        '/tmp/calib/color.jpg',
        '/tmp/calib/color.json',
        '/tmp/calib/dias.png',
        '/tmp/calib/dias.jpg',
        '/tmp/calib/dias.json',
        '/tmp/calib/flash.png',
        '/tmp/calib/flash.jpg',
        '/tmp/calib/flash.json',
        '/tmp/calib/nolight.png',
        '/tmp/calib/nolight.jpg',
        '/tmp/calib/nolight.json',
        '/tmp/calib/flash01.png',
        '/tmp/calib/flash01.jpg',
        '/tmp/calib/flash01.json',
        #'/tmp/calib/nolight01.png', '/tmp/calib/nolight01.jpg', '/tmp/calib/nolight01.json'
    ]
    res = send_files(filelist,
                     post_data={
                         "cmd": "calcamera",
                         "sice": 160,
                         "zoom": ZOOM
                     })
    if res:
        return res
    print("det gik skidt", res)
    return '{ "result": "false"}'
示例#14
0
def led_off():
    set_flash(0)
    set_dias(0)
示例#15
0
def get_set_led():
    dias = float(request.args.get('dias', 0))
    set_dias(dias)
    flash = float(request.args.get('flash', 0))
    set_flash(flash)
    return "dias=" + str(dias) + "&flash=" + str(flash)
示例#16
0
#from calibrate.cal_flash import calibrate_flash

print("Loading Webservice " + VERSION)
app = Flask(__name__)
app.debug = True
app.register_blueprint(pic)
app.register_blueprint(pic2d)
app.register_blueprint(pic3d)
app.register_blueprint(calibrate)
#app.register_blueprint(calibrate_flash)

app.secret_key = b'_5#y2xyzQ8z\n\xec]/'

# initialization
print("Test LED")
set_flash(1)
set_dias(1)
set_dias(0)
set_flash(0)

@app.route('/')
def home1():
    return render_template('index.html')

@app.route('/version')
def version():
    return "Webservice " + VERSION

if __name__ == '__main__':
    print("Script server running version "+ VERSION)
    #app = Flask(__name__)