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 :