問題
ubuntu16.4で動画処理をしたいと思い
bash
1pip install opencv-python
でopencv3.3.0
を導入しました
python
1import numpy as np 2import cv2 3import sys 4 5fps = 30 6resize_rate = 1 7 8video_input = cv2.VideoCapture('test.mp4') 9if(video_input.isOpened() == False): 10 print(video_input.isOpened()) 11 exit() 12 13count = 0 14while(True): 15 print(count) 16 count += 1 17 count_padded = '%05d' % count 18 ret,frame = video_input.read() 19 20 height,width = frame.shape[:2] 21 small_frame = cv2.resize(frame, (int(width/resize_rate), int(height/resize_rate))) 22 23 cv2.imshow('frame', small_frame) 24 c = cv2.waitKey(int(1000/fps)) & 0xFF 25 26 write_file_name = count_padded + ".jpg" 27 cv2.imwrite(write_file_name, small_frame) 28 29 if c==27: # ESC 30 break 31 32
上記のプログラム内のvideo_input = cv2.VideoCapture('test.mp4)
で動画を開こうとしているのですが
video_input.isOpened()
が常にFalseになってしまいます
下記のプログラムは正常に動作し、動くのでopencvのインストール失敗ということはなさそうです
python
1 2import numpy as np 3import cv2 4 5img = cv2.imread('test.jpeg') 6print(img) 7
環境
$ cat /etc/lsb-release DISTRIB_ID=Ubuntu DISTRIB_RELEASE=16.04 DISTRIB_CODENAME=xenial DISTRIB_DESCRIPTION="Ubuntu 16.04.3 LTS" $ python --version Python 3.6.0 :: Anaconda 4.3.1 (64-bit)
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2017/09/26 07:04
2017/09/26 09:52