質問内容,環境
openCVのVideoCaptureでカメラの映像を取得できません
・macos
・spyder
(クラムシェルモードで使用)
発生している問題・エラーメッセージ
[ WARN:0@0.009] global /private/var/folders/nz/j6p8yfhx1mv_0grj5xl4650h0000gp/T/abs_d9lyif19nl/croot/opencv-suite_1676472756314/work/modules/videoio/src/cap_gstreamer.cpp (862) isPipelinePlaying OpenCV | GStreamer warning: GStreamer: pipeline have not been created OpenCV: not authorized to capture video (status 0), requesting... Fatal Python error: Aborted Main thread: Thread 0x00000001e3cdde00 (most recent call first): File "/ユーザー名/Library/CloudStorage/クラウド名\u72ec\u7acb\u884c\u653f\u6cd5\u4eba\u56fd\u7acb\u9ad8\u7b49\u5c02\u9580\u5b66\u6821\u6a5f\u69cb/\u30c7\u30b9\u30af\u30c8\u30c3\u30d7/spyder/保存ファイル名.py", line 11 in <module> File "/ユーザー名/anaconda3/lib/python3.10/site-packages/spyder_kernels/py3compat.py", line 356 in compat_exec File "/ユーザー名/anaconda3/lib/python3.10/site-packages/spyder_kernels/customize/spydercustomize.py", line 473 in exec_code File "/ユーザー名/anaconda3/lib/python3.10/site-packages/spyder_kernels/customize/spydercustomize.py", line 615 in _exec_file File "/ユーザー名/anaconda3/lib/python3.10/site-packages/spyder_kernels/customize/spydercustomize.py", line 528 in runfile File "/var/folders/tc/lkwdg48j6k5bbl2mg_blgzqw0000gn/T/ipykernel_14548/3951762717.py", line 1 in <module>
該当のソースコード
python
1import cv2 2 3cap = cv2.VideoCapture(0) 4 5if not cap.isOpened(): 6 print("カメラが開けませんでした。") 7 exit() 8 9while True: 10 ret, frame = cap.read() 11 12 if not ret: 13 print("映像を取得できませんでした。") 14 break 15 16 cv2.imshow('Camera', frame) 17 18 if cv2.waitKey(1) & 0xFF == ord('q'): 19 break 20 21cap.release() 22cv2.destroyAllWindows()
試したこと
ターミナルで,カメラの識別子があっていることを確認しました.
