fix origin image render block & add time diff
Browse files
index.js
CHANGED
@@ -16,9 +16,10 @@ status.textContent = 'Ready';
|
|
16 |
const url = 'https://images.pexels.com/photos/5965592/pexels-photo-5965592.jpeg?auto=compress&cs=tinysrgb&w=1024';
|
17 |
function useRemoteImage(url) {
|
18 |
const image = document.createElement('img');
|
|
|
19 |
image.src = url;
|
20 |
imageContainer.appendChild(image);
|
21 |
-
start(url)
|
22 |
}
|
23 |
useRemoteImage(url)
|
24 |
|
@@ -39,7 +40,7 @@ fileSelect.addEventListener('change', function (e) {
|
|
39 |
const image = document.createElement('img');
|
40 |
image.src = e2.target.result;
|
41 |
imageContainer.appendChild(image);
|
42 |
-
start(image.src)
|
43 |
};
|
44 |
reader.readAsDataURL(file);
|
45 |
});
|
@@ -47,6 +48,7 @@ fileSelect.addEventListener('change', function (e) {
|
|
47 |
async function start(source) {
|
48 |
status.textContent = 'processing';
|
49 |
console.log('start process')
|
|
|
50 |
|
51 |
const image = await RawImage.read(source);
|
52 |
// Process image
|
@@ -60,7 +62,9 @@ async function start(source) {
|
|
60 |
const matteImage = await RawImage.fromTensor(output[0].mul(255).to('uint8')).resize(image.width, image.height);
|
61 |
|
62 |
console.log('matteImage', matteImage, output)
|
63 |
-
|
|
|
|
|
64 |
|
65 |
async function renderRawImage(image) {
|
66 |
let rawCanvas = await image.toCanvas();
|
|
|
16 |
const url = 'https://images.pexels.com/photos/5965592/pexels-photo-5965592.jpeg?auto=compress&cs=tinysrgb&w=1024';
|
17 |
function useRemoteImage(url) {
|
18 |
const image = document.createElement('img');
|
19 |
+
image.crossOrigin = "anonymous";
|
20 |
image.src = url;
|
21 |
imageContainer.appendChild(image);
|
22 |
+
setTimeout(() => start(url), 0)
|
23 |
}
|
24 |
useRemoteImage(url)
|
25 |
|
|
|
40 |
const image = document.createElement('img');
|
41 |
image.src = e2.target.result;
|
42 |
imageContainer.appendChild(image);
|
43 |
+
setTimeout(() => start(image.src), 0)
|
44 |
};
|
45 |
reader.readAsDataURL(file);
|
46 |
});
|
|
|
48 |
async function start(source) {
|
49 |
status.textContent = 'processing';
|
50 |
console.log('start process')
|
51 |
+
const startTime = new Date();
|
52 |
|
53 |
const image = await RawImage.read(source);
|
54 |
// Process image
|
|
|
62 |
const matteImage = await RawImage.fromTensor(output[0].mul(255).to('uint8')).resize(image.width, image.height);
|
63 |
|
64 |
console.log('matteImage', matteImage, output)
|
65 |
+
const endTime = new Date();
|
66 |
+
const diff = (endTime - startTime) / 1000
|
67 |
+
setTimeout(() => status.textContent = 'Finish: ' + diff + 's', 100)
|
68 |
|
69 |
async function renderRawImage(image) {
|
70 |
let rawCanvas = await image.toCanvas();
|