#概要
OpenCV2で
cap = cv2.VideoCapture('movie.avi')
frames = int(cap.get(cv2.cv.CV_CAP_PROP_FRAME_COUNT))
といった感じで処理していた部分をOpenCV3に切り替えたらエラーを吐かれるので、
cap = cv2.VideoCapture('movie.avi')
frames = int(cap.get(7))
に切り替えたら解決する。
要は現在のOpenCV3(3.2)ではVideocaptureクラスまわりの関数の説明で、プロップID(propId)とされている部分(CV_CAP_PROP_XXX)が各々対応した0~18の数字に切り替えられたという話。
#対応表
propId name | propId No. | Description |
---|---|---|
CV_CAP_PROP_POS_MSEC | 0 | Current position of the video file in milliseconds. |
CV_CAP_PROP_POS_FRAMES | 1 | 0-based index of the frame to be decoded/captured next. |
CV_CAP_PROP_POS_AVI_RATIO | 2 | Relative position of the video file: 0 - start of the film, 1 - end of the film. |
CV_CAP_PROP_FRAME_WIDTH | 3 | Width of the frames in the video stream. |
CV_CAP_PROP_FRAME_HEIGHT | 4 | Height of the frames in the video stream. |
CV_CAP_PROP_FPS | 5 | Frame rate. |
CV_CAP_PROP_FOURCC | 6 | 4-character code of codec. |
CV_CAP_PROP_FRAME_COUNT | 7 | Number of frames in the video file. |
CV_CAP_PROP_FORMAT | 8 | Format of the Mat objects returned by retrieve(). |
CV_CAP_PROP_MODE | 9 | Backend-specific value indicating the current capture mode. |
CV_CAP_PROP_BRIGHTNESS | 10 | Brightness of the image (only for cameras). |
CV_CAP_PROP_CONTRAST | 11 | Contrast of the image (only for cameras). |
CV_CAP_PROP_SATURATION | 12 | Saturation of the image (only for cameras). |
CV_CAP_PROP_HUE | 13 | Hue of the image (only for cameras). |
CV_CAP_PROP_GAIN | 14 | Gain of the image (only for cameras). |
CV_CAP_PROP_EXPOSURE | 15 | Exposure (only for cameras). |
CV_CAP_PROP_CONVERT_RGB | 16 | Boolean flags indicating whether images should be converted to RGB. |
CV_CAP_PROP_WHITE_BALANCE | 17 | Currently unsupported. |
CV_CAP_PROP_RECTIFICATION | 18 | Rectification flag for stereo cameras (note: only supported by DC1394 v 2.x backend currently). |
追記、OpenCVがマイナーチェンジしているので、若干古い情報となっています。今は使えますが気をつけてください。