0

以下の方法で、Windowsで接続されているカメラのIDは取得できるようですが、カメラデバイスの名前は取得できません。
デバイスの名前を取得する方法があれば知りたいです。

import cv2

for i1 in range(0, 20): 
    cap1 = cv2.VideoCapture( i1, cv2.CAP_DSHOW )
    if cap1.isOpened(): 
        print("VideoCapture(", i1, ") : Found")
    else:
        print("VideoCapture(", i1, ") : None")
    cap1.release() 

Pythonの実行環境は、WinPythonとPython 3.10.4です。

3
  • 1
    これは役に立ちますか?github.com/pvys/CV-camera-finder 2022年12月27日 0:17
  • ありがとうございます。実行環境がWinPythonなせいか分からないですが、指定されたモジュールが見つからないと表示され実行できませんでした。File "C:\Users\user\Documents\WPy64-31040\python-3.10.4.amd64\lib\site-packages\cvxopt\__init__.py", line 52, in <module>import cvxopt.base ImportError: DLL load failed while importing base: 指定されたモジュールが見つかりません。
    – taichi
    2022年12月27日 0:58
  • 1
    それはおそらくこちらの記事でしょう。import cvxopt.base --- ImportError: DLL load failed: The specified module could not be found 使用している版数のPythonのLibrary\binフォルダをPATHに追加してみてはどうでしょう? あるいはこちら Windows - CVXOPT の Python 3.5+ の記述に従って準備をするとか?
    – kunif
    2022年12月27日 1:19

1 件の回答 1

1

以下により,カメラ名を一覧できました.

import subprocess
import re

output = (
    subprocess.check_output(["powershell.exe", 'Get-PnpDevice -Class "Image"'])
    .decode("utf-8")
)

camera_infos = output.splitlines()[3:-2]

cameras = [re.split(r"\s{2,}", camera)[2] for camera in camera_infos]
print(cameras)

output: PowerShellから取得した全カメラ情報の文字列
camera_infos:各カメラ情報を要素に持つリスト
camerascamera_infosからカメラ名だけに絞ったリスト

この質問に回答するには、ログインする必要があります。

求めていた回答ではありませんか? のタグが付いた他の質問を参照する。