Create ComponentTree skel
This commit is contained in:
parent
6446dc37eb
commit
76f49ac72b
3
.gitignore
vendored
Normal file
3
.gitignore
vendored
Normal file
@ -0,0 +1,3 @@
|
||||
*.pyc
|
||||
img/
|
||||
res/
|
27
ComponentTree.py
Executable file
27
ComponentTree.py
Executable file
@ -0,0 +1,27 @@
|
||||
#!/usr/bin/python
|
||||
# -*- coding: utf-8 -*-
|
||||
# \file ComponentTree.py
|
||||
# \brief TODO
|
||||
# \author Florent Guiotte <florent.guiotte@gmail.com>
|
||||
# \version 0.1
|
||||
# \date 10 oct. 2017
|
||||
#
|
||||
# TODO details
|
||||
|
||||
import collections
|
||||
|
||||
class ComponentTree:
|
||||
def __init__(self, parent=None):
|
||||
self.parent = parent
|
||||
self.children = dict()
|
||||
|
||||
def __iter__(self):
|
||||
return self.children.__iter__()
|
||||
|
||||
def main():
|
||||
tree = ComponentTree()
|
||||
for i in tree:
|
||||
print(i)
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
33
Tree.py
33
Tree.py
@ -9,6 +9,8 @@
|
||||
# TODO details
|
||||
|
||||
import collections
|
||||
import cv2
|
||||
import ipdb
|
||||
|
||||
#class Node:
|
||||
# def __init__(self, val):
|
||||
@ -23,13 +25,13 @@ def Tree():
|
||||
|
||||
def walk(node):
|
||||
"""iterate tree in pre-order depth"""
|
||||
if isinstance(node, str): yield "+-" + node
|
||||
if not isinstance(node, str):
|
||||
if not isinstance(node, collections.defaultdict): yield "+-{}".format(node)
|
||||
if isinstance(node, collections.defaultdict):
|
||||
for child in node.values():
|
||||
for n in walk(child):
|
||||
yield "| " + n
|
||||
|
||||
if __name__ == "__main__":
|
||||
def helloworld():
|
||||
t = Tree()
|
||||
t[1] = "test"
|
||||
t[2][1] = "yoyo"
|
||||
@ -41,13 +43,32 @@ if __name__ == "__main__":
|
||||
|
||||
x = Tree()
|
||||
t[5] = x
|
||||
for i in range(256):
|
||||
for i in range(25):
|
||||
y = Tree()
|
||||
for j in range(10000):
|
||||
for j in range(10):
|
||||
x[j] = "quto"
|
||||
y['parent'] = x
|
||||
x['a'] = y
|
||||
x = y
|
||||
|
||||
|
||||
for i in walk(t):
|
||||
print(i)
|
||||
|
||||
def maxtree():
|
||||
img = cv2.imread('img/lena.ppm', 0)
|
||||
print(img)
|
||||
root = Tree()
|
||||
index = 0
|
||||
for i in img:
|
||||
for j in i:
|
||||
root[index] = j
|
||||
index += 1
|
||||
|
||||
for i in walk(root):
|
||||
print(i)
|
||||
|
||||
print(root)
|
||||
|
||||
if __name__ == "__main__":
|
||||
helloworld()
|
||||
#maxtree()
|
||||
|
Loading…
Reference in New Issue
Block a user