File size: 3,140 Bytes
1b369eb
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# RDD reconstruction example"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from sfm import match_rdd, extract_rdd\n",
    "from hloc import (\n",
    "    extract_features,\n",
    "    reconstruction,\n",
    "    visualization,\n",
    "    pairs_from_retrieval,\n",
    "    pairs_from_exhaustive,\n",
    ")\n",
    "from pathlib import Path\n",
    "import os\n",
    "import torch"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "images_dir = Path('./assets/mapping')\n",
    "device = torch.cuda.is_available()\n",
    "images = [image for image in os.listdir(images_dir) if image.endswith('.jpg') or image.endswith('.png')]\n",
    "outputs = Path('./outputs/reconstruction')\n",
    "if not outputs.exists():\n",
    "    outputs.mkdir(parents=True)\n",
    "sfm_pairs = outputs / 'sfm_pairs.txt'\n",
    "retrieval_conf = extract_features.confs[\"netvlad\"]\n",
    "feature_conf = extract_rdd.confs[\"rdd\"]\n",
    "matcher_conf = match_rdd.confs[\"rdd+lightglue\"]\n",
    "exhaustive_if_less = 30\n",
    "num_matched = 20"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# image_retrieval\n",
    "if len(images) < exhaustive_if_less:\n",
    "    pairs_from_exhaustive.main(sfm_pairs, images)\n",
    "else:\n",
    "    retrieval_path = extract_features.main(retrieval_conf, images_dir, outputs)\n",
    "    pairs_from_retrieval.main(retrieval_path, sfm_pairs, num_matched=num_matched)\n",
    "    \n",
    "# feature_extraction\n",
    "feature_path = extract_rdd.main(feature_conf, images_dir, outputs)\n",
    "# matching\n",
    "match_path = match_rdd.main(matcher_conf, sfm_pairs, feature_conf['output'], outputs)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# reconstruction\n",
    "image_options = {}\n",
    "mapper_options = {}\n",
    "model = reconstruction.main(outputs, images_dir, sfm_pairs, feature_path, \n",
    "            match_path, verbose=True, camera_mode='PER_IMAGE', image_options=image_options, mapper_options=mapper_options,\n",
    "            min_match_score = 0.2, skip_geometric_verification=False)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "print(model.summary())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "RDD",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.18"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}