Exemplo n.º 1
0
def change_camera_state():
    global message
    global FLAG
    global HOST
    global PORT

    print(request.form)
    print(request.form.to_dict(flat=False))
    message = request.form.to_dict(flat=False)

    message["host"] = HOST
    message["port"] = PORT

    try:
        if request.method == 'POST':
            #return request.form['test']
            print(message['camera_state'])
            if message['camera_state'] == [u'Start_recording']:
                message['camera_state'] = 'Rec'.decode('utf-8')
                Camera().change_flag(1)

                message['velo'] = scaner_cap.data_get()

            if message['camera_state'] == [u'End_of_recording']:
                message['camera_state'] = 'Rec start'.decode('utf-8')
                FLAG = 0
                #thread_1.end()
                Camera().change_flag(3)

            print(message)
            return render_template('index.html', message=message)

    except Exception as e:
        return str(e)
Exemplo n.º 2
0
def video_feed():
    print('i am called')
    #source="rtmp://localhost:1935/live/film"

    camera=Camera()
    tmp = Tmp.query.filter_by(user_id=current_user.id).first()
    camera.set_video_source(tmp.rtmpaddr)
    return Response(gen(camera),
                    mimetype='multipart/x-mixed-replace; boundary=frame')
def video_feed():
    """Video streaming route. Put this in the src attribute of an img tag."""

    gen_obj = gen(Camera())
    print("gen_obj")
    print(gen_obj)
    #print(gen_obj.next())
    return Response(gen(Camera()),
                    mimetype='multipart/x-mixed-replace; boundary=frame')
Exemplo n.º 4
0
def video_feed():
    """Video streaming route. Put this in the src attribute of an img tag."""
    global Camera
    Camera1 = Camera(1)
    print("set source cam1")
    return Response(gen(Camera1),
                    mimetype='multipart/x-mixed-replace; boundary=frame')
def stream_view():
    global message
    global ID

    Camera().change_flag(1)

    message['datetime_now'] = datetime.datetime.now()
    message['datetime_now_str'] = message['datetime_now'].strftime(
        "%Y-%m-%d %H:%M:%S")
    message['ID'] = message['datetime_now'].strftime("%Y%m%d%H%M%S")

    sql = "INSERT INTO `hazard_list`(`sub`, `DATE`, `hazard_type`) VALUES ('1000', '" + message[
        'datetime_now_str'] + "', 1)"
    print(sql)
    mysql.indi_regist(sql)

    sql = 'SELECT * FROM `hazard_list` WHERE `sub` = ' + str(
        1000) + " AND `DATE` = '" + message['datetime_now_str'] + "'"
    print(sql)
    select_ID = mysql.sql_excute_fetch(sql)
    print(select_ID[0])
    print(select_ID[0]['id'])
    ID = select_ID[0]['id']
    rows = generate()

    return Response(
        stream_with_context(stream_template('index.html', rows=rows)))
def rec_stop():
    print("==========\nrec_stop\n==========")
    global ID
    global message

    message['id'] = ID
    Camera().change_flag(3)
    print(message)
    if (ID > 0):
        message['output_path'] = output_folder + str(ID) + ".avi"

        #output_path = output_folder + str(ID) + ".avi"
        print("shutil.move")
        new_path = shutil.copy2('output3.avi', message['output_path'])
        print(message)

        sql = "UPDATE `Drive_recorder2` SET `full_path` = '{0}' WHERE `hazard_list_id`= {1}".format(
            message['output_path'], ID)
        print(sql)
        mysql.indi_regist(sql)
        sql = "UPDATE `hazard_list` SET `full_path` = '{0}' WHERE `id`= {1}".format(
            message['output_path'], ID)
        print(sql)
        mysql.indi_regist(sql)

        #img_output_folder = output_folder + str(ID) + "/"
        message['img_output_folder'] = output_folder + str(ID) + "/"
        print("module.video_2_frames(message, 'img_%s.png', mysql)")
        module.video_2_frames(message, 'img_%s.png', mysql)
        module.SemanticSeg_client(message['id'])

    return render_template('index.html')
Exemplo n.º 7
0
def video_feed():
    """Video streaming route. Put this in the src attribute of an img tag."""
    global p
    print('Terminating {} {}'.format(p.name, p.pid))
    p.terminate()
    p.join()
    return Response(gen(Camera()),
                    mimetype='multipart/x-mixed-replace; boundary=frame')
