質問編集履歴

3

追記3

2020/07/16 05:42

投稿

satosato
satosato

スコア20

test CHANGED
File without changes
test CHANGED
@@ -145,3 +145,31 @@
145
145
 
146
146
 
147
147
  長くなりましたが、何卒よろしくお願いします。
148
+
149
+
150
+
151
+ 【追記3】
152
+
153
+ ```Python
154
+
155
+ import cv2
156
+
157
+ import os
158
+
159
+ ```
160
+
161
+ に変更したところ
162
+
163
+ > エラー
164
+
165
+ Traceback (most recent call last):
166
+
167
+ File "camera.py", line 2, in <module>
168
+
169
+ import cv2
170
+
171
+ ImportError: No module named 'cv2'
172
+
173
+
174
+
175
+ となりました。

2

追記2

2020/07/16 05:42

投稿

satosato
satosato

スコア20

test CHANGED
File without changes
test CHANGED
@@ -113,3 +113,35 @@
113
113
  To avoid this problem you can invoke Python with '-m pip' instead of running pip directly.
114
114
 
115
115
  pip 20.1.1 from /home/pi/.local/lib/python3.5/site-packages/pip (python 3.5)
116
+
117
+
118
+
119
+ 【追記2】
120
+
121
+ 上記はPython2で実行しました。
122
+
123
+ 上記の開発環境構築の手順は以下の通りです。
124
+
125
+ > 開発環境構築手順
126
+
127
+ $ apt -y install libopencv-dev python-opencv
128
+
129
+ $ pip install -U pip
130
+
131
+
132
+
133
+ また、Python3での実行を試みたところ、以下のエラーが出ました。
134
+
135
+ > エラーメッセージPython3
136
+
137
+ Traceback (most recent call last):
138
+
139
+ File "camera.py", line 2, in <module>
140
+
141
+ import cv2, os
142
+
143
+ ImportError: No module named 'cv2'
144
+
145
+
146
+
147
+ 長くなりましたが、何卒よろしくお願いします。

1

追記

2020/07/16 05:39

投稿

satosato
satosato

スコア20

test CHANGED
File without changes
test CHANGED
@@ -9,3 +9,107 @@
9
9
  import cv2, os
10
10
 
11
11
  ImportError: /usr/lib/arm-linux-gnueabihf/libopencv_legacy.so.2.4: undefined symbol: _ZN2kv14Fernlassifmms4readEVKN?_8FileNodeE
12
+
13
+
14
+
15
+ 【追記】ソースコードと各種バージョンは以下の通りです。
16
+
17
+
18
+
19
+ ```Python
20
+
21
+ from datetime import datetime
22
+
23
+ import cv2, os
24
+
25
+
26
+
27
+ def main():
28
+
29
+
30
+
31
+ current_dir = os.path.dirname(os.path.abspath(__file__)) + '/'
32
+
33
+
34
+
35
+ cam = cv2.VideoCapture(0)
36
+
37
+ if cam == None:
38
+
39
+ return False
40
+
41
+
42
+
43
+ while True:
44
+
45
+ _, img = cam.read()
46
+
47
+
48
+
49
+ shoot_time = datetime.now()
50
+
51
+ image_file = current_dir + shoot_time.strftime('%Y%m%d_%H%M%S%f') +'.jpg'
52
+
53
+
54
+
55
+ cv2.imwrite(image_file, img)
56
+
57
+
58
+
59
+ if cv2.waitKey(1) == 13: break
60
+
61
+
62
+
63
+ cam.release()
64
+
65
+ cv2.destroyAllWindows()
66
+
67
+
68
+
69
+ if __name__ == '__main__':
70
+
71
+ main()
72
+
73
+
74
+
75
+ ```
76
+
77
+
78
+
79
+ > 各種バージョン
80
+
81
+ $ apt search opencv | grep -e libopencv-dev -e python-opencv
82
+
83
+ WARNING: apt does not have a stable CLI interface. Use with caution in scripts.
84
+
85
+ libopencv-dev/oldstable,now 2.4.9.1+dfsg1-2 armhf [インストール済み]
86
+
87
+ python-opencv/oldstable,now 2.4.9.1+dfsg1-2 armhf [インストール済み]
88
+
89
+ $ python -V
90
+
91
+ Python 2.7.13
92
+
93
+ $ python3 -V
94
+
95
+ Python 3.5.3
96
+
97
+ $pip -V
98
+
99
+ WARNING: pip is being invoked by an old script wrapper. This will fail in a future version of pip.
100
+
101
+ Please see https://github.com/pypa/pip/issues/5599 for advice on fixing the underlying issue.
102
+
103
+ To avoid this problem you can invoke Python with '-m pip' instead of running pip directly.
104
+
105
+ pip 20.1.1 from /home/pi/.local/lib/python2.7/site-packages/pip (python 2.7)
106
+
107
+ $ pip3 -V
108
+
109
+ WARNING: pip is being invoked by an old script wrapper. This will fail in a future version of pip.
110
+
111
+ Please see https://github.com/pypa/pip/issues/5599 for advice on fixing the underlying issue.
112
+
113
+ To avoid this problem you can invoke Python with '-m pip' instead of running pip directly.
114
+
115
+ pip 20.1.1 from /home/pi/.local/lib/python3.5/site-packages/pip (python 3.5)