Esempio n. 1
0
def keyFramesProperties(taskId):
    frameProperties = rqApi.parseBytesToJson(
        rqApi.getRequest({
            'task.id': str(taskId)
        }, models.Taskframespec).get_data())
    keyFrames = {}
    for prop in frameProperties:
        props = rqApi.parseBytesToJson(
            rqApi.getRequest({
                'frameSpec_id': str(prop['id'])
            }, models.Keyframespec).get_data())

        for i in range(0, len(props)):
            keyFrameSpec = {
                "frame":
                props[i]['frame'],
                props[i]['frameSpec']['propVal']['prop']:
                props[i]['frameSpec']['propVal']['value'],
                "prop":
                props[i]['frameSpec']['propVal']['prop']
            }

            if props[i]['frameSpec']['propVal']['prop'] not in keyFrames.keys(
            ):
                keyFrames[props[i]['frameSpec']['propVal']['prop']] = []

            keyFrames[props[i]['frameSpec']['propVal']['prop']].append(
                keyFrameSpec)

    return keyFrames
Esempio n. 2
0
def initializeProperties(model, key, value):
    """Get all properties of a tag
    :param model: model that represents the table with properties
    :param key: key to search by
    :param value: value to search by key
    :return: dictionary contains the properties
    """
    attrs = {}

    try:
        vals = rqApi.parseBytesToJson(
            rqApi.getRequest({
                key: value
            }, model).get_data())

        for val in vals:
            startIndex = val['spec']['text'].index('=') + 1

            try:
                endIndex = val['spec']['text'].index(':')
            except:
                endIndex = len(val['spec']['text'])
            attrs[val['spec']['text'][startIndex:endIndex]] = val['value']

    except Exception as e:
        logger.error(e, exc_info=True)

    return attrs
Esempio n. 3
0
def getLabeledPolygon(jobId):
    """Get all labeled polygon tags of a job
    :param jobId: the id of the job
    :return: array with all labeled polygon tags
    """
    labels = rqApi.parseBytesToJson(
        rqApi.getRequest({
            'job.id': jobId
        }, models.Labeledpolygon).get_data())
    labels = list(
        map(
            lambda label: {
                "geometry": {
                    "type": "Polygon",
                    "coordinates": parsePointToGeoJsonPolygon(label['points'])
                },
                "properties":
                initializeProperties(models.Labeledpolygonattributeval,
                                     'polygon_id', str(label['id'])),
                "frame":
                int(label['frame']),
                "class":
                label['label']['name']
            }, labels))

    return labels
Esempio n. 4
0
def getLabeledBox(jobId):
    """Get all labeledbox tags of a job
    :param jobId: the id of the job
    :return: array with all labeledbox tags
    """
    labels = rqApi.parseBytesToJson(
        rqApi.getRequest({
            'job.id': jobId
        }, models.Labeledbox).get_data())
    labels = list(
        map(
            lambda label: {
                "box": {
                    "xbr": float(label['xbr']),
                    "xtl": float(label['xtl']),
                    "ybr": float(label['ybr']),
                    "ytl": float(label['ytl'])
                },
                "properties":
                initializeProperties(models.Labeledboxattributeval, 'box_id',
                                     str(label['id'])),
                "frame":
                int(label['frame']),
                "class":
                label['label']['name']
            }, labels))

    return labels
Esempio n. 5
0
def getTaskAnnotations(projectName, source):
    """Get all tags of a task
    :param projectName: project name of the task
    :param source: source of the task
    :return: Json with all annotations of this task
    """
    task = rqApi.parseBytesToJson(
        rqApi.getRequest({
            'project.name': projectName,
            'source': source
        }, models.Task).get_data())

    if len(task) == 0:
        # Checking if the source is task name for images task
        task = rqApi.parseBytesToJson(
            rqApi.getRequest({
                'project.name': projectName,
                'name': source
            }, models.Task).get_data())
        if len(task) == 0:
            return -1

    jobId = rqApi.getJobId(task[0]['id'])

    labeledBox = getLabeledBox(jobId)
    trackedBox = getTrackedBox(jobId, int(task[0]['size']))
    labeledPolygon = getLabeledPolygon(jobId)
    frameProperties = getFrameProperties(task[0]['id'], int(task[0]['size']))

    taskAnnotations = {
        'project.name': projectName,
        'source': task[0]['source'],
        'annotations': trackedBox + labeledBox + labeledPolygon,
        'frameProperties': frameProperties,
        'name': task[0]['name']
    }

    return taskAnnotations
Esempio n. 6
0
def getCountFinishFramesRequest(data):
    """Get the count of finish frames in specific project\n
        params:
            data: json contains task and project name
        return: number of frames (string)
    """

    missingParam = rqApi.checkIfParamsExist(data, ['project.name'])

    if missingParam != "":
        return jsonify({'message': missingParam + ' is missing!'}), 401

    tasks = rqApi.getRequest(data, models.Task)
    try:
        tasks = rqApi.parseBytesToJson(tasks.get_data())
        totalFrames = 0
        for task in tasks:
            totalFrames += task['size']
        return str(totalFrames), 200
    except Exception as e:
        logger.error(e, exc_info=True)
        return jsonify({'message': 'There is no count of frames to show !'})
Esempio n. 7
0
def getTrackedBox(jobId, size):
    """Get all interpolation tags of a job
    :param jobId: the id of the job
    :param size: the size of the job
    :return: array with all tags
    """
    # Get all track id's of this job
    objectsPath = rqApi.parseBytesToJson(
        rqApi.getRequest({
            'job.id': jobId
        }, models.Objectpath).get_data())

    if len(objectsPath) != 0:
        objectsPath = list(map(lambda x: str(x['id']), objectsPath))
        objectsPath = ','.join(objectsPath)

        # Get all tracks for this job
        tracks = rqApi.parseBytesToJson(
            rqApi.getRequest({
                'track.id': str(objectsPath)
            }, models.Trackedbox).get_data())
        tracks = list(
            map(
                lambda track: {
                    "box": {
                        "xbr": float(track['xbr']),
                        "xtl": float(track['xtl']),
                        "ybr": float(track['ybr']),
                        "ytl": float(track['ytl'])
                    },
                    "properties":
                    initializeProperties(models.Trackedboxattributeval,
                                         'box_id', str(track['id'])),
                    "frame":
                    int(track['frame']),
                    "class":
                    track['track']['label']['name'],
                    "track_id":
                    int(track['track']['id']),
                    "outside":
                    track['outside']
                }, tracks))

        tracks_dict = {}

        for track in tracks:
            trackId = track['track_id']
            if trackId not in tracks_dict:
                tracks_dict[trackId] = []

            tracks_dict[trackId].append(track)

        completeTracks = []

        for trackId in tracks_dict:
            currentTrack = tracks_dict[trackId]
            currentTrack.sort(key=lambda x: x['frame'])
            currentTrack = completeFrame(currentTrack, size)
            completeTracks.extend(currentTrack)

        return completeTracks
    else:
        return []