johnrobinsn
commited on
Commit
•
ad1a298
1
Parent(s):
111dfa8
Added in resampling of larger images
Browse files- app.py +5 -0
- depth_viewer.py +0 -6
app.py
CHANGED
@@ -5,6 +5,7 @@ import numpy as np
|
|
5 |
from PIL import Image
|
6 |
from pathlib import Path
|
7 |
from depth_viewer import depthviewer2html
|
|
|
8 |
|
9 |
feature_extractor = DPTFeatureExtractor.from_pretrained("Intel/dpt-large")
|
10 |
model = DPTForDepthEstimation.from_pretrained("Intel/dpt-large")
|
@@ -13,6 +14,10 @@ def process_image(image_path):
|
|
13 |
image_path = Path(image_path)
|
14 |
image = Image.open(image_path)
|
15 |
|
|
|
|
|
|
|
|
|
16 |
# prepare image for the model
|
17 |
encoding = feature_extractor(image, return_tensors="pt")
|
18 |
|
|
|
5 |
from PIL import Image
|
6 |
from pathlib import Path
|
7 |
from depth_viewer import depthviewer2html
|
8 |
+
import cv2
|
9 |
|
10 |
feature_extractor = DPTFeatureExtractor.from_pretrained("Intel/dpt-large")
|
11 |
model = DPTForDepthEstimation.from_pretrained("Intel/dpt-large")
|
|
|
14 |
image_path = Path(image_path)
|
15 |
image = Image.open(image_path)
|
16 |
|
17 |
+
# if wider than 512 pixels let's resample to keep it performant on phones etc
|
18 |
+
if (image.size[0] > 512):
|
19 |
+
image = image.resize((512,int(512*image.size[1]/image.size[0])),Image.Resampling.LANCZOS)
|
20 |
+
|
21 |
# prepare image for the model
|
22 |
encoding = feature_extractor(image, return_tensors="pt")
|
23 |
|
depth_viewer.py
CHANGED
@@ -53,12 +53,6 @@ _viewer_html = '''
|
|
53 |
return document.getElementById("fshader").text
|
54 |
}
|
55 |
|
56 |
-
// The url for the image is passed in to the web application
|
57 |
-
//var p = new URLSearchParams(window.location.search);
|
58 |
-
//var image_url = 'https://tujot.com/thr/marsattacks.jpg';//p.get("image");
|
59 |
-
//var depth_url = '/depth?image='+image_url;
|
60 |
-
|
61 |
-
|
62 |
var texture = new THREE.TextureLoader().load(image_url, t => {
|
63 |
var w = t.image.width;
|
64 |
var h = t.image.height;
|
|
|
53 |
return document.getElementById("fshader").text
|
54 |
}
|
55 |
|
|
|
|
|
|
|
|
|
|
|
|
|
56 |
var texture = new THREE.TextureLoader().load(image_url, t => {
|
57 |
var w = t.image.width;
|
58 |
var h = t.image.height;
|