1

I pip-installed opencv-python and now I can do import cv2. But import cv fails:

ImportError: No module named 'cv'

I need cv because API of some classes, for example VideoCapture, require constants that are defined there.

Zoe
  • 27,060
  • 21
  • 118
  • 148
grześ
  • 467
  • 3
  • 21
  • You have a code which is for old opencv. Install opencv version 2.4 – Croolman Feb 22 '19 at 14:41
  • opencv2 and opencv are 2 different libraries and they don't require each other to my knowledge, could you post an example of where you require 'cv' – Aditya Shankar Feb 22 '19 at 14:42
  • `capture = cv2.VideoCapture(stream_url); video_fps = capture.get(cv2.CV_CAP_PROP_FPS)` leads to: `AttributeError: module 'cv2.cv2' has no attribute 'CV_CAP_PROP_FPS'` From what I've found out, these contants are defined in `cv` – grześ Feb 22 '19 at 15:30

1 Answers1

0

OK, so it turned out I was misled by an old version of documentation (for some reason search engine placed link to this version on top) that uses constants like CV_CAP_PROP_FPS. Also I've seen some code previously that used cv and not cv2 to get to these constants (but it was a while ago and I guess it was for Python 2 and some old version of opencv).

Thanks to this answer I realized that names of the constants changed between versions of opencv. A new version of docs seems to confirm that -- prefix CV_ is no longer there. I checked that the constants that I need are accessible from cv2, for example

import cv2

capture = cv2.VideoCapture("film.webm")
video_fps = capture.get(cv2.CAP_PROP_FPS)
print("fps", video_fps)

works fine!

grześ
  • 467
  • 3
  • 21