show | version | enable_checker |
---|---|---|
step |
1.0 |
true |
- 上次研究了三角函数
- 画正余弦曲线
- 画圆
- 还可以画点什么吗?🤔
import numpy as np
import cv2
canvas = np.zeros((300,300,3), np.uint8)
pts = np.array([[100,50],[200,50],[250,250],[50,250]],np.int32)
canvas = cv2.polylines(canvas,[pts],False,(0,0,255),5)
cv2.imshow("PolyLines",canvas)
cv2.waitKey()
cv2.destroyAllWindows()
- 绘制结果
- 如何理解不封闭呢?
import cv2
help(cv2.polylines)
- 观察参数列表
- 如果将isClosed封闭会如何呢?
import numpy as np
import cv2
canvas = np.zeros((300,300,3), np.uint8)
pts = np.array([[100,50],[200,50],[250,250],[50,250]],np.int32)
canvas = cv2.polylines(canvas,[pts],True,(0,0,255),5)
cv2.imshow("PolyLines",canvas)
cv2.waitKey()
cv2.destroyAllWindows()
- 还是四个点的列表
- 梯形封闭了
- 交换Points的位置会如何呢?
import numpy as np
import cv2
canvas = np.zeros((300,300,3), np.uint8)
pts = np.array([[100,50],[200,50],[50,250],[250,250]],np.int32)
canvas = cv2.polylines(canvas,[pts],True,(0,0,255),5)
cv2.imshow("PolyLines",canvas)
cv2.waitKey()
cv2.destroyAllWindows()
- 出现了神奇的图形
- 如果让点随机起来 会如何呢?
import numpy as np
import cv2
canvas = np.zeros((300,300,3), np.uint8)
point_list = []
for num in range(30):
pos = np.random.randint(0,300,size=(2,)).tolist()
point_list.append(pos)
pts = np.array(point_list,np.int32)
canvas = cv2.polylines(canvas,[pts],True,(0,0,255),5)
cv2.imshow("PolyLines",canvas)
cv2.waitKey()
cv2.destroyAllWindows()
- 循环30次
- 每次产生一个点
- 出现了神奇的画面
- 可以为图形填色吗?
import numpy as np
import cv2
canvas = np.zeros((300,300,3), np.uint8)
pts = np.array([[100,50],[200,50],[250,250],[50,250]],np.int32)
canvas = cv2.polylines(canvas,[pts],True,(0,0,255),5)
canvas = cv2.fillConvexPoly(canvas, pts, (200,200,200))
cv2.imshow("PolyLines",canvas)
cv2.waitKey()
cv2.destroyAllWindows()
- 通过四个顶点
- 画出了梯形
- 可以绘制更复杂一些的图形吗?
- 想要绘制如下的图形
- 应该如何编写代码呢?
import numpy as np
import cv2
canvas = np.zeros((300,300,3), np.uint8)
pts = np.array([[150,30],[50,100],[50,150],[100,100],[100,200],[200,200],[200,100],[250,150],[250,100]],np.int32)
canvas = cv2.polylines(canvas,[pts],True,(0,0,255),5)
cv2.imshow("PolyLines",canvas)
cv2.waitKey()
cv2.destroyAllWindows()
- 可以写一个字母A吗?
import numpy as np
import cv2
canvas = np.zeros((300,300,3), np.uint8)
shapes = []
shapes.append(np.array([[140,50],[50,250],[70,250],[160,50]],np.int32))
shapes.append(np.array([[140,50],[230,250],[250,250],[160,50]],np.int32))
shapes.append(np.array([[90,180],[210,180],[210,200],[90,200]],np.int32))
for shape in shapes:
canvas = cv2.fillConvexPoly(canvas,shape,(0,0,255))
cv2.imshow("PolyLines",canvas)
cv2.waitKey()
cv2.destroyAllWindows()
- 可以绘制更多字符吗?
- 西文字符
- E、F、I、K
- L、M、N、T
- W、X、Y、Z
- 中文字符
- 可、口、中、意
- 这次研究了
- 多边形的绘制与填色
- 还可以绘制各种字符效果
- 甚至可以加上衬线🤔
- 对了 好像我们也
- 可以直接输出字符的😳
- 直接输出字符会有什么好玩的吗?🤡
- 下次再说👋