Beispiel #1
0
    def __init__(self, parent=None):
        super(App, self).__init__(parent)

        #### Create Gui Elements ###########
        self.mainbox = gl.GLViewWidget()
        self.setFixedSize(800, 800)
        self.setCentralWidget(self.mainbox)
        self.mainbox.setFixedSize(1600, 1200)
        self.mainbox.opts['viewport'] = (0, 0, 1600, 1200)
        self.mainbox.setWindowTitle('test')
        g = gl.GLGridItem()
        self.mainbox.addItem(g)
        pos = np.empty((21, 3))
        sizes = np.ones((21)) * 0.1
        colors = []
        colors_tpt = [[0, 1, 1, 1]]
        for i in range(5):
            colors.append(colors_tpt[0])
            colors.append(colors_tpt[0])
            colors.append(colors_tpt[0])
            colors.append(colors_tpt[0])
        colors.append([1, 0, 1, 1])

        self.sp = gl.GLScatterPlotItem(pos=pos, size=sizes, color=np.array(colors), pxMode=False)
        self.mainbox.addItem(self.sp)
        self._data_container = Data_container()
        # print(self.mainbox.getViewport())
        self._gege_client = None
        self._didi_client = None
        self._prediction_thread = None

        # Start
        self._update()
Beispiel #2
0
    def __init__(self, filename):
        """Create a Persistent_data from a filename"""

        self.filename = filename
        self._lock = threading.Lock()

        data = {}
        # Check wether file exists
        if os.path.isfile(filename):
            # Load data from file
            try:
                with open(filename) as f:
                    data = json.loads(f.read())

            except IOError:
                log.write(
                    "Error in data_container: Failed to load \"%s\"" % filename)
                raise

            except ValueError:
                log.write(
                    "Error in data_container: Invalid JSON in \"%s\"" % filename)
                raise

        self._container = Data_container(data)
Beispiel #3
0
import flask
from flask import render_template, jsonify
import numpy as np
from io import StringIO
from PIL import Image
import requests
import socket
import base64
import json
import time
from data_container import Data_container

app = flask.Flask(__name__)
data_container = Data_container()
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)  # UDP


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


@app.route('/get_image_1/<timestamp>', methods=['GET', 'POST'])
def get_image_1(timestamp):
    ret = requests.get(
        "http://192.168.5.178/html/cam_pic.php/?time=%s&pDelay=40000" %
        timestamp)
    ret = ret.content
    data_container.insert_image(ret, 0)
    return ret
Beispiel #4
0
class Persistent_data_container (object):

    def __init__(self, filename):
        """Create a Persistent_data from a filename"""

        self.filename = filename
        self._lock = threading.Lock()

        data = {}
        # Check wether file exists
        if os.path.isfile(filename):
            # Load data from file
            try:
                with open(filename) as f:
                    data = json.loads(f.read())

            except IOError:
                log.write(
                    "Error in data_container: Failed to load \"%s\"" % filename)
                raise

            except ValueError:
                log.write(
                    "Error in data_container: Invalid JSON in \"%s\"" % filename)
                raise

        self._container = Data_container(data)

    def set(self, key, value):
        """Set a value.

        Keys:
            \"user.email\" means root [ "user" ] [ "email" ]

        This method is thread safe.
        """

        self._container.set(key, value)
        self._save()

    def append(self, key, value):
        """Append a value to a list responding to a key.

        Keys:
            \"user.email\" means root [ "user" ] [ "email" ]

        This method is thread safe.
        """

        self._container.append(key, value)
        self._save()

    def pop(self, key, index):
        """Pop the value at an index off a list responding to a key.

        Keys:
            \"user.email\" means root [ "user" ] [ "email" ]

        This method is thread safe.
        """

        self._container.pop(key, index)
        self._save()

    def remove(self, key, value):
        """Remove a value from a list responding to a key.

        Keys:
            \"user.email\" means root [ "user" ] [ "email" ]

        This method is thread safe.
        """

        self._container.remove(key, value)
        self._save()

    def _save(self):
        """Save the data to the container."""

        with self._lock:
            try:
                # Write data into file
                with open(self.filename, "w") as f:
                    f.write(
                        json.dumps(self._container.get_data(), indent=4, separators=[",", ": "]))

            except IOError:
                log.write(
                    "Error in data_container: Failed to open \"%s\"" % filename)
                raise

    def get(self, key):
        """Return a value or None if not set

        Keys:
            \"user.email\" means root [ "user" ] [ "email" ]

        This method is thread safe.
        """

        # Simply return value from self._container
        return self._container.get(key)

    def get_data(self):
        """Return a deepcopy of the wrapped data.

        This method is thread safe.
        """

        # Simply return value from self._container
        return self._container.get_data()

    def get_data_container(self, key):
        """Return a Data_container object representing a dict identified by a key.

        Keys:
            \"user.email\" means root [ "user" ] [ "email" ]

        This method is thread safe.
        """

        # Simply return value from self._container
        return self._container.get_data_container(key)
Beispiel #5
0
class App(QtGui.QMainWindow):
    def __init__(self, parent=None):
        super(App, self).__init__(parent)

        #### Create Gui Elements ###########
        self.mainbox = gl.GLViewWidget()
        self.setFixedSize(800, 800)
        self.setCentralWidget(self.mainbox)
        self.mainbox.setFixedSize(1600, 1200)
        self.mainbox.opts['viewport'] = (0, 0, 1600, 1200)
        self.mainbox.setWindowTitle('test')
        g = gl.GLGridItem()
        self.mainbox.addItem(g)
        pos = np.empty((21, 3))
        sizes = np.ones((21)) * 0.1
        colors = []
        colors_tpt = [[0, 1, 1, 1]]
        for i in range(5):
            colors.append(colors_tpt[0])
            colors.append(colors_tpt[0])
            colors.append(colors_tpt[0])
            colors.append(colors_tpt[0])
        colors.append([1, 0, 1, 1])

        self.sp = gl.GLScatterPlotItem(pos=pos, size=sizes, color=np.array(colors), pxMode=False)
        self.mainbox.addItem(self.sp)
        self._data_container = Data_container()
        # print(self.mainbox.getViewport())
        self._gege_client = None
        self._didi_client = None
        self._prediction_thread = None

        # Start
        self._update()

    def _update(self):
        # if self._gege_client:
        #     print(self._gege_client.isFinished())
        if not self._gege_client or self._gege_client.isFinished():
            self._gege_client = Client(self._data_container, "http://192.168.5.178/html/cam_pic.php", 0)
            self._gege_client.start()

        if not self._didi_client or self._didi_client.isFinished():
            self._didi_client = Client(self._data_container, "http://192.168.5.73/html/cam_pic.php", 1)
            self._didi_client.start()

        # if not self._prediction_thread or self._prediction_thread.isFinished():
        #     self._prediction_thread = Predict(self._data_container)
        #     self._prediction_thread.signal.connect(self._finished_prediction)
        #     self._prediction_thread.start()
        res_flag, ret = self._data_container.predict()
        if res_flag == 0:
            ret_points = np.reshape(ret, [21, 3])
            # print(ret_points)
            y, z, x = ret_points.T
            data = np.array([x, y, z])
            vector = data.transpose() / 50
            self.sp.setData(pos=vector)
        # print("update")

        QtCore.QTimer.singleShot(10, self._update)

    def _finished_prediction(self, result):
        pass