python open cv loading image


Question

I'm new to python and open cv. I'm trying to find out how to load an image in opencv with python. Can any one provide an example (with code) explaining how to load the image and display it?

import sys
import cv
from opencv.cv import *
from opencv.highgui import *
ll="/home/pavan/Desktop/iff pics/out0291.tif"
img= cvLoadImage( ll );
cvNamedWindow( “Example1”, CV_WINDOW_AUTOSIZE );
cvShowImage( “Example1”, img );
cvWaitKey(10);
cvDestroyWindow( “Example");
1
3
9/8/2010 11:23:38 AM

There have been quite a few changes in the openCV2 API:

import cv
ll = "/home/pavan/Desktop/iff pics/out0291.tif"
img = cv.LoadImage(ll)
cv.NamedWindow("Example", cv.CV_WINDOW_AUTOSIZE )
cv.ShowImage("Example", img )
cv.WaitKey(10000)
cv.DestroyWindow("Example")

It is a simpler, quite cleaner syntax!

Also, you don't need trailing ; à-la-matlab. Last, be careful about the quotes you use.

For the newer openCV3 API, you should see the other answer to this question.

7
8/5/2017 10:19:06 AM

Licensed under: CC-BY-SA with attribution
Not affiliated with: Stack Overflow
Icon