I'm wondering if there's a get rope-code-assist working on the cv namespace of openCV
import cv2.cv as cv
cv.LoadImage
So far I get [no match]. Is there something else I need to do?
The cv2.pyd is in the PYTHONPATH and has been built from the opencv source.
Related
I am trying to use OpenCV for Python 3 for the first time. To install, I simply typed "pip3 install opencv-python" into the terminal. When I do this, I see in Finder (I'm on a Mac), that in /usr/local/lib/python3.7/site-packages, I now have a new folder called "cv2". This is strange. Why isn't it cv3, as I used pip3? I do not know.
When I try to import cv2 from python3, it says "No module named 'cv2'". Luckily StackOverflow already has a solution: if I first change directories like: "cd /usr/local/lib/python3.7/site-packages" then I will be able to open cv2. I do not know why this step is necessary for OpenCV. I don't have to do this to "import numpy" for example; "numpy" does not care what directory I start from, and it is listed like just another module like cv2.
Anyways, I change directory to site-packages, start python3, and I import cv2. Now there is a new error. This time cv2 is found, but it says:
"from .cv2 import *
ModuleNotFoundError: No module named 'cv2.cv2'"
For the record, I also have Python 2.7. If I try "cd /usr/local/lib/python2.7/site-packages" and then start Python 2.7, I can import cv2. This is ok, but I want to use OpenCV with Python3.
Let me summarize.
(1) How can I get cv2 or cv3 to import when I start from any directory? Is this ever possible?
(2) How can I get cv3 for python3? cv2 seems to be problematic in python3 because because there is no "cv2.cv2"
The only thing we need to know here is, that 2 in cv2 is not a version. cv2 uses API of C++ while cv uses C API. Version of it is constantly updating being inside CV2.
There is no cv3 there's only import cv2 that opencv older or latest that is updated for old python or latest.
I am trying to write an OCR program in python. Now i got a program which perform OCR on digits and uses KNearest() function in cv2. But i didn't find any KNearest() function in cv2 while compiling the same. I already installed OpenCV form prebuilt binary cv2.pyd ( as per instructions given by site http://docs.opencv.org/trunk/doc/py_tutorials/py_setup/py_setup_in_windows/py_setup_in_windows.html#install-opencv-python-in-windows).
I'm assuming you are using OpenCV 3.x rather than 2.x. If this is the case, you'll want to replace
model = cv2.KNearest()
with
model = cv2.ml.KNearest_create()
>>> import cv2
>>> print cv2.KNearest
<built-in function KNearest>
If you're not able to do this, you most likely have a bad or old installation of opencv or its python bindings.
You didn't specify your OS, but if you're using any modern debian based distro (ubuntu, mint, ...), apt-get install python-opencv should suffice.
I'm trying to write some programs using opencv and python. I installed opencv and the python libraries from the repositories. I'm using ubuntu 12.04. The folder /var/lib/python-support/python2.7 contains just 5 files :
cv2.so
cv.py
cv.pyc
simplegeneric-0.7.egg-info
simplegeneric.py
simplegeneric.pyc
From what reading I have done, I think there's supposed to be an opencv folder around here. I'm able to import cv library using
import cv
but
from opencv import cv
And I cannot load the highgui module. Any way to work around this? I would really really like to do something in opencv
You must have installed OpenCV >= 2.3.1. In OpenCV 2.3.1 and higher, Python bindings do not have highgui.
import cv2
import cv2.cv as cv
and you're good to go.
import cv2
img = cv2.imread("image name")
cv2.imshow("window name", img)
cv2.waitKey(0)
You can find more help on OpenCV docs and you could also look at some of the opwncv stuff that I have been doing here.
I hope this helps.
You will get the highgui file in OpenCV folder(installed folder) in include/opencv/highgui.h.
I have downloaded OpenCV2.1 and Python2.6.
when i try to import cv using sys.path.append("C:\OpenCV2.1\Python2.6\Lib\site-packages") and then import cv, it tells me ImportError: DLLload failed..
I have tried the solutions given in previous thread to copy the two files in the above path to C:\Python26\Lib\site-packages, but i still can't import cv.
Is it because I missed out doing some steps after installing? What could be the reasons to why the system cannot find the module cv?
The OpenCV DLLs seem not to be found. Did you add OpenCV's bin directory to your PATH, "C:\OpenCV2.1\bin" in your case?
To use the Python wrappers
sys.path.append("C:\OpenCV2.1\Python2.6\Lib\site-packages")
import cv
should work, as well as copying cv.lib and cv.pyd to your C:\Python26\Lib\site-packages (assuming you installed Python to C:\Python26).
But those wrappers have to find the DLLs they should wrap. So make sure, they are in a path Python can find them.
Maybe this question Installing OpenCV on Windows 7 for Python 2.7 may help, especially Gia Thuy's journal post he mentions in his answer. Although he uses Python 2.7 and OpenCV 2.2, the procedure remains the same.
I'm trying to use OpenCV with Python and converting some C++ code. Anyway, if I do:
import cv
img = cv.LoadImage('image.jpg')
It's ok. Or:
import opencv.cv as opcv
size = opcv.cvSize(40, 50)
But anyway, the cv module doesn't have the cvSize data structure and the opencv.cv doesn't have the LoadImage. So, what exactly does each module have? I tried looking in the documentation but couldn't find it. Am I supposed to use it like this or is my setup misconfigured?
The real answer is :) that both "import opencv.cv" or "from opencv import cv" are the old-style wrapping imports.
Since OpenCV 2.0, the new-style Python wrapping is used, and the style you should use looks like this:
# 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's show the image in a window
cv.NamedWindow('your name', 1)
cv.ShowImage('your name', src_mat)
cv.WaitKey
The old-style wrappings made use of SWIG, the new-style wrappings, judging by the opencv 2.2 source code, seem to be self-made.
With:
import cv
You're importing the cv module from wherever it exists in the python modules search directories. This could be a different version of the module stored somewhere outside the opencv package install as it appears to be in this case.
But with:
import opencv.cv
You're explicitly importing the opencv packages version of cv, i.e. the one in the install directory for the opencv package. This version almost guarantees you have the one from the opencv package and it seems to be the same as using the syntax:
from opencv import cv