我就廢話不多說了,大家還是直接看代碼吧!mrC免費資源網
import time
import numpy as np
import cv2
python怎樣填充顏色。#方法一
start = time.time()
for i in range(1000):
canvas = np.zeros((1080,1920,3), np.uint8)
canvas[:,:,0] = 113
turtle庫如何填充顏色、canvas[:,:,1] = 207
canvas[:,:,2] = 250
end = time.time()
print ("方法一(切片賦值)時間:",end-start)
cv2.imwrite("test1.png",canvas)
python用turtle畫圓并填色,#方法二
start = time.time()
for i in range(1000):
canvas = np.zeros((1080,1920,3), np.uint8)
cv2.rectangle(canvas, (0, 0), (1920, 1080), (113,207,250), thickness=-1)
python算法大全,end = time.time()
print ("方法二(Opencv顏色填充)時間:",end-start)
cv2.imwrite("test2.png",canvas)
#方法三
start = time.time()
python中隱藏畫筆的代碼、for i in range(1000):
canvas = np.ones([1080,1920,3])*[113,207,250]
end = time.time()
print ("方法三(矩陣乘法)時間:",end-start)
cv2.imwrite("test3.png",canvas)
python菜鳥教程。# #方法四
start = time.time()
for i in range(1000):
canvas = np.zeros((1080,1920,3), np.uint8)
for i in range(1080):
使用while循環輸出100以內的偶數、for j in range(1920):
canvas[i][j] = [113,207,250]
end = time.time()
print ("方法四(循環遍歷賦值)時間:",end-start)
cv2.imwrite("test4.png",canvas)
編程怎么填充顏色。結果mrC免費資源網
方法一(切片賦值)時間: 6.554100275039673mrC免費資源網
方法二(Opencv顏色填充)時間: 3.6737191677093506mrC免費資源網
方法三(矩陣乘法)時間: 74.28376317024231mrC免費資源網
方法四(循環遍歷賦值)時間: 3245.07548809051504mrC免費資源網
python中ceil函數的用法?補充知識:規則多邊形顏色填充(Python)mrC免費資源網
以規則八邊型為例:
import matplotlib.pyplot as plt
import numpy as np
# 設置八邊形頂點坐標
x = [0, 0, 5, 10, 15, 15, 10, 5]
y = [5, 10, 15, 15, 10, 5, 0, 0]
# 通過調用 fill() 函數 完成繪制八邊形
# 參數 x 和 y 是用來繪制封閉區域頂點的有序坐標集
# 參數 color 用來指定封閉區域的填充顏色
plt.fill(x, y, color="green")
# 為了可視化效果更好,使用函數 xlim() 和 ylim() 完成多邊型在整個坐標軸中的相對位置調整(可自行刪除對比效果)
plt.xlim(-1, 17)
plt.ylim(-1, 17)
# 使用 xticks() 和 yticks() 調整刻度線的顯示位置
# np.arange(起始坐標,結束坐標,坐標間隔)
plt.xticks(np.arange(0, 16, 5))
plt.yticks(np.arange(0, 16, 5))
# 調用 show() 函數展示圖形的繪制效果
plt.show()
mrC免費資源網
版权声明:本站所有资料均为网友推荐收集整理而来,仅供学习和研究交流使用。
工作时间:8:00-18:00
客服电话
电子邮件
admin@qq.com
扫码二维码
获取最新动态