Function CalcEMD2 missing from OpenCV3 module for Anaconda Python - python

I need to calculate the Earth Mover's Distance (EMD) in my program. I am trying to follow this answer, but for some reason the cv2 module which I have on my system does not have the function CalcEMD2. Could someone explain why it is missing?
I am using Anaconda for Python 3.4 and installed OpenCV with
conda install -c https://conda.anaconda.org/menpo opencv3
The package installed without problems and imports nicely.
>>> import cv2
>>> print(cv2.__version__)
3.1.0
However, CalcEMD2 does not exist. The namespace of cv2 has only two members containing the string 'emd' (case-insensitive), neither of which is the function I'm looking for:
>>> [k for k in cv2.__dict__ if 'emd' in k.lower()]
['createEMDHistogramCostExtractor', 'createEMDL1HistogramCostExtractor']

You will find it under cv2.cv.CalcEMD2() for most OpenCV 2.7.x libraries I've seen.
The compareHist() also has parameters hiding under cv2.cv.CV_COMP_* as well.
Hope this helps.

Related

Raspberry Pi 3: OpenCV 3.4.0 missing some files after installation and can't be called within my code

I hope you're doing good.
I've been working on a robot for couple of months and got it working properly recently.
Sadly, my code got deleted including all libraries, tried to install OpenCV couple of times but I'm still getting errors
I used this link to install OpenCV 3.4.0 with the latest version of Raspbian https://www.life2coding.com/install-opencv-3-4-0-python-3-raspberry-pi-3/
ImportError: libavcodec.so.56: cannot open shared object file: No such
file or directory
Is there a proper way to install all libraries ? I'll include all libraries I used at the beginning of the code below.
Thanks in advance
[import cv2
import cv2.cv as cv
import numpy as np
from gopigo import *
import sys
import RPi.GPIO as GPIO
import time
import os
import multiprocessing as mp
Could be that you installed an old/wrong version of opencv, or it could be that you installed the base version, without the extra modules.
I would advice installing use pip, always works for me. In that case the following command should be enough:
pip install opencv-contrib-python
Note: you need to uninstall openCV first. Read more about the installation here
If you dont know what pip is, read about it and install from here
I was using 'Raspbian Stretch Lite' but didn't work, I might have missed something up while installing OpenCV library
I tried latest version of 'Raspbian Stretch with desktop and recommended software' from Raspberrypi's website https://www.raspberrypi.org/downloads/raspbian/
and followed all steps stated here to install OpenCV https://www.pyimagesearch.com/2017/09/04/raspbian-stretch-install-opencv-3-python-on-your-raspberry-pi/
Once done with OpenCV use this command within your code to relocate packages
import sys
sys.path.append('/usr/local/lib/python2.7/site-packages')
OpenCV is working fine to me now. Thanks to J.D. and Jayjayyy for guiding me and helping me to solve this issue, I really appreciate your help :)

Is there no more module cv for opencv python?

The solutions on this question do not work with the opencv python version 3.3.1. cv2.__version__ prints 3.3.1-dev, and even import cv2.cv returns the no module error.
On reading this answer it seems like both the cv2 and cv interfaces were maintained, at least for a while but that doesn't seem the case any more.
So...
Does the cv module exist any more?
If not, then from which opencv version was this lost? And where can we find old cv functions? For instance cv.StereoRectify
Thank you
In OpenCV 3.x cv was deprecated.
Some old cv modules can be found in cv2, as cv2.stereoRectify, others are not in opencv installation anymore due to legal concerns.
You may need to pip install opencv-contrib-python --user
It seems that the old cv module has been completely removed from OpenCV in version 3.
Old functions should have been ported to the current cv2 module. In your case, it seems cv.StereoRectify is now cv2.stereoRectify

cannot find reference for opencv functions in pycharm

