python 日本就業
Read basics of the drawing/image processing in python: Drawing flag of Thailand
閱讀python中繪圖/圖像處理的基礎知識: 泰國的繪圖標志
The national flag of Japan is a rectangular white banner bearing a crimson-red disc at its center. This flag is officially called Nisshōki but is more commonly known in Japan as Hinomaru. It embodies the country's sobriquet: Land of the Rising Sun.
日本的國旗是矩形的白色橫幅,其中心帶有深紅色的圓盤。 該旗幟正式被稱為Nisshōki,但在日本更廣為人知。 它體現了該國的縮寫:旭日之國。
Steps:
腳步:
First, we make a matrix of dimensions 300 X 600 X 3. Where the number of pixels of rows is 300, the number of pixels of columns is 600 and 3 represent the number of dimensions of the color coding in BGR format.
首先,我們制作一個尺寸為300 X 600 X 3的矩陣。如果行的像素數為300,則列的像素數為600,而3表示BGR格式的顏色編碼的維數。
Paint the complete image with white color. BGR code for White is (255,255,255).
用白色繪制整個圖像。 白色的BGR代碼是(255,255,255)。
Apply loop on rows and columns and implement the equation of the circle such that we get a circle in the center of the flag and color it crimson glory using RGB format.
在行和列上應用循環并實現圓的方程,這樣我們就可以在標志的中心得到一個圓,并使用RGB格式為其著色為深紅色。
Equation of circle:
圓方程:
((x-h)^2 - (y-k)^2)=r^2
Where (h, k) are the centres, (x, y) are co-ordinates of x-axis and y-axis and r is the radius of the circle.
其中(h,k)是中心, (x,y)是x軸和y軸的坐標, r是圓的半徑。
bgrcode for crimson glory color is (45, 0, 188).
深紅色的榮耀顏色的bgrcode是( 45,0,188 )。
Python代碼繪制日本國旗 (Python code to draw flag of Japan)
# import numpy library as np
import numpy as np
# import open-cv library
import cv2
# import sqrt function from the math module
from math import sqrt
# here image is of class 'uint8', the range of values
# that each colour component can have is [0 - 255]
# create a zero matrix of order 300x600 of 3-dimensions
flag = np.zeros((300, 600, 3),np.uint8)
# take coordinate of the circle
center_x, center_y = 150, 300
# take radius of the circle
radius = 50
# fill whole pixels of dimensions
# with White color
flag[:, :, :] = 255;
# Draw a circle with crimson glory color
# loop for rows i.e. for x-axis
for i in range(101,201) :
# loop for columns i.e. for y-axis
for j in range(251, 351) :
#applying the equation of circle to make the circle in the center.
distance = sqrt((center_x - i)**2 + (center_y - j)**2)
if distance <= radius :
# fill the circle with crimson glory
# color using RGB color representation.
flag[i, j, 0] = 45
flag[i, j, 1] = 0
flag[i, j, 2] = 188
# Show the image formed
cv2.imshow("Japan Flag",flag);
Output
輸出量

翻譯自: https://www.includehelp.com/python/drawing-flag-of-japan-image-processing-in-python.aspx
python 日本就業