Wednesday, July 11, 2012

python and opencv

Install OpenCV and Python
Yesterday we had problem about installing OpenCV with python, so I tried to install on my computer and it work quite well here. I also have problem with new version of OpenCV (OpenCV version 2). It seems like new version of OpenCV is just a zip file and we need more step that we have tried but it didn’t work such as Add <...>\OpenCV\bin to the system PATH and so on.
What I have installed: python-2.6 and OpenCV1.1 (OpenCV1.1 is .exe file, so it automatically add path for us. If you found problem about downloading the old version of OpenCV, you can email me to send the link to you, it’s about 25.5 MB)
After you installed those two programs, you can try if it work or not by import these two libraries from Python shell

>> from opencv.cv import *
>> from opencv.highgui import *

If it works, it means you can use this function with python.
There are some examples that you can learn more from <yourOpenCVpath>\samples\python. They also provided the example for C if you prefer to use.

Getting start with Python
To create new project,

  • File>New Window, then you will have new space to create your program
  • Import CV and Highgui
    from opencv.cv import *
    from opencv.highgui import *
  • You can try with load image and show image here I show the image called penguins.jpg here is the program;

from opencv.cv import *
from opencv.highgui import *

img = cvLoadImage ("penguin.png",0)
cvNamedWindow("Image", CV_WINDOW_AUTOSIZE)
cvShowImage("Image", img);

while cvWaitKey(0) != 0x1b: pass

  • After that, for test your program just press F5.


I hope I might help you to start your project, you can email me if you have problem about programming or image procelssing. I would glad to help you if I could.

No comments: