Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/opencv/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用opencv从python绘制m层六边形网格_Python_Opencv_Image Processing_Line - Fatal编程技术网

使用opencv从python绘制m层六边形网格

使用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)

我已经在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):
    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()