使用opencv从python绘制m层六边形网格
我已经在python中从networkx为m层六边形晶格创建了一个代码,我想在白色背景上使用opencv,使用函数line和circle为蓝色边(厚度1)和红色顶点(半径为2的磁盘)重复同样的操作使用opencv从python绘制m层六边形网格,python,opencv,image-processing,line,Python,Opencv,Image Processing,Line,我已经在python中从networkx为m层六边形晶格创建了一个代码,我想在白色背景上使用opencv,使用函数line和circle为蓝色边(厚度1)和红色顶点(半径为2的磁盘)重复同样的操作 import networkx as nx import matplotlib.pyplot as plt def node_dist(x,y, cx, cy): return abs(cx-x) + abs(cy-y) def remove_unwanted_nodes(G, m)
import networkx as nx
import matplotlib.pyplot as plt
def node_dist(x,y, cx, cy):
return abs(cx-x) + abs(cy-y)
def remove_unwanted_nodes(G, m):
cx, cy = m-0.5, 2*m -(m%2)
unwanted = []
for n in G.nodes:
x,y = n
if node_dist(x,y, cx, cy) > 2*m:
unwanted.append(n)
for n in unwanted:
G.remove_node(n)
return G
m = 4
G = nx.hexagonal_lattice_graph(2*m-1,2*m-1, periodic=False,
with_positions=True,
create_using=None)
pos = nx.get_node_attributes(G, 'pos')
G = remove_unwanted_nodes(G, m)
plt.figure(figsize=(8,8))
nx.draw(G, pos=pos, with_labels=True)
plt.show()