程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式師世界 >> 編程語言 >  >> 更多編程語言 >> Python

Python + opencv create simple gradient

編輯:Python
 First, determine the initial color and end color of the gradient
This paper selects the initial color (10,250,25) Stop color (255,92,0), Can be found in ps View in , As shown in the figure below :
First create a matrix ,500*500
From the initial color to the end color is the gradient process , Each point corresponds to RGB Values are gradient process values .
As shown in the picture , Each row rgb equally , Each column rgb The gradient
about opencv Description of color in :
arr[x,y,B]=XX
arr[x,y,G]=XX
arr[x,y,R]=XX
Then you can write the following python sentence
import cv2
import numpy
arr=numpy.ones((500,500,3),dtype=numpy.uint8)
for r in range(500):
for g in range(500):
arr[r, :, 0] = 10 + r / 500 * 230
arr[r, :, 1] = 250 - g / 500 *160
arr[r, :, 2] = 25- g / 500 * 25
img = cv2.cvtColor(arr,cv2.COLOR_BGR2RGB )
cv2.resize(img,(500,500))
cv2.imshow("ceshi",img)
key=cv2.waitKey(0)
if key==27: # Press esc Key time , Close all windows
print(key)
cv2.imwrite("./Gradient.jpg",img)# Save the picture
cv2.destroyAllWindows()
cv2.destroyAllWindows()

  The result is as follows :

 


  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式師世界 All Rights Reserved