Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | |||
5 | 6 | 7 | 8 | 9 | 10 | 11 |
12 | 13 | 14 | 15 | 16 | 17 | 18 |
19 | 20 | 21 | 22 | 23 | 24 | 25 |
26 | 27 | 28 | 29 | 30 | 31 |
Tags
- libopencv-dev
- translation
- Winform
- NodeMCU
- sshkey
- vim명령어
- c#
- 정보처리기사
- Google Drive API
- Python
- 아두이노
- vtk
- rotation
- google drive 업로드
- vi
- 고정ip할당
- api사용해서 google drive에 폴더만들기
- opencv
- google drive upload
- apt update
- opencv apt설치
- esp32
- 아두이노 설치
- opencv resize
- opengl
- 정보처리기사후기
- 우분투 opencv 설치
- annotating
- ubuntu
- vim
Archives
- Today
- Total
내가 보려고 만든 블로그
OpenCV를 사용하여 이미지에 주석 달기(python) 본문
반응형
# Import dependencies
import cv2
# Read Images
img = cv2.imread('Lenna.png')
# Print error message if image is null
if img is None:
print('Could not read image')
# Draw line on image
imageLine = img.copy()
#Draw the image from point A to B
pointA = (200,80)
pointB = (450,80)
cv2.line(imageLine, pointA, pointB, (255, 255, 0), thickness=3, lineType=cv2.LINE_AA)
# Draw circle
imageCircle = img.copy()
# define the center of circle
circle_center = (300,280)
# define the radius of the circle
radius =100
# Draw a circle using the circle() Function
cv2.circle(imageCircle, circle_center, radius, (0, 0, 255), thickness=3, lineType=cv2.LINE_AA)
#Draw Filled Circle
imageFilledCircle = img.copy()
# draw the filled circle on input image
cv2.circle(imageFilledCircle, circle_center, radius, (255, 0, 0), thickness=-1, lineType=cv2.LINE_AA)
#Draw Rectangle
imageRectangle = img.copy()
# define the starting and end points of the rectangle
start_point =(120,100)
end_point =(430,405)
# draw the rectangle
cv2.rectangle(imageRectangle, start_point, end_point, (0, 0, 255), thickness= 3, lineType=cv2.LINE_8)
#Draw an Ellipse
imageEllipse = img.copy()
# define the center point of ellipse
ellipse_center = (300,280)
# define the major and minor axes of the ellipse
axis1 = (100,50)
axis2 = (125,50)
# draw the ellipse
#Horizontal
cv2.ellipse(imageEllipse, ellipse_center, axis1, 0, 0, 360, (255, 0, 0), thickness=3)
#Vertical
cv2.ellipse(imageEllipse, ellipse_center, axis2, 90, 0, 360, (0, 0, 255), thickness=3)
#Draw a Half-Ellipse
halfEllipse = img.copy()
# define the axis point
axis1 = (100,50)
# draw the Incomplete/Open ellipse, just a outline
cv2.ellipse(halfEllipse, ellipse_center, axis1, 0, 180, 360, (255, 0, 0), thickness=3)
# if you want to draw a Filled ellipse, use this line of code
cv2.ellipse(halfEllipse, ellipse_center, axis1, 0, 0, 180, (0, 0, 255), thickness=-2)
#Adding Text
imageText = img.copy()
#let's write the text you want to put on the image
text = 'I am Lenna!'
#org: Where you want to put the text
org = (120,400)
# write the text on the input image
cv2.putText(imageText, text, org, fontFace = cv2.FONT_HERSHEY_COMPLEX, fontScale = 1.5, color = (250,225,100))
# Display Image
cv2.imshow('Original Image',img)
cv2.imshow('Image Line', imageLine)
cv2.imshow("Image Circle",imageCircle)
cv2.imshow('Image with Filled Circle',imageFilledCircle)
cv2.imshow('imageRectangle', imageRectangle)
cv2.imshow('ellipse Image',imageEllipse)
cv2.imshow('halfEllipse',halfEllipse)
cv2.imshow("Image Text",imageText)
cv2.waitKey(0)
반응형
'OpenCV > python' 카테고리의 다른 글
OpenCV를 사용한 이미지 Rotation, Translation(python) (0) | 2024.05.31 |
---|---|
OpenCV를 사용하여 이미지 자르기(python) (0) | 2024.05.30 |
OpenCV를 사용한 이미지 크기 조정(python) (0) | 2024.05.29 |
OpenCV를 사용하여 이미지 읽기, 표시 및 쓰기(python) (0) | 2024.05.27 |