5
4

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 3 years have passed since last update.

OpenCVでオートフォーカスWebカメラのフォーカスを設定する(Python)

Posted at

OpenCVでオートフォーカスWebカメラのフォーカスを変更する方法です。

LogicoolのC922n(オートフォーカスかつ60FPS出る)を買ったので試してみました。

フォーカス値は0~250の範囲で5刻みに設定できるようです。
フォーカス値を大きくしていくと、近くにピントが合います。

import cv2

cap = cv2.VideoCapture(0)
# 画像サイズを設定
cap.set(cv2.CAP_PROP_FRAME_WIDTH, 640)
cap.set(cv2.CAP_PROP_FRAME_HEIGHT, 360)
# FPSを設定
cap.set(cv2.CAP_PROP_FPS, 60)
# オートフォーカスをオフ
cap.set(cv2.CAP_PROP_AUTOFOCUS, 0)
# フォーカス値を設定
cap.set(cv2.CAP_PROP_FOCUS, 0)

# 映像を表示
while cap.isOpened():
    _, img = cap.read()
    cv2.imshow("manual_focus", img)
    key = cv2.waitKey(1)
    # qキーを押すと終了
    if key == ord('q'):
        break
cv2.destroyAllWindows()
cap.release()
5
4
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
5
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?