Skip to content

Instantly share code, notes, and snippets.

@Kelvinrr
Created August 3, 2017 16:30
Show Gist options
  • Select an option

  • Save Kelvinrr/7f79c451d19a8851a024a846bf630772 to your computer and use it in GitHub Desktop.

Select an option

Save Kelvinrr/7f79c451d19a8851a024a846bf630772 to your computer and use it in GitHub Desktop.
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Populating the interactive namespace from numpy and matplotlib\n"
]
}
],
"source": [
"import os\n",
"import sys\n",
"sys.path.insert(0, os.path.abspath('..'))\n",
"\n",
"from autocnet import cuda \n",
"from autocnet.examples import get_path\n",
"from autocnet.graph.network import CandidateGraph\n",
"from autocnet.graph.edge import Edge\n",
"from autocnet.vis.graph_view import *\n",
"# from autocnet.matcher.feature import FlannMatcher\n",
"\n",
"import itertools\n",
"import networkx as nx\n",
"import pandas as pd\n",
"from IPython.display import display\n",
"\n",
"import json\n",
"from tinydb import TinyDB, Query\n",
"\n",
"from plio.io.io_autocnetgraph import load as load_graph\n",
"from plio.io.io_autocnetgraph import save as save_graph\n",
"\n",
"%pylab inline"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [],
"source": [
"#Point to the adjacency Graph\n",
"adjacency = get_path('three_image_adjacency.json')\n",
"basepath = get_path('Apollo15')\n",
"cg = CandidateGraph.from_adjacency(adjacency, basepath=basepath)\n",
"\n",
"#Apply SIFT to extract features\n",
"cg.extract_features(extractor_parameters={'nfeatures':800})"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {
"scrolled": false
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"MATCHING COMPLETE ---------------------------------\n",
"updating CG...\n",
"update finished...\n"
]
},
{
"data": {
"text/html": [
"<div>\n",
"<style>\n",
" .dataframe thead tr:only-child th {\n",
" text-align: right;\n",
" }\n",
"\n",
" .dataframe thead th {\n",
" text-align: left;\n",
" }\n",
"\n",
" .dataframe tbody tr th {\n",
" vertical-align: top;\n",
" }\n",
"</style>\n",
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" <th>point_id</th>\n",
" <th>source_image</th>\n",
" <th>destination_image</th>\n",
" <th>source_idx</th>\n",
" <th>match_idx</th>\n",
" <th>x</th>\n",
" <th>y</th>\n",
" </tr>\n",
" <tr>\n",
" <th>m_id</th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>6</th>\n",
" <td>2.0</td>\n",
" <td>0.0</td>\n",
" <td>1.0</td>\n",
" <td>360.0</td>\n",
" <td>4.0</td>\n",
" <td>227.913086</td>\n",
" <td>215.556900</td>\n",
" </tr>\n",
" <tr>\n",
" <th>7</th>\n",
" <td>2.0</td>\n",
" <td>0.0</td>\n",
" <td>1.0</td>\n",
" <td>2.0</td>\n",
" <td>4.0</td>\n",
" <td>7.919065</td>\n",
" <td>219.848343</td>\n",
" </tr>\n",
" <tr>\n",
" <th>8</th>\n",
" <td>2.0</td>\n",
" <td>0.0</td>\n",
" <td>1.0</td>\n",
" <td>113.0</td>\n",
" <td>5.0</td>\n",
" <td>7.919065</td>\n",
" <td>219.848343</td>\n",
" </tr>\n",
" <tr>\n",
" <th>246</th>\n",
" <td>2.0</td>\n",
" <td>0.0</td>\n",
" <td>1.0</td>\n",
" <td>96.0</td>\n",
" <td>192.0</td>\n",
" <td>909.761230</td>\n",
" <td>914.576477</td>\n",
" </tr>\n",
" <tr>\n",
" <th>247</th>\n",
" <td>2.0</td>\n",
" <td>0.0</td>\n",
" <td>1.0</td>\n",
" <td>310.0</td>\n",
" <td>193.0</td>\n",
" <td>697.417786</td>\n",
" <td>919.242798</td>\n",
" </tr>\n",
" <tr>\n",
" <th>368</th>\n",
" <td>2.0</td>\n",
" <td>0.0</td>\n",
" <td>1.0</td>\n",
" <td>151.0</td>\n",
" <td>302.0</td>\n",
" <td>227.913086</td>\n",
" <td>215.556900</td>\n",
" </tr>\n",
" <tr>\n",
" <th>369</th>\n",
" <td>2.0</td>\n",
" <td>0.0</td>\n",
" <td>1.0</td>\n",
" <td>65.0</td>\n",
" <td>303.0</td>\n",
" <td>221.989166</td>\n",
" <td>547.352234</td>\n",
" </tr>\n",
" <tr>\n",
" <th>522</th>\n",
" <td>2.0</td>\n",
" <td>0.0</td>\n",
" <td>1.0</td>\n",
" <td>230.0</td>\n",
" <td>460.0</td>\n",
" <td>227.913086</td>\n",
" <td>215.556900</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1030</th>\n",
" <td>2.0</td>\n",
" <td>0.0</td>\n",
" <td>1.0</td>\n",
" <td>529.0</td>\n",
" <td>1058.0</td>\n",
" <td>227.913086</td>\n",
" <td>215.556900</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" point_id source_image destination_image source_idx match_idx \\\n",
"m_id \n",
"6 2.0 0.0 1.0 360.0 4.0 \n",
"7 2.0 0.0 1.0 2.0 4.0 \n",
"8 2.0 0.0 1.0 113.0 5.0 \n",
"246 2.0 0.0 1.0 96.0 192.0 \n",
"247 2.0 0.0 1.0 310.0 193.0 \n",
"368 2.0 0.0 1.0 151.0 302.0 \n",
"369 2.0 0.0 1.0 65.0 303.0 \n",
"522 2.0 0.0 1.0 230.0 460.0 \n",
"1030 2.0 0.0 1.0 529.0 1058.0 \n",
"\n",
" x y \n",
"m_id \n",
"6 227.913086 215.556900 \n",
"7 7.919065 219.848343 \n",
"8 7.919065 219.848343 \n",
"246 909.761230 914.576477 \n",
"247 697.417786 919.242798 \n",
"368 227.913086 215.556900 \n",
"369 221.989166 547.352234 \n",
"522 227.913086 215.556900 \n",
"1030 227.913086 215.556900 "
]
},
"execution_count": 4,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"edge = cg.edge[0][1] \n",
"edge.match()\n",
"cg.cpoints.query('point_id == 2') "
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"<div>\n",
"<style>\n",
" .dataframe thead tr:only-child th {\n",
" text-align: right;\n",
" }\n",
"\n",
" .dataframe thead th {\n",
" text-align: left;\n",
" }\n",
"\n",
" .dataframe tbody tr th {\n",
" vertical-align: top;\n",
" }\n",
"</style>\n",
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" <th>source_image</th>\n",
" <th>source_idx</th>\n",
" <th>destination_image</th>\n",
" <th>destination_idx</th>\n",
" <th>distance</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>0.0</td>\n",
" <td>9.0</td>\n",
" <td>1.0</td>\n",
" <td>0.0</td>\n",
" <td>205.623444</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1</th>\n",
" <td>0.0</td>\n",
" <td>40.0</td>\n",
" <td>1.0</td>\n",
" <td>0.0</td>\n",
" <td>265.584259</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2</th>\n",
" <td>0.0</td>\n",
" <td>349.0</td>\n",
" <td>1.0</td>\n",
" <td>1.0</td>\n",
" <td>91.032959</td>\n",
" </tr>\n",
" <tr>\n",
" <th>3</th>\n",
" <td>0.0</td>\n",
" <td>267.0</td>\n",
" <td>1.0</td>\n",
" <td>1.0</td>\n",
" <td>235.376297</td>\n",
" </tr>\n",
" <tr>\n",
" <th>4</th>\n",
" <td>0.0</td>\n",
" <td>360.0</td>\n",
" <td>1.0</td>\n",
" <td>2.0</td>\n",
" <td>105.019043</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" source_image source_idx destination_image destination_idx distance\n",
"0 0.0 9.0 1.0 0.0 205.623444\n",
"1 0.0 40.0 1.0 0.0 265.584259\n",
"2 0.0 349.0 1.0 1.0 91.032959\n",
"3 0.0 267.0 1.0 1.0 235.376297\n",
"4 0.0 360.0 1.0 2.0 105.019043"
]
},
"execution_count": 6,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"edge.matches.head() "
]
},
{
"cell_type": "code",
"execution_count": 8,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"updating CG...\n",
"update finished...\n"
]
},
{
"data": {
"text/html": [
"<div>\n",
"<style>\n",
" .dataframe thead tr:only-child th {\n",
" text-align: right;\n",
" }\n",
"\n",
" .dataframe thead th {\n",
" text-align: left;\n",
" }\n",
"\n",
" .dataframe tbody tr th {\n",
" vertical-align: top;\n",
" }\n",
"</style>\n",
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" <th>point_id</th>\n",
" <th>source_image</th>\n",
" <th>destination_image</th>\n",
" <th>source_idx</th>\n",
" <th>match_idx</th>\n",
" <th>x</th>\n",
" <th>y</th>\n",
" </tr>\n",
" <tr>\n",
" <th>m_id</th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>5</th>\n",
" <td>2.0</td>\n",
" <td>0.0</td>\n",
" <td>1.0</td>\n",
" <td>3.0</td>\n",
" <td>10.0</td>\n",
" <td>810.255188</td>\n",
" <td>25.143291</td>\n",
" </tr>\n",
" <tr>\n",
" <th>6</th>\n",
" <td>2.0</td>\n",
" <td>0.0</td>\n",
" <td>1.0</td>\n",
" <td>5.0</td>\n",
" <td>10.0</td>\n",
" <td>587.252502</td>\n",
" <td>18.988146</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" point_id source_image destination_image source_idx match_idx \\\n",
"m_id \n",
"5 2.0 0.0 1.0 3.0 10.0 \n",
"6 2.0 0.0 1.0 5.0 10.0 \n",
"\n",
" x y \n",
"m_id \n",
"5 810.255188 25.143291 \n",
"6 587.252502 18.988146 "
]
},
"execution_count": 8,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"edge.symmetry_check() \n",
"cg.cpoints.query('point_id == 2') "
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"# Point to the adjacency Graph\n",
"adjacency = get_path('three_image_adjacency.json')\n",
"basepath = get_path('Apollo15')\n",
"cg = CandidateGraph.from_adjacency(adjacency, basepath=basepath)\n",
"\n",
"#Apply SIFT to extract features\n",
"cg.extract_features(extractor_parameters={'nfeatures':300})"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {
"scrolled": false
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"MATCHING COMPLETE ---------------------------------\n",
"updating CG...\n",
"update finished...\n",
"MATCHING COMPLETE ---------------------------------\n",
"updating CG...\n",
"update finished...\n",
"MATCHING COMPLETE ---------------------------------\n",
"updating CG...\n",
"update finished...\n"
]
},
{
"data": {
"text/html": [
"<div>\n",
"<style>\n",
" .dataframe thead tr:only-child th {\n",
" text-align: right;\n",
" }\n",
"\n",
" .dataframe thead th {\n",
" text-align: left;\n",
" }\n",
"\n",
" .dataframe tbody tr th {\n",
" vertical-align: top;\n",
" }\n",
"</style>\n",
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" <th>point_id</th>\n",
" <th>source_image</th>\n",
" <th>destination_image</th>\n",
" <th>source_idx</th>\n",
" <th>match_idx</th>\n",
" <th>x</th>\n",
" <th>y</th>\n",
" </tr>\n",
" <tr>\n",
" <th>m_id</th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>6</th>\n",
" <td>2.0</td>\n",
" <td>0.0</td>\n",
" <td>1.0</td>\n",
" <td>711.0</td>\n",
" <td>4.0</td>\n",
" <td>263.777069</td>\n",
" <td>386.623718</td>\n",
" </tr>\n",
" <tr>\n",
" <th>7</th>\n",
" <td>2.0</td>\n",
" <td>0.0</td>\n",
" <td>1.0</td>\n",
" <td>2.0</td>\n",
" <td>4.0</td>\n",
" <td>716.104858</td>\n",
" <td>388.033691</td>\n",
" </tr>\n",
" <tr>\n",
" <th>8</th>\n",
" <td>2.0</td>\n",
" <td>0.0</td>\n",
" <td>1.0</td>\n",
" <td>130.0</td>\n",
" <td>5.0</td>\n",
" <td>716.104858</td>\n",
" <td>388.033691</td>\n",
" </tr>\n",
" <tr>\n",
" <th>957</th>\n",
" <td>2.0</td>\n",
" <td>0.0</td>\n",
" <td>1.0</td>\n",
" <td>475.0</td>\n",
" <td>950.0</td>\n",
" <td>992.194031</td>\n",
" <td>444.741760</td>\n",
" </tr>\n",
" <tr>\n",
" <th>958</th>\n",
" <td>2.0</td>\n",
" <td>0.0</td>\n",
" <td>1.0</td>\n",
" <td>647.0</td>\n",
" <td>951.0</td>\n",
" <td>176.202057</td>\n",
" <td>490.933716</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1213</th>\n",
" <td>2.0</td>\n",
" <td>0.0</td>\n",
" <td>1.0</td>\n",
" <td>654.0</td>\n",
" <td>1308.0</td>\n",
" <td>992.194031</td>\n",
" <td>444.741760</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1561</th>\n",
" <td>2.0</td>\n",
" <td>0.0</td>\n",
" <td>1.0</td>\n",
" <td>637.0</td>\n",
" <td>2874.0</td>\n",
" <td>176.202057</td>\n",
" <td>490.933716</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1838</th>\n",
" <td>2.0</td>\n",
" <td>0.0</td>\n",
" <td>2.0</td>\n",
" <td>238.0</td>\n",
" <td>476.0</td>\n",
" <td>992.194031</td>\n",
" <td>444.741760</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1883</th>\n",
" <td>2.0</td>\n",
" <td>0.0</td>\n",
" <td>2.0</td>\n",
" <td>283.0</td>\n",
" <td>566.0</td>\n",
" <td>992.194031</td>\n",
" <td>444.741760</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2089</th>\n",
" <td>2.0</td>\n",
" <td>0.0</td>\n",
" <td>2.0</td>\n",
" <td>489.0</td>\n",
" <td>978.0</td>\n",
" <td>992.194031</td>\n",
" <td>444.741760</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2108</th>\n",
" <td>2.0</td>\n",
" <td>0.0</td>\n",
" <td>2.0</td>\n",
" <td>508.0</td>\n",
" <td>1016.0</td>\n",
" <td>992.194031</td>\n",
" <td>444.741760</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2327</th>\n",
" <td>2.0</td>\n",
" <td>0.0</td>\n",
" <td>2.0</td>\n",
" <td>727.0</td>\n",
" <td>1454.0</td>\n",
" <td>263.777069</td>\n",
" <td>386.623718</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" point_id source_image destination_image source_idx match_idx \\\n",
"m_id \n",
"6 2.0 0.0 1.0 711.0 4.0 \n",
"7 2.0 0.0 1.0 2.0 4.0 \n",
"8 2.0 0.0 1.0 130.0 5.0 \n",
"957 2.0 0.0 1.0 475.0 950.0 \n",
"958 2.0 0.0 1.0 647.0 951.0 \n",
"1213 2.0 0.0 1.0 654.0 1308.0 \n",
"1561 2.0 0.0 1.0 637.0 2874.0 \n",
"1838 2.0 0.0 2.0 238.0 476.0 \n",
"1883 2.0 0.0 2.0 283.0 566.0 \n",
"2089 2.0 0.0 2.0 489.0 978.0 \n",
"2108 2.0 0.0 2.0 508.0 1016.0 \n",
"2327 2.0 0.0 2.0 727.0 1454.0 \n",
"\n",
" x y \n",
"m_id \n",
"6 263.777069 386.623718 \n",
"7 716.104858 388.033691 \n",
"8 716.104858 388.033691 \n",
"957 992.194031 444.741760 \n",
"958 176.202057 490.933716 \n",
"1213 992.194031 444.741760 \n",
"1561 176.202057 490.933716 \n",
"1838 992.194031 444.741760 \n",
"1883 992.194031 444.741760 \n",
"2089 992.194031 444.741760 \n",
"2108 992.194031 444.741760 \n",
"2327 263.777069 386.623718 "
]
},
"execution_count": 3,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"#Match\n",
"cg.match()\n",
"cg.cpoints.query('point_id == 2')"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [],
"source": [
"#Apply outlier detection\n",
"# cg.symmetry_checks()\n",
"# cg.cpoints.query('point_id == 2')"
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {},
"outputs": [],
"source": [
"# cg.apply_func_to_edges(Edge.ratio_check)\n",
"# cg.cpoints.query('point_id == 2')"
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {},
"outputs": [],
"source": [
"# cg.compute_fundamental_matrices(clean_keys=['symmetry', 'ratio'])\n",
"# cg.cpoints.query('point_id == 2')"
]
},
{
"cell_type": "code",
"execution_count": 60,
"metadata": {},
"outputs": [],
"source": [
"m01 = cg.edge[0][1].matches\n",
"cp = cg.cpoints"
]
},
{
"cell_type": "code",
"execution_count": 61,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"<div>\n",
"<style>\n",
" .dataframe thead tr:only-child th {\n",
" text-align: right;\n",
" }\n",
"\n",
" .dataframe thead th {\n",
" text-align: left;\n",
" }\n",
"\n",
" .dataframe tbody tr th {\n",
" vertical-align: top;\n",
" }\n",
"</style>\n",
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" <th>point_id</th>\n",
" <th>source_image</th>\n",
" <th>destination_image</th>\n",
" <th>source_idx</th>\n",
" <th>match_idx</th>\n",
" <th>x</th>\n",
" <th>y</th>\n",
" </tr>\n",
" <tr>\n",
" <th>m_id</th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>0.0</td>\n",
" <td>0.0</td>\n",
" <td>1.0</td>\n",
" <td>624.0</td>\n",
" <td>0.0</td>\n",
" <td>483.393341</td>\n",
" <td>993.464905</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1</th>\n",
" <td>0.0</td>\n",
" <td>0.0</td>\n",
" <td>1.0</td>\n",
" <td>0.0</td>\n",
" <td>0.0</td>\n",
" <td>746.357971</td>\n",
" <td>156.659271</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2</th>\n",
" <td>0.0</td>\n",
" <td>0.0</td>\n",
" <td>1.0</td>\n",
" <td>413.0</td>\n",
" <td>1.0</td>\n",
" <td>746.357971</td>\n",
" <td>156.659271</td>\n",
" </tr>\n",
" <tr>\n",
" <th>3</th>\n",
" <td>1.0</td>\n",
" <td>0.0</td>\n",
" <td>1.0</td>\n",
" <td>50.0</td>\n",
" <td>2.0</td>\n",
" <td>543.315247</td>\n",
" <td>380.489105</td>\n",
" </tr>\n",
" <tr>\n",
" <th>4</th>\n",
" <td>1.0</td>\n",
" <td>0.0</td>\n",
" <td>1.0</td>\n",
" <td>1.0</td>\n",
" <td>2.0</td>\n",
" <td>985.959290</td>\n",
" <td>384.589508</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" point_id source_image destination_image source_idx match_idx \\\n",
"m_id \n",
"0 0.0 0.0 1.0 624.0 0.0 \n",
"1 0.0 0.0 1.0 0.0 0.0 \n",
"2 0.0 0.0 1.0 413.0 1.0 \n",
"3 1.0 0.0 1.0 50.0 2.0 \n",
"4 1.0 0.0 1.0 1.0 2.0 \n",
"\n",
" x y \n",
"m_id \n",
"0 483.393341 993.464905 \n",
"1 746.357971 156.659271 \n",
"2 746.357971 156.659271 \n",
"3 543.315247 380.489105 \n",
"4 985.959290 384.589508 "
]
},
"execution_count": 61,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"cp.head(5)"
]
},
{
"cell_type": "code",
"execution_count": 62,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"<div>\n",
"<style>\n",
" .dataframe thead tr:only-child th {\n",
" text-align: right;\n",
" }\n",
"\n",
" .dataframe thead th {\n",
" text-align: left;\n",
" }\n",
"\n",
" .dataframe tbody tr th {\n",
" vertical-align: top;\n",
" }\n",
"</style>\n",
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" <th>source_image</th>\n",
" <th>source_idx</th>\n",
" <th>destination_image</th>\n",
" <th>destination_idx</th>\n",
" <th>distance</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>0.0</td>\n",
" <td>624.0</td>\n",
" <td>1.0</td>\n",
" <td>0.0</td>\n",
" <td>291.398346</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1</th>\n",
" <td>0.0</td>\n",
" <td>413.0</td>\n",
" <td>1.0</td>\n",
" <td>0.0</td>\n",
" <td>302.978546</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2</th>\n",
" <td>0.0</td>\n",
" <td>50.0</td>\n",
" <td>1.0</td>\n",
" <td>1.0</td>\n",
" <td>185.628662</td>\n",
" </tr>\n",
" <tr>\n",
" <th>3</th>\n",
" <td>0.0</td>\n",
" <td>152.0</td>\n",
" <td>1.0</td>\n",
" <td>1.0</td>\n",
" <td>195.338165</td>\n",
" </tr>\n",
" <tr>\n",
" <th>4</th>\n",
" <td>0.0</td>\n",
" <td>711.0</td>\n",
" <td>1.0</td>\n",
" <td>2.0</td>\n",
" <td>123.194969</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" source_image source_idx destination_image destination_idx distance\n",
"0 0.0 624.0 1.0 0.0 291.398346\n",
"1 0.0 413.0 1.0 0.0 302.978546\n",
"2 0.0 50.0 1.0 1.0 185.628662\n",
"3 0.0 152.0 1.0 1.0 195.338165\n",
"4 0.0 711.0 1.0 2.0 123.194969"
]
},
"execution_count": 62,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"m01.head(5)"
]
},
{
"cell_type": "code",
"execution_count": 63,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"<div>\n",
"<style>\n",
" .dataframe thead tr:only-child th {\n",
" text-align: right;\n",
" }\n",
"\n",
" .dataframe thead th {\n",
" text-align: left;\n",
" }\n",
"\n",
" .dataframe tbody tr th {\n",
" vertical-align: top;\n",
" }\n",
"</style>\n",
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" <th>source_image</th>\n",
" <th>destination_image</th>\n",
" <th>match_idx</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>0.0</td>\n",
" <td>1.0</td>\n",
" <td>0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1</th>\n",
" <td>0.0</td>\n",
" <td>1.0</td>\n",
" <td>1</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2</th>\n",
" <td>0.0</td>\n",
" <td>1.0</td>\n",
" <td>2</td>\n",
" </tr>\n",
" <tr>\n",
" <th>3</th>\n",
" <td>0.0</td>\n",
" <td>1.0</td>\n",
" <td>3</td>\n",
" </tr>\n",
" <tr>\n",
" <th>4</th>\n",
" <td>0.0</td>\n",
" <td>1.0</td>\n",
" <td>4</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" source_image destination_image match_idx\n",
"0 0.0 1.0 0\n",
"1 0.0 1.0 1\n",
"2 0.0 1.0 2\n",
"3 0.0 1.0 3\n",
"4 0.0 1.0 4"
]
},
"execution_count": 63,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"m01idx = m01.reset_index(drop=False)[['source_image', 'destination_image', 'index']]\n",
"m01idx.columns = ['source_image', 'destination_image', 'match_idx']\n",
"m01idx.head()"
]
},
{
"cell_type": "code",
"execution_count": 64,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"<div>\n",
"<style>\n",
" .dataframe thead tr:only-child th {\n",
" text-align: right;\n",
" }\n",
"\n",
" .dataframe thead th {\n",
" text-align: left;\n",
" }\n",
"\n",
" .dataframe tbody tr th {\n",
" vertical-align: top;\n",
" }\n",
"</style>\n",
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" <th>source_image</th>\n",
" <th>destination_image</th>\n",
" <th>match_idx</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>0.0</td>\n",
" <td>2.0</td>\n",
" <td>0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1</th>\n",
" <td>0.0</td>\n",
" <td>2.0</td>\n",
" <td>1</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2</th>\n",
" <td>0.0</td>\n",
" <td>2.0</td>\n",
" <td>2</td>\n",
" </tr>\n",
" <tr>\n",
" <th>3</th>\n",
" <td>0.0</td>\n",
" <td>2.0</td>\n",
" <td>3</td>\n",
" </tr>\n",
" <tr>\n",
" <th>4</th>\n",
" <td>0.0</td>\n",
" <td>2.0</td>\n",
" <td>4</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" source_image destination_image match_idx\n",
"0 0.0 2.0 0\n",
"1 0.0 2.0 1\n",
"2 0.0 2.0 2\n",
"3 0.0 2.0 3\n",
"4 0.0 2.0 4"
]
},
"execution_count": 64,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"m12idx = cg.edge[0][2].matches.reset_index(drop=False)[['source_image', 'destination_image', 'index']]\n",
"m12idx.columns = ['source_image', 'destination_image', 'match_idx']\n",
"m12idx.head()"
]
},
{
"cell_type": "code",
"execution_count": 96,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"<div>\n",
"<style>\n",
" .dataframe thead tr:only-child th {\n",
" text-align: right;\n",
" }\n",
"\n",
" .dataframe thead th {\n",
" text-align: left;\n",
" }\n",
"\n",
" .dataframe tbody tr th {\n",
" vertical-align: top;\n",
" }\n",
"</style>\n",
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" <th>source_image</th>\n",
" <th>destination_image</th>\n",
" <th>match_idx</th>\n",
" </tr>\n",
" <tr>\n",
" <th>m_id</th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>0.0</td>\n",
" <td>1.0</td>\n",
" <td>0.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1</th>\n",
" <td>0.0</td>\n",
" <td>1.0</td>\n",
" <td>0.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2</th>\n",
" <td>0.0</td>\n",
" <td>1.0</td>\n",
" <td>1.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>3</th>\n",
" <td>0.0</td>\n",
" <td>1.0</td>\n",
" <td>2.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>4</th>\n",
" <td>0.0</td>\n",
" <td>1.0</td>\n",
" <td>2.0</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" source_image destination_image match_idx\n",
"m_id \n",
"0 0.0 1.0 0.0\n",
"1 0.0 1.0 0.0\n",
"2 0.0 1.0 1.0\n",
"3 0.0 1.0 2.0\n",
"4 0.0 1.0 2.0"
]
},
"execution_count": 96,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"cpidx = cp[['source_image', 'destination_image', 'match_idx']] \n",
"cpidx.head()"
]
},
{
"cell_type": "code",
"execution_count": 97,
"metadata": {},
"outputs": [],
"source": [
"mask = pd.Series(np.zeros(cp.shape[0], dtype=bool)) "
]
},
{
"cell_type": "code",
"execution_count": 101,
"metadata": {
"scrolled": false
},
"outputs": [],
"source": [
"mask[pd.merge(cpidx,m12idx, how='inner', left_index=True, on=['source_image', 'destination_image', 'match_idx']).index] = True "
]
},
{
"cell_type": "code",
"execution_count": 99,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"<div>\n",
"<style>\n",
" .dataframe thead tr:only-child th {\n",
" text-align: right;\n",
" }\n",
"\n",
" .dataframe thead th {\n",
" text-align: left;\n",
" }\n",
"\n",
" .dataframe tbody tr th {\n",
" vertical-align: top;\n",
" }\n",
"</style>\n",
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" <th>point_id</th>\n",
" <th>source_image</th>\n",
" <th>destination_image</th>\n",
" <th>source_idx</th>\n",
" <th>match_idx</th>\n",
" <th>x</th>\n",
" <th>y</th>\n",
" </tr>\n",
" <tr>\n",
" <th>m_id</th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>0.0</td>\n",
" <td>0.0</td>\n",
" <td>1.0</td>\n",
" <td>624.0</td>\n",
" <td>0.0</td>\n",
" <td>483.393341</td>\n",
" <td>993.464905</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2</th>\n",
" <td>0.0</td>\n",
" <td>0.0</td>\n",
" <td>1.0</td>\n",
" <td>413.0</td>\n",
" <td>1.0</td>\n",
" <td>746.357971</td>\n",
" <td>156.659271</td>\n",
" </tr>\n",
" <tr>\n",
" <th>4</th>\n",
" <td>1.0</td>\n",
" <td>0.0</td>\n",
" <td>1.0</td>\n",
" <td>1.0</td>\n",
" <td>2.0</td>\n",
" <td>985.959290</td>\n",
" <td>384.589508</td>\n",
" </tr>\n",
" <tr>\n",
" <th>6</th>\n",
" <td>2.0</td>\n",
" <td>0.0</td>\n",
" <td>1.0</td>\n",
" <td>711.0</td>\n",
" <td>4.0</td>\n",
" <td>263.777069</td>\n",
" <td>386.623718</td>\n",
" </tr>\n",
" <tr>\n",
" <th>8</th>\n",
" <td>2.0</td>\n",
" <td>0.0</td>\n",
" <td>1.0</td>\n",
" <td>130.0</td>\n",
" <td>5.0</td>\n",
" <td>716.104858</td>\n",
" <td>388.033691</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" point_id source_image destination_image source_idx match_idx \\\n",
"m_id \n",
"0 0.0 0.0 1.0 624.0 0.0 \n",
"2 0.0 0.0 1.0 413.0 1.0 \n",
"4 1.0 0.0 1.0 1.0 2.0 \n",
"6 2.0 0.0 1.0 711.0 4.0 \n",
"8 2.0 0.0 1.0 130.0 5.0 \n",
"\n",
" x y \n",
"m_id \n",
"0 483.393341 993.464905 \n",
"2 746.357971 156.659271 \n",
"4 985.959290 384.589508 \n",
"6 263.777069 386.623718 \n",
"8 716.104858 388.033691 "
]
},
"execution_count": 99,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"cp[mask].head()"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": 15,
"metadata": {
"scrolled": false
},
"outputs": [],
"source": [
"# def somefunc(x):\n",
"# x[2].matches.index.name = 'match_idx'\n",
"# return x[2].matches.reset_index(drop=False)[['source_image','destination_image', 'match_idx']]\n",
"\n",
"# df = pd.concat(cg.apply(somefunc))\n",
"# df.head()"
]
},
{
"cell_type": "code",
"execution_count": 14,
"metadata": {
"scrolled": false
},
"outputs": [
{
"ename": "NameError",
"evalue": "name 'df' is not defined",
"output_type": "error",
"traceback": [
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
"\u001b[0;31mNameError\u001b[0m Traceback (most recent call last)",
"\u001b[0;32m<ipython-input-14-f410de8656f3>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m()\u001b[0m\n\u001b[0;32m----> 1\u001b[0;31m \u001b[0mcg\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mcpoints\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mmerge\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mdf\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mreset_index\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mdrop\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;32mFalse\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mon\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;34m'source_image'\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m'destination_image'\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m'match_idx'\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mhow\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;34m'left'\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mquery\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m'point_id == 2'\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m",
"\u001b[0;31mNameError\u001b[0m: name 'df' is not defined"
]
}
],
"source": [
"cg.cpoints.merge(df.reset_index(drop=False), on=['source_image','destination_image', 'match_idx'], how='left').query('point_id == 2')"
]
},
{
"cell_type": "code",
"execution_count": 18,
"metadata": {
"scrolled": false
},
"outputs": [
{
"data": {
"text/html": [
"<div>\n",
"<style>\n",
" .dataframe thead tr:only-child th {\n",
" text-align: right;\n",
" }\n",
"\n",
" .dataframe thead th {\n",
" text-align: left;\n",
" }\n",
"\n",
" .dataframe tbody tr th {\n",
" vertical-align: top;\n",
" }\n",
"</style>\n",
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
"Empty DataFrame\n",
"Columns: []\n",
"Index: []"
]
},
"execution_count": 18,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"cg.cpoints"
]
},
{
"cell_type": "code",
"execution_count": 104,
"metadata": {
"collapsed": true,
"scrolled": false
},
"outputs": [],
"source": [
"def subgraph(self, nbunch):\n",
" s = super(CandidateGraph, self)\n",
" sg = s.subgraph(nbunch)\n",
" self.nodemask = sg.nodes()\n",
" \n",
"def nodes_iter(self, data=False):\n",
" s = super(CandidateGraph, self)\n",
" return (node for node in s.nodes_iter(data) if node in self.nodemask)\n",
"\n",
"def edges_iter(self, nbunch=[], data=False, key=False):\n",
" s = super(CandidateGraph, self)\n",
" nbunch.extend(self.nodemask)\n",
" print(nbunch)\n",
" return s.edges_iter(nbunch, data,key)\n",
" \n",
" "
]
},
{
"cell_type": "code",
"execution_count": 110,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"cg.subgraph = subgraph\n",
"cg.nodes_iter = nodes_iter\n",
"cg.edges_iter = edges_iter"
]
},
{
"cell_type": "code",
"execution_count": 10,
"metadata": {
"scrolled": false
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"dict_keys([])\n",
"None\n",
"[None]\n",
"try\n"
]
}
],
"source": [
"cg.subgraph([0])"
]
},
{
"cell_type": "code",
"execution_count": 11,
"metadata": {
"scrolled": false
},
"outputs": [
{
"data": {
"text/plain": [
"[0]"
]
},
"execution_count": 11,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"cg.nodemask"
]
},
{
"cell_type": "code",
"execution_count": 266,
"metadata": {
"scrolled": false
},
"outputs": [
{
"data": {
"text/plain": [
"[(0,\n",
" \n",
" NodeID: 0\n",
" Image Name: AS15-M-0297_SML.png\n",
" Image PATH: /Users/krodriguez/repos/autocnet/autocnet/examples/Apollo15/AS15-M-0297_SML.png\n",
" Number Keypoints: 800\n",
" Available Masks : Empty DataFrame\n",
"Columns: []\n",
"Index: []\n",
" Type: <class 'autocnet.graph.node.Node'>\n",
" ),\n",
" (1,\n",
" \n",
" NodeID: 1\n",
" Image Name: AS15-M-0299_SML.png\n",
" Image PATH: /Users/krodriguez/repos/autocnet/autocnet/examples/Apollo15/AS15-M-0299_SML.png\n",
" Number Keypoints: 800\n",
" Available Masks : Empty DataFrame\n",
"Columns: []\n",
"Index: []\n",
" Type: <class 'autocnet.graph.node.Node'>\n",
" ),\n",
" (2,\n",
" \n",
" NodeID: 2\n",
" Image Name: AS15-M-0298_SML.png\n",
" Image PATH: /Users/krodriguez/repos/autocnet/autocnet/examples/Apollo15/AS15-M-0298_SML.png\n",
" Number Keypoints: 800\n",
" Available Masks : Empty DataFrame\n",
"Columns: []\n",
"Index: []\n",
" Type: <class 'autocnet.graph.node.Node'>\n",
" )]"
]
},
"execution_count": 266,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"list(cg.nodes_iter(data=True))"
]
},
{
"cell_type": "code",
"execution_count": 267,
"metadata": {
"scrolled": true
},
"outputs": [],
"source": [
"# globals()['test'] = 'hello'"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": 272,
"metadata": {},
"outputs": [],
"source": [
"func.__kwdefaults__ = {'hello':'test'}"
]
},
{
"cell_type": "code",
"execution_count": 273,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"test\n"
]
}
],
"source": [
"func()"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"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.5.3"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment