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

質問編集履歴

5

windowsエラーの詳細

2019/10/09 06:40

投稿

aqufiz
aqufiz

スコア70

title CHANGED
File without changes
body CHANGED
@@ -11,6 +11,8 @@
11
11
  OpenCVのバージョンをpython -m pip install opencv-pythonで更新してみたり,
12
12
  vscodeではなく,直接Pythonから実行などを試していたところ
13
13
  vscodeでqを押して終了すると,そこでプログラムが終了せずに止まってしまうようになりました.
14
+ そして,このような状態になってしまってからは"1/1: 0... success (1920x1080 at 30.00 FPS)."の
15
+ FPSは0と表示されています.
14
16
 
15
17
  ターミナルの表示はこのようになっています
16
18
  ```

4

Windowsのエラー追加

2019/10/09 06:40

投稿

aqufiz
aqufiz

スコア70

title CHANGED
File without changes
body CHANGED
@@ -6,8 +6,11 @@
6
6
  何か解決方法があれば,教えていただきたいです.
7
7
  よろしくお願いいたします.
8
8
 
9
- **追記
9
+ 追記
10
- Windowsのvscodeで実行したところこのエラーは起きませんでした.**
10
+ ~~Windowsのvscodeで実行したところこのエラーは起きませんでした~~
11
+ OpenCVのバージョンをpython -m pip install opencv-pythonで更新してみたり,
12
+ vscodeではなく,直接Pythonから実行などを試していたところ
13
+ vscodeでqを押して終了すると,そこでプログラムが終了せずに止まってしまうようになりました.
11
14
 
12
15
  ターミナルの表示はこのようになっています
13
16
  ```

3

エラーの追加

2019/10/09 06:37

投稿

aqufiz
aqufiz

スコア70

title CHANGED
File without changes
body CHANGED
@@ -9,6 +9,34 @@
9
9
  **追記
10
10
  Windowsのvscodeで実行したところこのエラーは起きませんでした.**
11
11
 
12
+ ターミナルの表示はこのようになっています
13
+ ```
14
+ Namespace(cfg='cfg/yolov3.cfg', conf_thres=0.3, data='data/coco.data', device='', fourcc='mp4v', half=False, img_size=416, nms_thres=0.5, output='output', source='0', view_img=False, weights='weights/yolov3.weights')
15
+ Using CUDA device0 _CudaDeviceProperties(name='Xavier', total_memory=15698MB)
16
+
17
+ 1/1: 0... success (1920x1080 at 30.00 FPS).
18
+
19
+
20
+ QStandardPaths: wrong ownership on runtime directory /run/user/1000, 1000 instead of 0
21
+ 0: 256x416 1 persons, 1 bottles, Done. (0.075s)
22
+ 0: 256x416 1 persons, 1 bottles, Done. (0.072s)
23
+ 0: 256x416 1 persons, 1 bottles, Done. (0.072s)
24
+ 0: 256x416 1 persons, 1 bottles, Done. (0.072s)
25
+ 0: 256x416 1 persons, 1 bottles, Done. (0.073s)
26
+ 0: 256x416 1 persons, 1 bottles, Done. (0.074s)
27
+ 0: 256x416 1 persons, 1 bottles, Done. (0.072s)
28
+ 0: 256x416 1 persons, 1 bottles, Done. (0.072s)
29
+ 0: 256x416 1 persons, 1 bottles, Done. (0.071s)
30
+
31
+
32
+
33
+
34
+ "ここでqを押す”
35
+ Done. (21.684s)
36
+ FATAL: exception not rethrown
37
+ Aborted
38
+ ```
39
+
12
40
  ```Python
13
41
  class LoadStreams: # multiple IP or RTSP cameras
14
42
  def __init__(self, sources='streams.txt', img_size=416, half=False):

2

追記

2019/10/09 06:32

投稿

aqufiz
aqufiz

スコア70

title CHANGED
File without changes
body CHANGED
@@ -6,6 +6,9 @@
6
6
  何か解決方法があれば,教えていただきたいです.
7
7
  よろしくお願いいたします.
8
8
 
9
+ **追記
10
+ Windowsのvscodeで実行したところこのエラーは起きませんでした.**
11
+
9
12
  ```Python
10
13
  class LoadStreams: # multiple IP or RTSP cameras
11
14
  def __init__(self, sources='streams.txt', img_size=416, half=False):

1

間違ったcodeの変更

2019/10/09 03:53

投稿

aqufiz
aqufiz

スコア70

title CHANGED
File without changes
body CHANGED
@@ -7,80 +7,69 @@
7
7
  よろしくお願いいたします.
8
8
 
