所以我正在尝试使用一个接收角度并以该角度间隔绘制线条的函数制作image that looks like this。我编写了代码,生成了看起来像但不太像的图像,使用三角函数计算线的距离,并使用opencv的.line函数绘制线:
def drawImg(ang):
image = np.zeros((500,500), np.uint8) #black 500x500 matrix
ang*=np.pi/180 #convert angle to radians
origAng=ang
adj=250 #distance between the middle and the edge of the frame which is
#the triangle adjacent side
x=250
negx=250
while(x<500): #draw lines until x reaches the edge of the frame
opos=adj*np.tan(ang) #triangle opposite side calculation
#which is the distance between lines
cv2.line(image,(negx,500),(x,0),255,1) #1 pixel thick white line draw
cv2.line(image,(x,500),(negx,0),255,1)
negx-=int(opos) #increment x variables and angle
x+=int(opos)
ang+=origAng
#same thing for the y axis
ang=origAng
y=250
negy=250
while(y<500):
opos=adj*np.tan(ang)
cv2.line(image,(0,negy),(500,y),250,1)
cv2.line(image,(0,y),(500,negy),250,1)
negy-=int(opos)
y+=int(opos)
ang+=origAng
cv2.imshow('img',image)
cv2.waitKey(0)
cv2.destroyAllWindows()
如果有人知道如何使其更接近我想要的图像,我会非常感谢您的帮助。