Esempio n. 1
0
def configure():
    _, source_buffer = cv2.imencode('.jpg', source_image)

    _, frame = camera.read()
    frame = cv2.flip(scale_crop(frame), 1)
    _, frame_buffer = cv2.imencode('.jpg', frame)

    source_encoded = base64.b64encode(source_buffer)
    frame_encoded = base64.b64encode(frame_buffer)

    data = {
        "source": source_encoded,
        "frame": frame_encoded,
    }

    r = requests.post(configure_url, data=data)

    if r.status_code != 200:
        print("error")
        return ('', 204)

    global uid
    uid = r.text

    if uid == NULL_UID:
      return redirect(url_for('mismatch'))

    return redirect(url_for('index'))
Esempio n. 2
0
def get_source_frame(image, start_x, start_y, end_x, end_y):
    center_x = (end_x+start_x)/2
    center_y = (end_y-start_y)/2
    fH, fW = (end_y-start_y, end_x-start_x)
    crop_size = (fH+fW)/2
    s = crop_size/2
    face = image[center_y-s:center_y+s, center_x-s:center_x+s]
    return scale_crop(face)
Esempio n. 3
0
def upload_image():
    if request.method == "POST":
        if request.files:
            image = request.files["image"]

            global source_image
            source_image = cv2.imdecode(np.fromstring(image.read(), np.uint8), cv2.IMREAD_COLOR)
            source_image = cv2.flip(scale_crop(source_image), 1)

    return redirect(url_for('index'))
Esempio n. 4
0
def gen_frames():  # generate frame by frame from camera
    while True:
        # Capture frame-by-frame
        success, frame = camera.read()  # read the camera frame
        if not success:
            break
        else:
            frame = cv2.flip(scale_crop(frame), 1)
            _, buffer = cv2.imencode('.jpg', frame)
            stream_bytes = buffer.tobytes()
            yield (b'--frame\r\n'
                   b'Content-Type: image/jpeg\r\n\r\n' + stream_bytes + b'\r\n')
Esempio n. 5
0
def gen_transformed_frames():
    while True:
        # Capture frame-by-frame
        success, frame = camera.read()  # read the camera frame
        if not success:
            break
        else:
            frame = cv2.flip(scale_crop(frame), 1)
            _, frame_buffer = cv2.imencode('.jpg', frame)
            frame_encoded = base64.b64encode(frame_buffer)
            data = {
                "uid": uid,
                "frame": frame_encoded
            }

            r = requests.post(transform_url, data=data)
            yield (b'--frame\r\n'
                   b'Content-Type: image/jpeg\r\n\r\n' + r.content + b'\r\n')
Esempio n. 6
0
app = Flask(__name__)
camera = cv2.VideoCapture(0)

server_url = 'http://127.0.0.1:5000'
# server_url = 'http://9aaa3ade2048.ngrok.io'
# server_url = "http://34.221.75.41:5000"
configure_url = server_url + "/configure"
transform_url = server_url + "/transform"

uid = None
NULL_UID = '#'

source_image = imageio.imread('images/ryan.png')
source_image = cv2.cvtColor(source_image, cv2.COLOR_BGR2RGB)
source_image = cv2.flip(scale_crop(source_image), 1)


def gen_frames():  # generate frame by frame from camera
    while True:
        # Capture frame-by-frame
        success, frame = camera.read()  # read the camera frame
        if not success:
            break
        else:
            frame = cv2.flip(scale_crop(frame), 1)
            _, buffer = cv2.imencode('.jpg', frame)
            stream_bytes = buffer.tobytes()
            yield (b'--frame\r\n'
                   b'Content-Type: image/jpeg\r\n\r\n' + stream_bytes + b'\r\n')