teratail header banner
teratail header banner
質問するログイン新規登録

質問編集履歴

3

追記3

2020/07/16 05:42

投稿

satosato
satosato

スコア20

title CHANGED
File without changes
body CHANGED
@@ -71,4 +71,18 @@
71
71
  import cv2, os
72
72
  ImportError: No module named 'cv2'
73
73
 
74
- 長くなりましたが、何卒よろしくお願いします。
74
+ 長くなりましたが、何卒よろしくお願いします。
75
+
76
+ 【追記3】
77
+ ```Python
78
+ import cv2
79
+ import os
80
+ ```
81
+ に変更したところ
82
+ > エラー
83
+ Traceback (most recent call last):
84
+ File "camera.py", line 2, in <module>
85
+ import cv2
86
+ ImportError: No module named 'cv2'
87
+
88
+ となりました。

2

追記2

2020/07/16 05:42

投稿

satosato
satosato

スコア20

title CHANGED
File without changes
body CHANGED
@@ -55,4 +55,20 @@
55
55
  WARNING: pip is being invoked by an old script wrapper. This will fail in a future version of pip.
56
56
  Please see https://github.com/pypa/pip/issues/5599 for advice on fixing the underlying issue.
57
57
  To avoid this problem you can invoke Python with '-m pip' instead of running pip directly.
58
- pip 20.1.1 from /home/pi/.local/lib/python3.5/site-packages/pip (python 3.5)
58
+ pip 20.1.1 from /home/pi/.local/lib/python3.5/site-packages/pip (python 3.5)
59
+
60
+ 【追記2】
61
+ 上記はPython2で実行しました。
62
+ 上記の開発環境構築の手順は以下の通りです。
63
+ > 開発環境構築手順
64
+ $ apt -y install libopencv-dev python-opencv
65
+ $ pip install -U pip
66
+
67
+ また、Python3での実行を試みたところ、以下のエラーが出ました。
68
+ > エラーメッセージPython3
69
+ Traceback (most recent call last):
70
+ File "camera.py", line 2, in <module>
71
+ import cv2, os
72
+ ImportError: No module named 'cv2'
73
+
74
+ 長くなりましたが、何卒よろしくお願いします。

1

追記

2020/07/16 05:39

投稿

satosato
satosato

スコア20

title CHANGED
File without changes
body CHANGED
@@ -3,4 +3,56 @@
3
3
  Traceback (most recent call last):
4
4
  File "camera.py", line 2, in <module>
5
5
  import cv2, os
6
- ImportError: /usr/lib/arm-linux-gnueabihf/libopencv_legacy.so.2.4: undefined symbol: _ZN2kv14Fernlassifmms4readEVKN?_8FileNodeE
6
+ ImportError: /usr/lib/arm-linux-gnueabihf/libopencv_legacy.so.2.4: undefined symbol: _ZN2kv14Fernlassifmms4readEVKN?_8FileNodeE
7
+
8
+ 【追記】ソースコードと各種バージョンは以下の通りです。
9
+
10
+ ```Python
11
+ from datetime import datetime
12
+ import cv2, os
13
+
14
+ def main():
15
+
16
+ current_dir = os.path.dirname(os.path.abspath(__file__)) + '/'
17
+
18
+ cam = cv2.VideoCapture(0)
19
+ if cam == None:
20
+ return False
21
+
22
+ while True:
23
+ _, img = cam.read()
24
+
25
+ shoot_time = datetime.now()
26
+ image_file = current_dir + shoot_time.strftime('%Y%m%d_%H%M%S%f') +'.jpg'
27
+
28
+ cv2.imwrite(image_file, img)
29
+
30
+ if cv2.waitKey(1) == 13: break
31
+
32
+ cam.release()
33
+ cv2.destroyAllWindows()
34
+
35
+ if __name__ == '__main__':
36
+ main()
37
+
38
+ ```
39
+
40
+ > 各種バージョン
41
+ $ apt search opencv | grep -e libopencv-dev -e python-opencv
42
+ WARNING: apt does not have a stable CLI interface. Use with caution in scripts.
43
+ libopencv-dev/oldstable,now 2.4.9.1+dfsg1-2 armhf [インストール済み]
44
+ python-opencv/oldstable,now 2.4.9.1+dfsg1-2 armhf [インストール済み]
45
+ $ python -V
46
+ Python 2.7.13
47
+ $ python3 -V
48
+ Python 3.5.3
49
+ $pip -V
50
+ WARNING: pip is being invoked by an old script wrapper. This will fail in a future version of pip.
51
+ Please see https://github.com/pypa/pip/issues/5599 for advice on fixing the underlying issue.
52
+ To avoid this problem you can invoke Python with '-m pip' instead of running pip directly.
53
+ pip 20.1.1 from /home/pi/.local/lib/python2.7/site-packages/pip (python 2.7)
54
+ $ pip3 -V
55
+ WARNING: pip is being invoked by an old script wrapper. This will fail in a future version of pip.
56
+ Please see https://github.com/pypa/pip/issues/5599 for advice on fixing the underlying issue.
57
+ To avoid this problem you can invoke Python with '-m pip' instead of running pip directly.
58
+ pip 20.1.1 from /home/pi/.local/lib/python3.5/site-packages/pip (python 3.5)