Difference between "import cv" and "import opencv.cv" using Python + OpenCV?

I am trying to use OpenCV with Python and convert some C ++ code. Anyway, if I do this:

import cv
img = cv.LoadImage('image.jpg')

This is normal. Or:

import opencv.cv as opcv
size = opcv.cvSize(40, 50)

But in any case, the module cvdoes not have a data structure cvSize, but opencv.cvdoes not LoadImage. So what exactly does each module have? I tried looking for documentation, but could not find it. Should I use it like this, or is my setup incorrectly configured?

+3
source share
2 answers

The real answer: :) that both "import opencv.cv" or "from opencv import cv" are import copies of the old style.

OpenCV 2.0 Python , , , :

# import only cv, no opencv
# this also brings in sub modules such as highgui
import cv
# no "cv" prepended before all method names
src_mat = cv.LoadImageM('yourfilename.png', cv.CV_LOAD_IMAGE_GRAYSCALE)
# let show the image in a window
cv.NamedWindow('your name', 1)
cv.ShowImage('your name', src_mat)
cv.WaitKey

SWIG, , opencv 2.2, .

+2

import cv 

cv , , python. , - opencv, , .

:

import opencv.cv

opvv- cv, opencv-. , opencv-, , :

from opencv import cv
0

Source: https://habr.com/ru/post/1778453/


All Articles