Implement Matterport downloads
This commit is contained in:
parent
db3d012976
commit
8f9f728118
7 changed files with 52 additions and 90 deletions
0
hallmonitor.sh
Normal file → Executable file
0
hallmonitor.sh
Normal file → Executable file
|
@ -6,7 +6,8 @@ import argparse
|
||||||
|
|
||||||
regs = {
|
regs = {
|
||||||
"\d/\d/\d_\d\.jpg": "krpanosteal",
|
"\d/\d/\d_\d\.jpg": "krpanosteal",
|
||||||
"pano\_[frblud].jpg": "krpanosteal"
|
"pano\_[frblud].jpg": "krpanosteal",
|
||||||
|
"my.matterport.com/show/": "matterportsteal"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -7,6 +7,18 @@ import tempfile
|
||||||
import pathlib
|
import pathlib
|
||||||
import os
|
import os
|
||||||
from stitching import tiles_to_equirectangular_blender, multistitch
|
from stitching import tiles_to_equirectangular_blender, multistitch
|
||||||
|
import robobrowser
|
||||||
|
|
||||||
|
def krpano_detect(url):
|
||||||
|
'''
|
||||||
|
Takes any URL and tries to detect a krpano panorama embedded in the site.
|
||||||
|
|
||||||
|
:param url: URL of a site containing a krpano panorama
|
||||||
|
:return: URL of an image contained in krpano panorama if found, else False
|
||||||
|
'''
|
||||||
|
|
||||||
|
juha = bs4.BeautifulSoup(request.urlopen(url).read(), "html.parser")
|
||||||
|
|
||||||
|
|
||||||
def krpano_normalize(url):
|
def krpano_normalize(url):
|
||||||
'''
|
'''
|
||||||
|
@ -139,7 +151,7 @@ def krpano_make_tiles(url):
|
||||||
raise ValueError("%s does not seem to be a valid krpano URL." % url)
|
raise ValueError("%s does not seem to be a valid krpano URL." % url)
|
||||||
|
|
||||||
|
|
||||||
def krpano_to_equirectangular(url, rotation=[0,0,0], resolution=[0,0]):
|
def krpano_to_equirectangular(url, rotation=[0,0,0], resolution=[3840,1920]):
|
||||||
'''
|
'''
|
||||||
Takes the URL of any image in a krpano panorama and returns a finished
|
Takes the URL of any image in a krpano panorama and returns a finished
|
||||||
stitched image.
|
stitched image.
|
||||||
|
|
|
@ -1,65 +1,21 @@
|
||||||
import sys
|
import sys
|
||||||
import os
|
import os
|
||||||
import argparse
|
|
||||||
from urllib import request
|
from urllib import request
|
||||||
from urllib import parse
|
from urllib import parse
|
||||||
from bs4 import BeautifulSoup
|
from bs4 import BeautifulSoup
|
||||||
import json
|
import json
|
||||||
import subprocess
|
import subprocess
|
||||||
import math
|
import math
|
||||||
|
import io
|
||||||
|
import PIL.Image
|
||||||
|
from stitching import multistitch, tiles_to_equirectangular_blender
|
||||||
|
|
||||||
def pars_args():
|
def get_url_data(url):
|
||||||
parser = argparse.ArgumentParser()
|
|
||||||
parser.add_argument(
|
|
||||||
"--url",
|
|
||||||
"-u",
|
|
||||||
type=str,
|
|
||||||
help="Download URL")
|
|
||||||
|
|
||||||
parser.add_argument(
|
|
||||||
"--dir",
|
|
||||||
"-d",
|
|
||||||
type=str,
|
|
||||||
default = None,
|
|
||||||
help="Save directory if none is specified title will be used")
|
|
||||||
|
|
||||||
parser.add_argument(
|
|
||||||
"--rot",
|
|
||||||
"-r",
|
|
||||||
type=str,
|
|
||||||
default = 0,
|
|
||||||
help = "Panorama rotation in degree")
|
|
||||||
|
|
||||||
parser.add_argument(
|
|
||||||
"--disable-download",
|
|
||||||
"-dd",
|
|
||||||
action = "store_true",
|
|
||||||
help = "Disables Download")
|
|
||||||
|
|
||||||
args = parser.parse_args()
|
|
||||||
args = vars(args)
|
|
||||||
|
|
||||||
if not args["url"]:
|
|
||||||
print("+ + + Please provide URL + + +")
|
|
||||||
parser.print_help()
|
|
||||||
sys.exit(0)
|
|
||||||
|
|
||||||
return args
|
|
||||||
|
|
||||||
def get_url_data(url, directory):
|
|
||||||
# Load Data from URL
|
# Load Data from URL
|
||||||
soup_from_url = BeautifulSoup(request.urlopen(url).read(), "html.parser")
|
soup_from_url = BeautifulSoup(request.urlopen(url).read(), "html.parser")
|
||||||
pano_data = json.loads(soup_from_url.script.contents[0][33:-1])
|
pano_data = json.loads(soup_from_url.script.contents[0][33:-1])
|
||||||
|
|
||||||
print("Downloading: " + soup_from_url.title.string)
|
return create_dl_url(pano_data)
|
||||||
|
|
||||||
# Create Directory if none is specified
|
|
||||||
if directory is None:
|
|
||||||
directory = soup_from_url.title.string
|
|
||||||
directory = directory.replace(" - Matterport 3D Showcase", "")
|
|
||||||
dl_url = create_dl_url(pano_data)
|
|
||||||
|
|
||||||
return dl_url, directory
|
|
||||||
|
|
||||||
def create_dl_url(pano_data):
|
def create_dl_url(pano_data):
|
||||||
# URL Download Creation
|
# URL Download Creation
|
||||||
|
@ -70,38 +26,43 @@ def create_dl_url(pano_data):
|
||||||
dl_url = template_dl_url.replace("{{filename}}", custom_url_part)
|
dl_url = template_dl_url.replace("{{filename}}", custom_url_part)
|
||||||
return dl_url
|
return dl_url
|
||||||
|
|
||||||
def dl_tiles(dl_url, directory):
|
def dl_tiles(dl_url):
|
||||||
if not os.path.exists(directory):
|
output = []
|
||||||
os.makedirs(directory)
|
|
||||||
|
|
||||||
picture_count = 0
|
|
||||||
for i in range(0,6):
|
for i in range(0,6):
|
||||||
|
i_array = []
|
||||||
|
|
||||||
for j in range(0,4):
|
for j in range(0,4):
|
||||||
|
j_array = []
|
||||||
|
|
||||||
for k in range(0,4):
|
for k in range(0,4):
|
||||||
file_number = str(i) + "_" + str(k) + "_" + str(j)
|
file_number = str(i) + "_" + str(k) + "_" + str(j)
|
||||||
temp_dl_url = dl_url.replace("$i_$j_$k", file_number)
|
temp_dl_url = dl_url.replace("$i_$j_$k", file_number)
|
||||||
request.urlretrieve(temp_dl_url, directory + \
|
res = request.urlopen(temp_dl_url)
|
||||||
"/" + "part-" + str(i) + "-1-" + \
|
assert res.getcode() == 200
|
||||||
str(j) + "_" + str(k) + ".jpg")
|
fo = io.BytesIO(res.read())
|
||||||
picture_count += 1
|
img = PIL.Image.open(fo)
|
||||||
print("Downloading Picture: " + str(picture_count) + "/96" + "\r", sep=' ', end='', flush=True)
|
j_array.append(img)
|
||||||
print("Downloading Picture: " + str(picture_count) + "/96")
|
|
||||||
|
|
||||||
def create_cube(directory, rotation):
|
i_array.append(j_array)
|
||||||
print("Creating cube")
|
|
||||||
rc = subprocess.check_call(["./matterport_dl.sh",
|
|
||||||
str(directory),
|
|
||||||
str(int(math.degrees(rotation)))])
|
|
||||||
|
|
||||||
|
output.append(i_array)
|
||||||
|
|
||||||
def main():
|
return output
|
||||||
args = pars_args()
|
|
||||||
directory = args["dir"]
|
|
||||||
rotation = math.radians(-float(args["rot"]))
|
|
||||||
dl_url, directory = get_url_data(args["url"], directory)
|
|
||||||
if not args["disable_download"]:
|
|
||||||
dl_tiles(dl_url, directory)
|
|
||||||
create_cube(directory, rotation)
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
def matterport_make_tiles(url):
|
||||||
main()
|
dl_url = get_url_data(url)
|
||||||
|
images = dl_tiles(dl_url)
|
||||||
|
return multistitch(images)
|
||||||
|
|
||||||
|
def matterport_to_equirectangular(url, rotation=[0,0,0], resolution=[3840,1920]):
|
||||||
|
stitched = matterport_make_tiles(url)
|
||||||
|
function = tiles_to_equirectangular_blender
|
||||||
|
|
||||||
|
ordered = stitched[1:5] + [stitched[0], stitched[5]]
|
||||||
|
|
||||||
|
rx, ry, rz = rotation
|
||||||
|
width, height = resolution
|
||||||
|
return function(*ordered, rx=rx, ry=ry, rz=rz, width=width, height=height)
|
||||||
|
|
||||||
|
process_url = matterport_to_equirectangular
|
||||||
|
|
|
@ -1,12 +0,0 @@
|
||||||
#!/bin/bash
|
|
||||||
mkdir "${1}/cube" -p
|
|
||||||
|
|
||||||
for ((f=0;f<=5;f++)); do
|
|
||||||
convert "${1}/part-${f}-1-0_0.jpg" "${1}/part-${f}-1-0_1.jpg" "${1}/part-${f}-1-0_2.jpg" "${1}/part-${f}-1-0_3.jpg" +append "${1}/_part-${f}-1-0.jpg"
|
|
||||||
convert "${1}/part-${f}-1-1_0.jpg" "${1}/part-${f}-1-1_1.jpg" "${1}/part-${f}-1-1_2.jpg" "${1}/part-${f}-1-1_3.jpg" +append "${1}/_part-${f}-1-1.jpg"
|
|
||||||
convert "${1}/part-${f}-1-2_0.jpg" "${1}/part-${f}-1-2_1.jpg" "${1}/part-${f}-1-2_2.jpg" "${1}/part-${f}-1-2_3.jpg" +append "${1}/_part-${f}-1-2.jpg"
|
|
||||||
convert "${1}/part-${f}-1-3_0.jpg" "${1}/part-${f}-1-3_1.jpg" "${1}/part-${f}-1-3_2.jpg" "${1}/part-${f}-1-3_3.jpg" +append "${1}/_part-${f}-1-3.jpg"
|
|
||||||
convert "${1}/_part-${f}-1-0.jpg" "${1}/_part-${f}-1-1.jpg" "${1}/_part-${f}-1-2.jpg" "${1}/_part-${f}-1-3.jpg" -append "${1}/cube/${f}.jpg"
|
|
||||||
done
|
|
||||||
|
|
||||||
cube2sphere -r 3840 2160 -R 0 0 $2 -f jpg -b blender "${1}/cube/3.jpg" "${1}/cube/1.jpg" "${1}/cube/2.jpg" "${1}/cube/4.jpg" "${1}/cube/0.jpg" "${1}/cube/5.jpg" -o "${1}/cube/${1}"
|
|
|
@ -39,7 +39,7 @@ def static(req):
|
||||||
|
|
||||||
def addjob(req):
|
def addjob(req):
|
||||||
jobid = str(uuid.uuid4())
|
jobid = str(uuid.uuid4())
|
||||||
config = configparser.ConfigParser()
|
config = configparser.ConfigParser(strict=False, interpolation=None)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
title = re.sub(r"[^a-zA-Z0-9_\-]", "_", req.args["title"][0]) or output
|
title = re.sub(r"[^a-zA-Z0-9_\-]", "_", req.args["title"][0]) or output
|
||||||
|
|
|
@ -13,7 +13,7 @@ processes = {}
|
||||||
def handleIncoming(filename):
|
def handleIncoming(filename):
|
||||||
print(filename)
|
print(filename)
|
||||||
time.sleep(1)
|
time.sleep(1)
|
||||||
config = configparser.ConfigParser()
|
config = configparser.ConfigParser(strict=False, interpolation=None)
|
||||||
config.read(filename)
|
config.read(filename)
|
||||||
p = subprocess.Popen(["./handler.py", config["Job"]["url"], "--title",
|
p = subprocess.Popen(["./handler.py", config["Job"]["url"], "--title",
|
||||||
filename.split("/")[-1] + "---" + config["Job"]["title"],
|
filename.split("/")[-1] + "---" + config["Job"]["title"],
|
||||||
|
|
Loading…
Reference in a new issue