๐ ๋ณธ ์์ ๋ Window10์ VSCode, Python3.11.0๋ก ์์ฑ๋์์ต๋๋ค.
"์ง์ "์ ๊ทธ๋ฆฌ๋ ํจ์๋ "line" ๋ฉ์๋๋ฅผ ์ฌ์ฉํ๋ฉด ๋๋ค.
import cv2
import numpy as np
# ํฐ๋ฐฐ๊ฒฝ์ ๋น ์ด๋ฏธ์ง ์์ฑ(512 x 512)
white_background = np.ones((512,512),dtype=np.uint8) * 255
# ์ง์
cv2.line(
img=white_background,
pt1=(0,0),
pt2=(256,256),
color=100,
thickness=3,
lineType=cv2.LINE_4,
shift=0)
cv2.imshow("line",white_background)
cv2.waitKey(0)
cv2.destroyAllWindows()
๋งค๊ฐ๋ณ์๋ ๋ค์๊ณผ ๊ฐ๋ค.
- img : ๊ทธ๋ฆด np.array
- pt1 : ์์ ์ขํ
- pt2 : ๋ ์ขํ
- color : ์
- thickness : ์ ๊ตต๊ธฐ
- lineType : ์ ํ์ (cv2.LINE_4, cv2.LINE_8, cv2.LINE_AA)
- shift : ๊ทธ๋ฆฌ๊ธฐ ์ขํ๊ฐ์ ์ถ์ ๋น์จ
"ํ์ดํ ์ง์ "์ "arrowedLine" ๋ฉ์๋๋ฅผ ์ฌ์ฉํ๋ฉด ๋๋ค.
import cv2
import numpy as np
# ํฐ๋ฐฐ๊ฒฝ์ ๋น ์ด๋ฏธ์ง ์์ฑ(512 x 512)
white_background = np.ones((512,512),dtype=np.uint8) * 255
# ํ์ดํ
cv2.arrowedLine(
img=white_background,
pt1=(0,0),
pt2=(256,256),
color=100,
thickness=3,
line_type=cv2.LINE_AA,
shift=0,
tipLength=0.2
)
cv2.imshow("arrow",white_background)
cv2.waitKey(0)
cv2.destroyAllWindows()
๋งค๊ฐ๋ณ์๋ ๋ค์๊ณผ ๊ฐ๋ค.
- img : ๊ทธ๋ฆด np.array
- pt1 : ์์ ์ขํ
- pt2 : ๋ ์ขํ
- color : ์
- thickness : ์ ๊ตต๊ธฐ
- lineType : ์ ํ์ (cv2.LINE_4, cv2.LINE_8, cv2.LINE_AA)
- shift : ๊ทธ๋ฆฌ๊ธฐ ์ขํ๊ฐ์ ์ถ์ ๋น์จ
- tipLength : ํ์ดํ ๋ชจ์์ ๊ธธ์ด
"๋ง์ปค"์ "drawMarker" ๋ฉ์๋๋ฅผ ์ฌ์ฉํ๋ฉด ๋๋ค.
import cv2
import numpy as np
# ํฐ๋ฐฐ๊ฒฝ์ ๋น ์ด๋ฏธ์ง ์์ฑ(512 x 512)
white_background = np.ones((512,512),dtype=np.uint8) * 255
# ๋ง์ปค
cv2.drawMarker(
img=white_background,
position=(50,50),
color=0,
markerType=cv2.MARKER_DIAMOND,
markerSize=20,
thickness=3,
line_type=cv2.LINE_8
)
cv2.imshow("Marker",white_background)
cv2.waitKey(0)
cv2.destroyAllWindows()
๋งค๊ฐ๋ณ์๋ ๋ค์๊ณผ ๊ฐ๋ค.
- img : ๊ทธ๋ฆด np.array
- position : ๊ทธ๋ฆด ์ขํ
- color : ์
- markerType : ๋ง์ปค์ ์ข ๋ฅ(cv2.MARKER_DIAMONE, ...)
- markerSize : ๋ง์ปค์ ํฌ๊ธฐ
- thickness : ์ ๊ตต๊ธฐ
- lineType : ์ ํ์ (cv2.LINE_4, cv2.LINE_8, cv2.LINE_AA)
"์ฌ๊ฐํ"์ "rectangle"์ ์ฌ์ฉํ๋ค.
import cv2
import numpy as np
background = np.ones((512,512,3),dtype=np.uint8) * 255 # BGR ์ฑ๋
# ์ฌ๊ฐํ
cv2.rectangle(
img=background,
pt1 = (50,50),
pt2 = (250,250),
color=(255,0,0),
thickness=1,
lineType=cv2.LINE_AA,
shift=0
)
cv2.imshow("rectangle",background)
cv2.waitKey(0)
cv2.destroyAllWindows()
๋งค๊ฐ๋ณ์๋ ๋ค์๊ณผ ๊ฐ๋ค.
- img : ๊ทธ๋ฆด np.array
- pt1 : ์์ ์ขํ
- pt2 : ๋ ์ขํ
- color : ์
- thickness : ์ ๊ตต๊ธฐ
- lineType : ์ ํ์ (cv2.LINE_4, cv2.LINE_8, cv2.LINE_AA)
- shift : ๊ทธ๋ฆฌ๊ธฐ ์ขํ๊ฐ์ ์ถ์ ๋น์จ
"์"์ "circle"์ ์ฌ์ฉํ๋ค.
import cv2
import numpy as np
background = np.ones((512,512,3),dtype=np.uint8) * 255 # RGB ์ฑ๋
cv2.circle(
img=background,
center=(256,256),
radius=50,
color=(0,255,0),
thickness=3,
lineType=cv2.LINE_8,
shift=0
)
cv2.imshow("circle",background)
cv2.waitKey(0)
cv2.destroyAllWindows()
๋งค๊ฐ๋ณ์๋ ๋ค์๊ณผ ๊ฐ๋ค.
- img : ๊ทธ๋ฆด np.array
- center : ์ค์ฌ์ ์ขํ
- radius : ๋ฐ์ง๋ฆ
- color : ์
- thickness : ์ ๊ตต๊ธฐ
- lineType : ์ ํ์ (cv2.LINE_4, cv2.LINE_8, cv2.LINE_AA)
- shift : ๊ทธ๋ฆฌ๊ธฐ ์ขํ๊ฐ์ ์ถ์ ๋น์จ
"ํ์"์ "ellipse"๋ฅผ ์ฌ์ฉํ๋ค.
import cv2
import numpy as np
background = np.ones((512,512,3),dtype=np.uint8) * 255 # RGB ์ฑ๋
cv2.ellipse(
img=background,
center=(256,256),
axes=(170,100),
angle=0,
startAngle=0,
endAngle=360,
color=(0,255,100),
thickness=3,
lineType=cv2.LINE_AA,
shift=0
)
cv2.imshow("ellipse",background)
cv2.waitKey(0)
cv2.destroyAllWindows()
๋งค๊ฐ๋ณ์๋ ๋ค์๊ณผ ๊ฐ๋ค.
- img : ๊ทธ๋ฆด np.array
- center : ์ค์ฌ์ ์ขํ
- axes : (x๋ฐ์ง๋ฆ, y๋ฐ์ง๋ฆ)
- angle : ํ์ ํ์ ๊ฐ๋(x์ถ ๊ธฐ์ค, ์๊ณ ๋ฐฉํฅ)
- startAngle : ํ์ ํธ์ ์์ ๊ฐ๋(x์ถ๊ธฐ์ค, ์๊ณ๋ฐฉํฅ)
- endAngle : ํ์ ํธ์ ๋ ๊ฐ๋(y์ถ ๊ธฐ์ค, ์๊ณ ๋ฐฉํฅ)
- color : ์
- thickness : ์ ๊ตต๊ธฐ
- lineType : ์ ํ์ (cv2.LINE_4, cv2.LINE_8, cv2.LINE_AA)
- shift : ๊ทธ๋ฆฌ๊ธฐ ์ขํ๊ฐ์ ์ถ์ ๋น์จ
"๋ค๊ฐํ"์ ๊ทธ๋ฆด๋๋ "polylines"๋ฅผ ์ฌ์ฉํ๋ค.
import cv2
import numpy as np
background = np.zeros((512,512,3),dtype=np.uint8) # RGB ์ฑ๋
points = np.array([[[10,10],[170,10],[200,230],[70,70],[50,150]]],dtype=np.int32)
cv2.polylines(
img=background,
pts=points,
isClosed=True,
color=(255,255,0),
thickness=2,
lineType=cv2.LINE_AA,
shift=0
)
cv2.imshow("polylines",background)
cv2.waitKey(0)
cv2.destroyAllWindows()
๋งค๊ฐ๋ณ์๋ ๋ค์๊ณผ ๊ฐ๋ค.
- img : ๊ทธ๋ฆด np.array
- pts : ํด๋ฆฌ๊ณค ์ขํ ๋ฐฐ์ด
- isClosed : True ์ ๋ซํ ๋ํ
- color : ์
- thickness : ์ ๊ตต๊ธฐ
- lineType : ์ ํ์ (cv2.LINE_4, cv2.LINE_8, cv2.LINE_AA)
- shift : ๊ทธ๋ฆฌ๊ธฐ ์ขํ๊ฐ์ ์ถ์ ๋น์จ
"๋ณผ๋ก ๋ค๊ฐํ"์ ๊ทธ๋ฆด๋๋ "fillConvexPoly"๋ฅผ ์ฌ์ฉํ๋ค.
import cv2
import numpy as np
background = np.zeros((512,512,3),dtype=np.uint8) # RGB ์ฑ๋
points = np.array([[[10,10],[170,10],[200,230],[70,70],[50,150]]],dtype=np.int32)
# ๋ณผ๋ก ๋ค๊ฐํ
cv2.fillConvexPoly(
img=background,
points=points,
color=(102,100,24),
lineType=cv2.LINE_8,
shift=0
)
cv2.imshow("fill Poly",background)
cv2.waitKey(0)
cv2.destroyAllWindows()
๋งค๊ฐ๋ณ์๋ ๋ค์๊ณผ ๊ฐ๋ค.
- img : ๊ทธ๋ฆด np.array
- points : ํด๋ฆฌ๊ณค ์ขํ ๋ฐฐ์ด
- axes : (x๋ฐ์ง๋ฆ, y๋ฐ์ง๋ฆ)
- color : ์
- lineType : ์ ํ์ (cv2.LINE_4, cv2.LINE_8, cv2.LINE_AA)
- shift : ๊ทธ๋ฆฌ๊ธฐ ์ขํ๊ฐ์ ์ถ์ ๋น์จ
'AI > Computer Vision' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[Computer Vision] ์์์ ๋ช ์ ์ ์ด (0) | 2024.08.28 |
---|---|
[Computer Vision] ํ ์คํธ ์ฝ์ ๋ฐ ์ ์ฉํ ๊ธฐ๋ฅ (0) | 2024.08.28 |
[Computer Vision] ๊ธฐ๋ณธ ์ฌ์ฉ๋ฒ (0) | 2024.08.27 |
[Computer Vision] Inpainting (0) | 2024.03.25 |
[Computer Vision] DreamBooth (0) | 2024.03.11 |