-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDepthImage.vue
129 lines (119 loc) · 2.86 KB
/
DepthImage.vue
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
<template>
<div class="image-wrapper">
<div class="canvasContainer" ref="canvasContainer" />
<ImageUpload
@imageChange="onImageChange"
:class="{ 'hidden' : imageProcessed }"
/>
<!-- (comes from this.$emit('imageChange', this.previewImage);) -->
<div v-if="debug" class="controls">
<label for="port">RunwayML HTTP Server http://localhost:</label>
<input type="text" id="port" name="port" v-model="port" />
</div>
<div v-if="debug">
<img ref="srcImage" />
<img ref="depthImage" />
</div>
</div>
</template>
<script>
import ImageUpload from './ImageUpload.vue';
import ImageEffect from '../scripts/image-effect';
import { loadImage, dataUrlToImage } from '../scripts/utils/image-utils';
export default {
components: {
ImageUpload,
},
data: () => ({
port: 8000, // default port
displayImage: null,
debug: false,
imageProcessed: false,
}),
computed: {
postUrl() {
return `http://localhost:${this.port}/query`;
},
},
mounted() {
this.displayImage = new ImageEffect(this.$refs.canvasContainer);
if (this.debug) {
Promise.all([
loadImage('../test-img.png'),
loadImage('../test-img-depth.png'),
]).then((img) => {
this.displayImage.addTexture([img[0], img[1]]);
});
}
},
methods: {
async onImageChange(imgUrl) {
if (this.debug) {
this.$refs.srcImage.src = imgUrl;
}
this.sendImage(this.postUrl, {
image: imgUrl,
});
},
async sendImage(url, data) {
try {
const response = await fetch(`${url}`, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify(data),
});
const processedImg = await response.json();
// show depth image
if (this.debug) {
this.$refs.depthImage.src = processedImg.depth_image;
}
// send images to webgl programm
if (this.displayImage) {
Promise.all([
dataUrlToImage(data.image),
dataUrlToImage(processedImg.depth_image),
]).then((img) => {
this.imageProcessed = true;
this.displayImage.addTexture([img[0], img[1]]);
});
}
} catch (error) {
// eslint-disable-next-line no-alert
alert('Please check RunwayML\'s GET port and make sure a workspace with \'DenseDepth\' is running.');
// console.error(error);
}
},
},
};
</script>
<style>
canvas {
display: block;
}
input {
border: 0;
font-size: inherit;
font-family: inherit;
width: 4em;
}
img {
width: 400px;
}
.controls {
font-size: 1rem;
font-family: monospace;
}
.canvasContainer {
height: 100vh;
position: absolute;
top: 0;
left: 0;
right: 0;
bottom: 0;
}
.image-wrapper{
position: relative;
}
</style>