0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

始点と終点を指定することで線が描けます

import cv2

img = cv2.imread("bird.jpg")

img = cv2.line(img,(210,80),(240,30),(255,0,0),1) # source, start, end, color, line width
img = cv2.line(img,(230,100),(280,50),(255,0,0),1)
img = cv2.line(img,(250,120),(320,70),(255,0,0),1)

cv2.imshow(img)

bird.jpg ダウンロード (48).png

テキストも描けます

import cv2

img = cv2.imread("bird.jpg")

cv2.putText(img,
            text="I am a bird.",
            org=(210,80),
            fontFace=cv2.FONT_HERSHEY_SIMPLEX,
            fontScale=0.7,
            color=(0, 255, 0),
            thickness=2,
            lineType=cv2.LINE_4)

cv2.imshow(img)

ダウンロード (49).png

時計を描いてみる

import cv2
import math

img = cv2.imread("bird.jpg")
h, w = img.shape[:2]
center_x = w / 2
center_y = h / 2
center = (int(center_x),int(center_y))
rad = int(w / 3)

for i in range(0,12):
  point = (int(center_x + rad * math.cos(math.radians(i*30))),int(center_y + rad * math.sin(math.radians(i*30))))
  img = cv2.line(img,center,point,(255,0,0),1)
  cv2.putText(img,
            text=str(i),
            org=point,
            fontFace=cv2.FONT_HERSHEY_SIMPLEX,
            fontScale=1.0,
            color=(0, 255, 0),
            thickness=2,
            lineType=cv2.LINE_4)

cv2.imshow(img)

ダウンロード (50).png

🐣


フリーランスエンジニアです。
お仕事のご相談こちらまで
rockyshikoku@gmail.com

Core MLやARKitを使ったアプリを作っています。
機械学習/AR関連の情報を発信しています。

Twitter
Medium
GitHub

0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?