~fboucault/+junk/fingerprintgpu

« back to all changes in this revision

Viewing changes to fingerprintgpu/SegmentBoundingBoxes.qml

  • Committer: Florian Boucault
  • Date: 2016-05-25 08:19:05 UTC
  • Revision ID: florian.boucault@canonical.com-20160525081905-xj1591i0becrq9t1
supportĀ guĀ scaling

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
import QtQuick 2.4
2
2
 
3
3
QtObject {
 
4
    id: segmentBoundingBoxes
 
5
 
4
6
    property string source
5
7
    onSourceChanged: parseBoundingBoxes(source)
6
8
 
7
9
    property var boundingBoxes: []
 
10
    property real width
 
11
    property real height
8
12
    property int count: boundingBoxes.length
9
13
 
10
14
    function parseBoundingBoxes(source) {
13
17
        xhr.onreadystatechange = function() {
14
18
            if (xhr.readyState == XMLHttpRequest.DONE) {
15
19
                var b = [];
16
 
                var list = JSON.parse(xhr.responseText);
17
 
                for (var i in list) {
18
 
                    b[i] = list[i];
19
 
                }
20
 
                boundingBoxes = b;
 
20
                var json = JSON.parse(xhr.responseText);
 
21
                boundingBoxes = json["boxes"];
 
22
                width = json["width"];
 
23
                height = json["height"];
21
24
            }
22
25
        }
23
26
        xhr.send();
39
42
    }
40
43
    
41
44
    function computeIntersections(hitBox) {
 
45
        var absoluteHitBox = [hitBox[0] * width, hitBox[1] * height,
 
46
                              hitBox[2] * width, hitBox[3] * height];
 
47
 
42
48
        var intersections = [];
43
49
        for (var i in boundingBoxes) {
44
50
            var boundingBox = boundingBoxes[i];
45
 
            if (intersects(hitBox, boundingBox)) {
 
51
            if (intersects(absoluteHitBox, boundingBox)) {
46
52
                intersections.push(i);
47
53
            }
48
54
        }