Exemplo n.º 8
0
def image():
    height = request.args.get('height')
    width = request.args.get('width')
    cam = Camera()
    cam.set_video_height(int(height))
    cam.set_video_width(int(width))
    """Returns a single current image for the webcam"""
    return Response(gen2(cam, height, width), mimetype='image/jpeg')
Exemplo n.º 9
0
    if data['image'] and len(data['image']) > 0:
        image = decode_image(data['image'])
        processed = process_image(image)

        encodings = get_encodings(processed)

        if len(encodings) > 0:
            encoded = encode_encoding(encodings[0])
            return jsonify({
                'success': 'true',
                'message': 'generated encoding',
                'encoding': encoded
            })

    return jsonify({'success': 'false', 'message': 'Ivalid data!'})


def update_faces():
    threading.Timer(5.0, update_faces).start()
    user_data = get_user_data()
    Storage.set_encodings(user_data['encodings'])
    Storage.set_names(user_data['names'])
    print('updated')


if __name__ == '__main__':
    update_faces()
    gen(Camera())

    app.run(host='localhost', threaded=True)
Exemplo n.º 10
0
#!/usr/bin/env python
from importlib import import_module
import os
from flask import Flask, render_template, Response

# import camera driver
if os.environ.get('CAMERA'):
    Camera = import_module('camera_' + os.environ['CAMERA']).Camera
else:
    # from camera import Camera
    # Raspberry Pi camera module (requires picamera package)
    from camera_opencv import Camera
    # from camera_pi import Camera

app = Flask(__name__)
appCam = Camera()


@app.route('/')
def index():
    """Video streaming home page."""
    return render_template('index.html')


def gen(camera):
    """Video streaming generator function."""
    while True:
        frame = camera.get_frame()
        yield (b'--frame\r\n'
               b'Content-Type: image/jpeg\r\n\r\n' + frame + b'\r\n')
Exemplo n.º 11
0
#!/usr/bin/env python
from importlib import import_module
import os
from flask import Flask, render_template, Response
import camera_opencv
import camera_opencv_2
from camera_opencv import Camera
from camera_opencv_2 import Camera2
import cv2
import numpy as np
from time import sleep
# from camera_pi import Camera

app = Flask(__name__)
camera1 = Camera()
sleep(.2)
camera2 = Camera2()
sleep(.2)


@app.route('/')
def index():
    """Video streaming home page."""
    return render_template('index.html')


@app.route('/getmethod/<jsdata>')
def save_frame_1(jsdata):
    cv2.imwrite("./frames/" + str(jsdata) + ".png", camera1.current_frame)
    return jsdata
Exemplo n.º 12
0
#!/usr/bin/env python
from flask import Flask, render_template, Response

# import camera driver
from camera_opencv import Camera

app = Flask(__name__)
cam = Camera()


@app.route('/')
def index():
    """Video streaming home page."""
    return render_template('index.html')


def gen(camera):
    """Video streaming generator function."""
    while True:
        frame = camera.get_frame()
        yield (b'--frame\r\n'
               b'Content-Type: image/jpeg\r\n\r\n' + frame + b'\r\n')


@app.route('/video_feed')
def video_feed():
    """Video streaming route. Put this in the src attribute of an img tag."""
    return Response(gen(cam),
                    mimetype='multipart/x-mixed-replace; boundary=frame')

def video_feed():
    """Video streaming route. Put this in the src attribute of an img tag."""
    # if request.url_rule == '/video_feed' and request.url_rule == '/start' :
    return Response(gen(Camera()),
                    mimetype='multipart/x-mixed-replace; boundary=frame')
Exemplo n.º 14
0
    while True:
        frame = camera.get_frame()
        image = segnet.segment(frame)
        yield (b'--frame\r\n'+b'Content-Type: image/jpeg\r\n\r\n' + image + b'\r\n')

@app.route('/video_feed')
def video_feed():
    return Response(gen(Camera()), mimetype='multipart/x-mixed-replace; boundary=frame')

