Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

OpenCV with Python (cv or cv2)

859 views
Skip to first unread message

Markos

unread,
May 26, 2015, 9:52:00 AM5/26/15
to pytho...@python.org
Hi,

I want to use OpenCV with Python.

I installed version 2.4.9
(http://sourceforge.net/projects/opencvlibrary/files/opencv-unix/2.4.9/opencv-2.4.9.zip/)
in debian Squeeze running Python 2.6.6. Using the tutorial:
http://indranilsinharoy.com/2012/11/01/installing-opencv-on-linux/

(I tried to install versions 2.4.11 and 2.4.10 (in Squeeze with python
2.2.6) but I couldn't.)

I lost some time trying to load the module cv2:

> >> Import cv2.cv the cv
Traceback (most recent call last):
File "<stdin>", line 1, in <module >>
ImportError: No module named cv2.cv

After a while I realized I could use the cv module. (import cv)

But still I do not understand the differences between the modules cv and
cv2.

Do you suggest any good tutorial about the differences between cv and cv2?

I will have to make many changes in python programs using cv to reuse
the code later with cv2?

Thanks,
Markos

Laura Creighton

unread,
May 26, 2015, 10:21:38 AM5/26/15
to Markos, pytho...@python.org, l...@openend.se
In a message of Tue, 26 May 2015 10:24:30 -0300, Markos writes:
>Hi,
>
>I want to use OpenCV with Python.
>
>I installed version 2.4.9
>(http://sourceforge.net/projects/opencvlibrary/files/opencv-unix/2.4.9/opencv-2.4.9.zip/)
>in debian Squeeze running Python 2.6.6. Using the tutorial:
>http://indranilsinharoy.com/2012/11/01/installing-opencv-on-linux/
>
>(I tried to install versions 2.4.11 and 2.4.10 (in Squeeze with python
>2.2.6) but I couldn't.)

You mean python 2.6.6, right?
and this package: https://packages.debian.org/source/squeeze/opencv
which is 2.1.0-3 is too old for you?

What do you mean that you
tried to install versions 2.4.11 and 2.4.10 but couldn't? What
error messages did you get?

>I lost some time trying to load the module cv2:
>
>> >> Import cv2.cv the cv

s/the/as/ ?

>Traceback (most recent call last):
>File "<stdin>", line 1, in <module >>
>ImportError: No module named cv2.cv
>
>After a while I realized I could use the cv module. (import cv)
>
>But still I do not understand the differences between the modules cv and
>cv2.
>
>Do you suggest any good tutorial about the differences between cv and cv2?
>
>I will have to make many changes in python programs using cv to reuse
>the code later with cv2?
>
>Thanks,
>Markos
>--
>https://mail.python.org/mailman/listinfo/python-list

post the output you got from cmake

It will probably complain that it is missing some headers, so couldn't
make libcv2.so

If you haven't installed python-dev (not just python) and numpy I
guarantee it will not find needed headers; if you have but it is
still not being made we will have to look harder at what is going wrong.

If it made a libcv.so for you, did it put it in a place you can see
with your PYTHONPATH?

Laura


Thomas 'PointedEars' Lahn

unread,
May 26, 2015, 11:49:35 AM5/26/15
to
Markos wrote:
^^^^^^
Please append your last name.

> I want to use OpenCV with Python.
>
> I installed version 2.4.9
> (http://sourceforge.net/projects/opencvlibrary/files/opencv-unix/2.4.9/opencv-2.4.9.zip/)
> in debian Squeeze running Python 2.6.6. Using the tutorial:
> http://indranilsinharoy.com/2012/11/01/installing-opencv-on-linux/

Do not do that. Install the distribution packages instead.

> (I tried to install versions 2.4.11 and 2.4.10 (in Squeeze with python
> 2.2.6) but I couldn't.)

I have stretch/sid with python-opencv=2.4.9+dsfg-1.1 installed.

squeeze has python-opencv=2.1.0-3+squeeze1. squeeze is *oldoldstable* now.
You want to upgrade NOW.

<https://packages.debian.org/search?suite=squeeze&searchon=names&keywords=python-opencv>

--
PointedEars

Twitter: @PointedEars2
Please do not cc me. / Bitte keine Kopien per E-Mail.

Rustom Mody

unread,
May 26, 2015, 1:03:10 PM5/26/15
to
On Tuesday, May 26, 2015 at 9:19:35 PM UTC+5:30, Thomas 'PointedEars' Lahn wrote:
> Markos wrote:
> ^^^^^^
> Please append your last name.

No more required than an affidavit proving PointedEars is your legal name

Thomas 'PointedEars' Lahn

unread,
May 26, 2015, 6:20:08 PM5/26/15
to
In addition to this utter nonsense, do you have anything constructive to say
about the rest of my posting? If not, troll elsewhere.

IronManMark20

unread,
May 27, 2015, 12:54:40 AM5/27/15
to
To actually answer your questions, cv2 is the newest and best opencv binding. It uses numpy arrays, instead of what cv uses. This means it is much easier to deal with. I will also point you to https://stackoverflow.com/questions/10417108/what-is-different-between-all-these-opencv-python-interfaces

Markos

unread,
May 27, 2015, 7:41:25 PM5/27/15
to Laura Creighton, pytho...@python.org
Hi Laura,

On 26-05-2015 11:21, Laura Creighton wrote:
> In a message of Tue, 26 May 2015 10:24:30 -0300, Markos writes:
>
>> Hi,
>>
>> I want to use OpenCV with Python.
>>
>> I installed version 2.4.9
>> (http://sourceforge.net/projects/opencvlibrary/files/opencv-unix/2.4.9/opencv-2.4.9.zip/)
>> in debian Squeeze running Python 2.6.6. Using the tutorial:
>> http://indranilsinharoy.com/2012/11/01/installing-opencv-on-linux/
>>
>> (I tried to install versions 2.4.11 and 2.4.10 (in Squeeze with python
>> 2.2.6) but I couldn't.)
>>
> You mean python 2.6.6, right?
> and this package: https://packages.debian.org/source/squeeze/opencv
> which is 2.1.0-3 is too old for you?
>
>

I installed this package (python-opencv) but I thought this package
would be only some API for python to use the opencv library and I
imagined that I would still have to install the opencv library from source.

> What do you mean that you
> tried to install versions 2.4.11 and 2.4.10 but couldn't? What
> error messages did you get?
>
>
For example when trying to install the 2.4.11 version after running cmake:

cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local -D
WITH_TBB=ON -D BUILD_NEW_PYTHON_SUPPORT=ON -D WITH_V4L=ON -D
INSTALL_C_EXAMPLES=ON -D INSTALL_PYTHON_EXAMPLES=ON -D BUILD_EXAMPLES=ON
-D WITH_QT=ON -D WITH_OPENGL=ON ..

(Output of cmake at the end of message.)

and make -j2 to compile, but an error occurred after compiling 55%:

[ 55%] Building CXX object
modules/legacy/CMakeFiles/opencv_legacy.dir/src/facedetection.cpp.o
Linking CXX shared library ../../lib/libopencv_legacy.so
[ 55%] Built target opencv_legacy
make: ** [all] Erro 2

>> I lost some time trying to load the module cv2:
>>
>>
>>>>> Import cv2.cv the cv
>>>>>
> s/the/as/ ?
>

import cv2.cv as cv


>
>
>> Traceback (most recent call last):
>> File "<stdin>", line 1, in<module>>
>> ImportError: No module named cv2.cv
>>
>> After a while I realized I could use the cv module. (import cv)
>>
>> But still I do not understand the differences between the modules cv and
>> cv2.
>>
>> Do you suggest any good tutorial about the differences between cv and cv2?
>>
>> I will have to make many changes in python programs using cv to reuse
>> the code later with cv2?
>>
>> Thanks,
>> Markos
>> --
>> https://mail.python.org/mailman/listinfo/python-list
>>
> post the output you got from cmake
>

At the end of message.

> It will probably complain that it is missing some headers, so couldn't
> make libcv2.so
>
> If you haven't installed python-dev (not just python) and numpy I
> guarantee it will not find needed headers; if you have but it is
> still not being made we will have to look harder at what is going wrong.
>
>
I installed the following packages:

apt-get install cmake
apt-get install build-essential
apt-get install pkg-config
apt-get install libgtk2.0-dev
apt-get install python-opencv python-dev python-numpy
apt-get install libpng12-0 libpng12-dev libpng++-dev libpng3 libpnglite-dev libpngwriter0-dev libpngwriter0c2 zlib1g-dbg
zlib1g zlib1g-dev pngtools libjasper-dev libjasper-runtime libjasper1 libjpeg8 libjpeg8-dbg libjpeg62 libjpeg62-dev

libjpeg-progs libtiff4-dev libtiff4 libtiffxx0c2 libtiff-tools ffmpeg libavcodec-dev libavcodec52 libavformat52

libavformat-dev libswscale0 libswscale-dev openexr libopenexr6 libopenexr-dev

apt-get install libgstreamer0.10-0-dbg libgstreamer0.10-0 libgstreamer0.10-dev libgstreamer-plugins-base0.10-dev

libxine1-ffmpeg libxine-dev libxine1-bin libunicap2 libunicap2-dev libucil2 libucil2-dev libdc1394-22-dev

libdc1394-22 libdc1394-utils libv4l-0 libv4l-dev
apt-get install libqt4-dev

> If it made a libcv.so for you, did it put it in a place you can see
> with your PYTHONPATH?
>
> Laura
>
>
>
>>> import sys
>>> print sys.path
['', '/usr/lib/python2.6', '/usr/lib/python2.6/plat-linux2',
'/usr/lib/python2.6/lib-tk', '/usr/lib/python2.6/lib-old',
'/usr/lib/python2.6/lib-dynload',
'/usr/local/lib/python2.6/dist-packages',
'/usr/lib/python2.6/dist-packages',
'/usr/lib/python2.6/dist-packages/PIL',
'/usr/lib/python2.6/dist-packages/gst-0.10',
'/usr/lib/pymodules/python2.6', '/usr/lib/pymodules/python2.6/gtk-2.0',
'/usr/lib/python2.6/dist-packages/wx-2.8-gtk2-unicode']

import cv works fine but I didn't find libcv.so in my system.

I suppose that cv had already been installed by the package
python-opencv, and the compilation of the opencv didn't install cv2.

Thanks for your attention,
Markos


Return of cmake
-- Linker flags (Release):
-- Linker flags (Debug):
-- Precompiled headers: YES
--
-- OpenCV modules:
-- To be built: core flann imgproc highgui
features2d calib3d ml video legacy objdetect photo gpu ocl nonfree
contrib stitching superres ts videostab
-- Disabled: world
-- Disabled by dependency: -
-- Unavailable: androidcamera dynamicuda java python viz
--
-- GUI:
-- QT 4.x: YES (ver 4.6.3 EDITION = OpenSource)
-- QT OpenGL support: YES (/usr/lib/libQtOpenGL.so)
-- OpenGL support: YES (/usr/lib/libGLU.so
/usr/lib/libGL.so /usr/lib/libSM.so /usr/lib/libICE.so
/usr/lib/libX11.so /usr/lib/libXext.so)
-- VTK support: NO
--
-- Media I/O:
-- ZLib: /usr/lib/libz.so (ver 1.2.3.4)
-- JPEG: /usr/lib/libjpeg.so (ver 62)
-- PNG: /usr/lib/libpng.so (ver 1.2.44)
-- TIFF: /usr/lib/libtiff.so (ver 42 - 3.9.4)
-- JPEG 2000: /usr/lib/libjasper.so (ver 1.900.1)
-- OpenEXR: /usr/lib/libImath.so
/usr/lib/libIlmImf.so /usr/lib/libIex.so /usr/lib/libHalf.so
/usr/lib/libIlmThread.so (ver 1.6.1)
--
-- Video I/O:
-- DC1394 1.x: NO
-- DC1394 2.x: YES (ver 2.1.2)
-- FFMPEG: YES
-- codec: YES (ver 52.123.0)
-- format: YES (ver 52.111.0)
-- util: YES (ver 50.43.0)
-- swscale: YES (ver 0.14.1)
-- gentoo-style: YES
-- GStreamer:
-- base: YES (ver 0.10.30)
-- video: YES (ver 0.10.30)
-- app: YES (ver 0.10.30)
-- riff: YES (ver 0.10.30)
-- pbutils: YES (ver 0.10.30)
-- OpenNI: NO
-- OpenNI PrimeSensor Modules: NO
-- PvAPI: NO
-- GigEVisionSDK: NO
-- UniCap: NO
-- UniCap ucil: NO
-- V4L/V4L2: Using libv4l1 (ver 0.8.0) / libv4l2
(ver 0.8.0)
-- XIMEA: NO
-- Xine: NO
--
-- Other third-party libraries:
-- Use IPP: NO
-- Use Eigen: NO
-- Use TBB: NO
-- Use OpenMP: NO
-- Use GCD NO
-- Use Concurrency NO
-- Use C=: NO
-- Use Cuda: NO
-- Use OpenCL: YES
--
-- OpenCL:
-- Version: dynamic
-- Include path:
~/Programacao/Python/OpenCV/opencv-2.4.11/3rdparty/include/opencl/1.2
-- Use AMD FFT: NO
-- Use AMD BLAS: NO
--
-- Python:
-- Interpreter: /usr/bin/python2.6 (ver 2.6.6)
-- Libraries: NO
-- numpy:
/usr/lib/pymodules/python2.6/numpy/core/include (ver 1.4.1)
-- packages path: lib/python2.6/dist-packages
--
-- Java:
-- ant: NO
-- JNI: /usr/lib/jvm/java-6-sun/include
/usr/lib/jvm/java-6-sun/include/linux /usr/lib/jvm/java-6-sun/include
-- Java tests: NO
--
-- Documentation:
-- Build Documentation: NO
-- Sphinx: NO
-- PdfLaTeX compiler: /usr/bin/pdflatex
-- Doxygen: NO
--
-- Tests and samples:
-- Tests: YES
-- Performance tests: YES
-- C/C++ Examples: YES
--
-- Install path: /usr/local
--
-- cvconfig.h is in:
~/Programacao/Python/OpenCV/opencv-2.4.11/build
-- -----------------------------------------------------------------
--
-- Configuring done
-- Generating done
-- Build files have been written to:
~/Programacao/Python/OpenCV/opencv-2.4.11/build

Laura Creighton

unread,
May 28, 2015, 12:48:21 AM5/28/15
to Markos, Laura Creighton, pytho...@python.org
Your cmake output doesn't mention that it tried to build libcv.so
so, I guess the reason you cannot find it is that it never tried
to make it.

You may already have fixed your problem by just installing the relevant
debian package. If not, it may be that you need to install this one
https://packages.debian.org/squeeze/libcv-dev to get libcv.

You have another problem. Squeeze is _very_ old.
According to http://stackoverflow.com/questions/5212728/libcxcore-so-2-missing-in-opencv
the opencv project renamed a bunch of libraries, so if at all possible you
should upgrade your debian distribution. You may have all sorts of
mismatches between the source you just built and the libraries you
need -- which you will only find by trial and error.

Laura

Markos

unread,
May 29, 2015, 10:46:55 AM5/29/15
to Laura Creighton, pytho...@python.org
Hi Laura,

I will follow your advice and install Debian 8.0. I was postponing this
upgrade. :^)

I just find that Jessie is the new stable release.

According to the tutorial:

http://milq.github.io/install-opencv-ubuntu-debian/

the simplest way to install opencv in jessie is:

apt-get install python-dev libopencv-opencv

And from what I saw the opencv package available in the repository is 2.4.9

https://packages.debian.org/jessie/python-opencv

And from what I saw on the site:

https://packages.debian.org/jessie/python3
and
https://packages.debian.org/jessie/python

There are packages in the repository for python 3.4.2-2 and 2.7.9-1

My doubt is which version of Python (3.4.2-2 or 2.7.9-1) is compatible
with the opencv library 2.4.9 available in the repository?

Thanks for your attention,
Markos


Chris Angelico

unread,
May 29, 2015, 10:51:24 AM5/29/15
to pytho...@python.org
On Sat, May 30, 2015 at 12:29 AM, Markos <mar...@c2o.pro.br> wrote:
> the simplest way to install opencv in jessie is:
>
> apt-get install python-dev libopencv-opencv
>
> And from what I saw the opencv package available in the repository is 2.4.9
>
> https://packages.debian.org/jessie/python-opencv
>
> And from what I saw on the site:
>
> https://packages.debian.org/jessie/python3
> and
> https://packages.debian.org/jessie/python
>
> There are packages in the repository for python 3.4.2-2 and 2.7.9-1
>
> My doubt is which version of Python (3.4.2-2 or 2.7.9-1) is compatible with
> the opencv library 2.4.9 available in the repository?

Since it's managed by the Debian repo, you can simply look at its
dependencies. In this case, python-opencv is built for Python 2, not
Python 3, so it'll pull in Python 2.7.9-1. Unfortunately there isn't a
corresponding python3-opencv package, so I don't know how hard it
would be to install for Python 3.4.2; but personally, I'd just try
using pip to install it.

$ apt-cache show python-opencv
Version: 2.4.9.1+dfsg-1+b1
Depends: python (<< 2.8), python:any (>= 2.7.5-5~), python (>= 2.7~),
libc6 (>= 2.14), libgcc1 (>= 1:4.1.1), libopencv-calib3d2.4,
libopencv-contrib2.4, libopencv-core2.4, libopencv-features2d2.4,
libopencv-flann2.4, libopencv-highgui2.4, libopencv-imgproc2.4,
libopencv-legacy2.4, libopencv-ml2.4, libopencv-objdetect2.4,
libopencv-photo2.4, libopencv-video2.4, libpython2.7 (>= 2.7),
libstdc++6 (>= 4.1.1), python-numpy-abi9, python-numpy (>= 1:1.6.1)

If you simply "apt-get install python-opencv", it'll make sure you
have the right Python installed.

ChrisA
0 new messages