-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathutility.js
More file actions
47 lines (44 loc) · 1.59 KB
/
utility.js
File metadata and controls
47 lines (44 loc) · 1.59 KB
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
function drag(movable,pos){
if(movable==null) return;
const mouseDownEvent = new MouseEvent('mousedown', {
clientX: movable.getBoundingClientRect().left,
clientY: movable.getBoundingClientRect().top,
pageX: 0,
pageY: 0,
bubbles: true,
cancelable: true,
view: window
});
const mouseMoveEvent = new MouseEvent('mousemove', {
clientX: movable.getBoundingClientRect().left+pos,
clientY: movable.getBoundingClientRect().top,
bubbles: true,
cancelable: true,
view: window
});
const mouseUpEvent = new MouseEvent('mouseup',{
pageX: movable.getBoundingClientRect().left+pos,
pageY: movable.getBoundingClientRect().top,
bubbles: true,
cancelable: true,
view: window
});
movable.dispatchEvent(mouseDownEvent)
setTimeout(()=>movable.dispatchEvent(mouseMoveEvent),500);
setTimeout(()=>movable.dispatchEvent(mouseUpEvent),550);
}
function predict(img,model){
var elem=document.createElement('canvas');
elem.setAttribute("width",224);
elem.setAttribute("height",224);
let ctx=elem.getContext('2d');
ctx.drawImage(img, 0, 0, img.width, img.height, 0, 0, 224, 224);
let imageData = tf.browser.fromPixels(elem);
imageData = tf.stack([imageData]);
model.predict(imageData).data().then(result=>{
const movable = document.getElementById('slideBlock');
let rect=movable.getBoundingClientRect();
let fix=20;
drag(movable,result[1]/224*img.width-rect.x + fix);
});
}