parser = argparse.ArgumentParser(formatter_class=argparse.ArgumentDefaultsHelpFormatter)
parser.add_argument('--model', help='File path of .tflite file.', required=True)
parser.add_argument('--labels', help='File path of labels file.', required=True)
parser.add_argument('--overlay', help='Overlay original image.', default=True)
parser.add_argument('--source', help='picamera or cv', default='cv')
args = parser.parse_args()

if args.source == "cv":
    from camera_opencv import Camera
    source = 0
elif args.source == "picamera":
    from camera_pi import Camera
    source = 0
    
Camera.set_video_source(source)

segnet = Segnet(args.labels, args.model, args.overlay)

if __name__ == "__main__" :
   app.run(host = '0.0.0.0', port = 5000, debug = True)
    
Exemplo n.º 15
0
def monitorDataGreenhouse():
    return Response(gen(Camera()),
                    mimetype='multipart/x-mixed-replace; boundary=frame')
Exemplo n.º 16
0
from flask import Flask, render_template, Response
from flask_socketio import SocketIO, emit
from threading import Lock
from gevent import monkey
from gevent.pywsgi import WSGIServer
import numpy as np
#from geventwebsocket.handler import WebSocketHandler

monkey.patch_all()

# import camera driver
from camera_opencv import Camera

app = Flask(__name__)

camears = [Camera('videos/car2.avi')]


def gen(camera):
    """Video streaming generator function."""
    while True:
        time.sleep(0.02)
        frame = camera.get_frame()
        yield (b'--frame\r\n'
               b'Content-Type: image/jpeg\r\n\r\n' + frame + b'\r\n')


@app.route('/video_feed')
def video_feed():
    """Video streaming routeSSS. Put this in the src attribute of an img tag."""
    return Response(gen(camears[0]),
Exemplo n.º 17
0
def video_feed():
    return Response(gen(Camera()),
                    mimetype='multipart/x-mixed-replace; boundary=frame')
Exemplo n.º 18
0
def video_feed():
    #Video streaming route. Feeds the src attribute of the img tag
    return Response(gen(Camera()),
                    mimetype='multipart/x-mixed-replace; boundary=frame')
Exemplo n.º 19
0
#!/usr/bin/env python
from importlib import import_module
import os
from flask import Flask, render_template, Response, send_from_directory
from flask_cors import *
# import camera driver

from camera_opencv import Camera
import threading

# Raspberry Pi camera module (requires picamera package)
# from camera_pi import Camera

app = Flask(__name__)
CORS(app, supports_credentials=True)
camera = Camera()


def gen(camera):
    """Video streaming generator function."""
    while True:
        frame = camera.get_frame()
        yield (b'--frame\r\n'
               b'Content-Type: image/jpeg\r\n\r\n' + frame + b'\r\n')


@app.route('/video_feed')
def video_feed():
    """Video streaming route. Put this in the src attribute of an img tag."""
    return Response(gen(camera),
                    mimetype='multipart/x-mixed-replace; boundary=frame')
Exemplo n.º 20
0
def video_feed():
    """Video streaming route. Put this in the src attribute of an img tag."""
    return Response(gen(Camera(config)),
                    mimetype='multipart/x-mixed-replace; boundary=frame')
Exemplo n.º 21
0
def image():
    """Returns a single current image for the webcam"""
    cameraID = request.args.get('cid')
    return Response(gen2(Camera()), mimetype='image/jpeg')
Exemplo n.º 22
0
def video_feed():
    frame = gen(Camera())
    # print(Camera.motionStatus)
    return Response(frame,
                    mimetype='multipart/x-mixed-replace; boundary=frame')
Exemplo n.º 23
0
def stream():
    cameraID = request.args.get('cid')
    #return Response(gen(VideoCamera(cameraID)), mimetype='multipart/x-mixed-replace; boundary=frame')
    return Response(gen(Camera()), mimetype='multipart/x-mixed-replace; boundary=frame')
Exemplo n.º 24
0
def image():
    """Returns a single current image for the webcam"""
    return Response(gen2(Camera()), mimetype='image/jpeg')
Exemplo n.º 25
0
def video_feed():
    """This function streams the images on the frame, with the next one overlapping and replacing the former. This is
    achieved by setting mimetype to 'multipart/x-mixed-replace'. The idea is that by replacing the image with another
    so quickly, it'd look like a video."""
    return Response(gen(Camera()),
                    mimetype='multipart/x-mixed-replace; boundary=frame')