I have opencv-python installed and the .pyd file is added in the site-packages and the DLLs. The code works with images. When I want to read, show, write an image it works. But I get a warning that the functions' references cannot be found in init.py . Due to this, I can not use the auto-complete feature. Could someone help me out? I am using opencv 3.4.0 and python 3.6.4 in pycharm. I downloaded opencv via pip in the command prompt.
The problem is caused by CV2 and how __init__.py does the imports. Just ignore the warnings the program will work all the same, or you can do an import with an alias like:
import cv2.cv2 as cv2
If you have a warning on it press Alt+Enter to install and fix it. Now you will have the code completion and no other warnings (about that) on the project.
Switching to an older version of opencv solved this problem for me.
Apparently pycharm sometime breaks depending on the version of opencv. For me, the newest version was, 4.6.X unstalling and installing 4.5.X did the trick.
I use python 3.10 and my newest version for opencv is 4.6.0.66 ,by changing opencv version to 4.5.5.62 and with an alias: import cv2.cv2 as cv2 my problem has solved.
Import cv2 as follows:
from cv2 import cv2
I installed version 4.5.5.64 and imported with an alias.
import cv2.cv2 as cvv2
I was using Python 3.10.2288.0 and OpenCV 1.6.0.66.
I resolved the issue by rolling back the OpenCV version to 4.5.5.62.

No module named cv

I'm trying to run this script:
https://github.com/openalpr/train-detector/blob/master/crop_plates.py
I've never dealt with python before. First of all I had some syntax errors in the print lines. They were lacking parentheses...but I'm not sure if I get this error because of the Python version I installed or this was indeed a syntax error. After fixing the syntax error I'm receiving the following error:
C:\>py crop_plates.py
Traceback (most recent call last):
File "crop_plates.py", line 7, in <module>
import cv2, cv
ImportError: No module named cv
I did the following:
Installed Python 2.7.5 32 bits.
Installed numpy 1.9.1 32 bits (also tried different versions)
Installed matplotlib 1.3.0.
Installed OpenCv
Copied cv2.pyd from
C:\Users\Me\Downloads\opencv\build\python\2.7\x86
to
C:\Python27\Lib\site-packages
But I can't find anywhere the cv.pyd file that I'm missing.
I found references to this guide for installing Opencv but it's not working
http://opencv.willowgarage.com/documentation/python/
Thank you very much,
Edit: I'm running Python in Windows 7.
For ImportError: No module named cv, try installing opencv-python module using below command:
pip install opencv-python
cv2.cv doesn't exists in OpenCV 3.0. Use simply cv2
Also, the attribute is no more CV_HOUGH_GRADIENT but HOUGH_GRADIENT
So what you looking for is probably:
cv2.HOUGH_GRADIENT
OK , I searched for a while and find the following :
First: you may write: import cv2.cv as cv to solve your proplem
cv and cv2 are both interface for python , and now , the newest "cv2" is the most used one , but clearly some libraries still use cv and others (like yours) use mix of the two,What is different between all these OpenCV Python interfaces?
It seems this code is using a old version of OpenCV. Unfortunately there is no mention of the exact version they used in their repo.
As the code is at least 2 years old, I would install opencv version 2.4.
pip install opencv-python==2.4

Where can i get OpenCV for python?

Where can i get OpenCV for python?What are the pre-requisites?? i tried to install opencv-python through synaptic package manager but Python says
No module named CVtypes
CVTypes is a third party implementation that essentially wraps python around objects written in C, the language that OpenCV is written in (along with C++). If you want to use that, you will have to download and install it separately, as it is not part of the standard repositories of Ubuntu's Synaptic package manager that I know of at this time (I assume you are on Ubuntu because you mentioned 'Synaptic', Ubuntu's package manager).
However, there is an official python interface for OpenCV that is included in the OpenCV SVN repository and build packages. When installing version 1.0 from the package manager in Ubuntu, the python modules will be installed in the following directory:
/usr/lib/pymodules/python2.6/opencv
Ensure that is part of your PYTHONPATH environment variable and you should be able to import the modules as such:
from opencv.cv import *
from opencv.highgui import *
OpenCV over time has accumulated numerous Python bindings, mostly due to the strange way arrays are represented in OpenCV (IMHO). Here is a short list:
PyOpenCV
Scikits Image
Ctypes OpenCV
SWIG OpenCV
Choose which one you want to use and keep it consistent and upto date. I personally prefer the classic WillowGarage version[listed last] over its fancier cousins since it has most development and test muscle behind it.
get it from here unofficial binary packages.
by the way, they provide unofficial packages for many other projects
Tried the official website? http://opencv.willowgarage.com/wiki/Welcome
check your openCV version. Version 2 needs a simple
import cv
you may have a look at the samples/python folder.
this webpage explains in great depth on the installation
http://opencvpython.blogspot.com/2012/05/install-opencv-in-windows-for-python.html
after the installation try out the samples provided by opencv\samples\python2

Categories

Resources