9
9
  ```Python
10
- class LoadImages: # for inference
10
+ class LoadStreams: # multiple IP or RTSP cameras
11
- def __init__(self, path, img_size=416, half=False):
11
+ def __init__(self, sources='streams.txt', img_size=416, half=False):
12
- path = str(Path(path)) # os-agnostic
13
- files = []
14
- if os.path.isdir(path):
15
- files = sorted(glob.glob(os.path.join(path, '*.*')))
16
- elif os.path.isfile(path):
12
+ self.mode = 'images'
17
- files = [path]
18
-
19
- images = [x for x in files if os.path.splitext(x)[-1].lower() in img_formats]
20
- videos = [x for x in files if os.path.splitext(x)[-1].lower() in vid_formats]
21
- nI, nV = len(images), len(videos)
22
-
23
13
  self.img_size = img_size
24
- self.files = images + videos
25
- self.nF = nI + nV # number of files
26
- self.video_flag = [False] * nI + [True] * nV
27
- self.mode = 'images'
28
14
  self.half = half # half precision fp16 images
15
+
29
- if any(videos):
16
+ if os.path.isfile(sources):
30
- self.new_video(videos[0]) # new video
17
+ with open(sources, 'r') as f:
18
+ sources = [x.strip() for x in f.read().splitlines() if len(x.strip())]
31
19
  else:
32
- self.cap = None
20
+ sources = [sources]
33
- assert self.nF > 0, 'No images or videos found in ' + path
34
21
 
22
+ n = len(sources)
23
+ self.imgs = [None] * n
24
+ self.sources = sources
25
+ for i, s in enumerate(sources):
26
+ # Start the thread to read frames from the video stream
27
+ print('%g/%g: %s... ' % (i + 1, n, s), end='')
28
+ cap = cv2.VideoCapture(0 if s == '0' else s)
29
+ #if s == '0':
30
+ #cap.set(3,1280)
31
+ #cap.set(4,720)
32
+ assert cap.isOpened(), 'Failed to open %s' % s
33
+ w = int(cap.get(cv2.CAP_PROP_FRAME_WIDTH))
34
+ h = int(cap.get(cv2.CAP_PROP_FRAME_HEIGHT))
35
+ fps = cap.get(cv2.CAP_PROP_FPS) % 100
36
+ _, self.imgs[i] = cap.read() # guarantee first frame
37
+ thread = Thread(target=self.update, args=([i, cap]), daemon=True)
38
+ print(' success (%gx%g at %.2f FPS).' % (w, h, fps))
39
+ thread.start()
40
+ print('') # newline
41
+
42
+ def update(self, index, cap):
43
+ # Read next stream frame in a daemon thread
44
+ while cap.isOpened():
45
+ _, self.imgs[index] = cap.read()
46
+ time.sleep(0.030) # 33.3 FPS to keep buffer empty
47
+
35
48
  def __iter__(self):
36
- self.count = 0
49
+ self.count = -1
37
50
  return self
38
51
 
39
52
  def __next__(self):
40
- if self.count == self.nF:
53
+ self.count += 1
54
+ img0 = self.imgs.copy()
55
+ if cv2.waitKey(1) == ord('q'): # q to quit
56
+ cv2.destroyAllWindows()
41
57
  raise StopIteration
42
- path = self.files[self.count]
43
58
 
44
- if self.video_flag[self.count]:
45
- # Read video
59
+ # Letterbox
46
- self.mode = 'video'
47
- ret_val, img0 = self.cap.read()
48
- if not ret_val:
49
- self.count += 1
50
- self.cap.release()
51
- if self.count == self.nF: # last video
60
+ img = [letterbox(x, new_shape=self.img_size)[0] for x in img0]
52
- raise StopIteration
53
- else:
54
- path = self.files[self.count]
55
- self.new_video(path)
56
- ret_val, img0 = self.cap.read()
57
61
 
62
+ # Stack
58
- self.frame += 1
63
+ img = np.stack(img, 0)
59
- print('video %g/%g (%g/%g) %s: ' % (self.count + 1, self.nF, self.frame, self.nframes, path), end='')
60
64
 
61
- else:
62
- # Read image
63
- self.count += 1
64
- img0 = cv2.imread(path) # BGR
65
- assert img0 is not None, 'Image Not Found ' + path
66
- print('image %g/%g %s: ' % (self.count, self.nF, path), end='')
67
-
68
- # Padded resize
69
- img, *_ = letterbox(img0, new_shape=self.img_size)
70
-
71
65
  # Normalize RGB
72
- img = img[:, :, ::-1].transpose(2, 0, 1) # BGR to RGB
66
+ img = img[:, :, :, ::-1].transpose(0, 3, 1, 2) # BGR to RGB
73
67
  img = np.ascontiguousarray(img, dtype=np.float16 if self.half else np.float32) # uint8 to fp16/fp32
74
68
  img /= 255.0 # 0 - 255 to 0.0 - 1.0
75
69
 
76
- # cv2.imwrite(path + '.letterbox.jpg', 255 * img.transpose((1, 2, 0))[:, :, ::-1]) # save letterbox image
77
- return path, img, img0, self.cap
70
+ return self.sources, img, img0, None
78
71
 
79
- def new_video(self, path):
72
+ def __len__(self):
80
- self.frame = 0
81
- self.cap = cv2.VideoCapture(path)
82
- self.nframes = int(self.cap.get(cv2.CAP_PROP_FRAME_COUNT))
73
+ return 0 # 1E12 frames = 32 streams at 30 FPS for 30 years
83
74
 
84
- def __len__(self):
85
- return self.nF # number of files
86
75
  ```