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 = {
|
||||
"\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 os
|
||||
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):
|
||||
'''
|
||||
|
@ -139,7 +151,7 @@ def krpano_make_tiles(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
|
||||
stitched image.
|
||||
|
|
|
@ -1,65 +1,21 @@
|
|||
import sys
|
||||
import os
|
||||
import argparse
|
||||
from urllib import request
|
||||
from urllib import parse
|
||||
from bs4 import BeautifulSoup
|
||||
import json
|
||||
import subprocess
|
||||
import math
|
||||
import io
|
||||
import PIL.Image
|
||||
from stitching import multistitch, tiles_to_equirectangular_blender
|
||||
|
||||
def pars_args():
|
||||
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):
|
||||
def get_url_data(url):
|
||||
# Load Data from URL
|
||||
soup_from_url = BeautifulSoup(request.urlopen(url).read(), "html.parser")
|
||||
pano_data = json.loads(soup_from_url.script.contents[0][33:-1])
|
||||
|
||||
print("Downloading: " + soup_from_url.title.string)
|
||||
|
||||
# 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
|
||||
return create_dl_url(pano_data)
|
||||
|
||||
def create_dl_url(pano_data):
|
||||
# URL Download Creation
|
||||
|
@ -70,38 +26,43 @@ def create_dl_url(pano_data):
|
|||
dl_url = template_dl_url.replace("{{filename}}", custom_url_part)
|
||||
return dl_url
|
||||
|
||||
def dl_tiles(dl_url, directory):
|
||||
if not os.path.exists(directory):
|
||||
os.makedirs(directory)
|
||||
def dl_tiles(dl_url):
|
||||
output = []
|
||||
|
||||
picture_count = 0
|
||||
for i in range(0,6):
|
||||
i_array = []
|
||||
|
||||
for j in range(0,4):
|
||||
j_array = []
|
||||
|
||||
for k in range(0,4):
|
||||
file_number = str(i) + "_" + str(k) + "_" + str(j)
|
||||
temp_dl_url = dl_url.replace("$i_$j_$k", file_number)
|
||||
request.urlretrieve(temp_dl_url, directory + \
|
||||
"/" + "part-" + str(i) + "-1-" + \
|
||||
str(j) + "_" + str(k) + ".jpg")
|
||||
picture_count += 1
|
||||
print("Downloading Picture: " + str(picture_count) + "/96" + "\r", sep=' ', end='', flush=True)
|
||||
print("Downloading Picture: " + str(picture_count) + "/96")
|
||||
res = request.urlopen(temp_dl_url)
|
||||
assert res.getcode() == 200
|
||||
fo = io.BytesIO(res.read())
|
||||
img = PIL.Image.open(fo)
|
||||
j_array.append(img)
|
||||
|
||||
def create_cube(directory, rotation):
|
||||
print("Creating cube")
|
||||
rc = subprocess.check_call(["./matterport_dl.sh",
|
||||
str(directory),
|
||||
str(int(math.degrees(rotation)))])
|
||||
i_array.append(j_array)
|
||||
|
||||
output.append(i_array)
|
||||
|
||||
def main():
|
||||
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)
|
||||
return output
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
def matterport_make_tiles(url):
|
||||
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):
|
||||
jobid = str(uuid.uuid4())
|
||||
config = configparser.ConfigParser()
|
||||
config = configparser.ConfigParser(strict=False, interpolation=None)
|
||||
|
||||
try:
|
||||
title = re.sub(r"[^a-zA-Z0-9_\-]", "_", req.args["title"][0]) or output
|
||||
|
|
|
@ -13,7 +13,7 @@ processes = {}
|
|||
def handleIncoming(filename):
|
||||
print(filename)
|
||||
time.sleep(1)
|
||||
config = configparser.ConfigParser()
|
||||
config = configparser.ConfigParser(strict=False, interpolation=None)
|
||||
config.read(filename)
|
||||
p = subprocess.Popen(["./handler.py", config["Job"]["url"], "--title",
|
||||
filename.split("/")[-1] + "---" + config["Job"]["title"],
|
||||
|
|
Loading…
Reference in a new issue