I added another feature to the web application. This is opencv's face detection application - just upload an image and see the magic! (click here to go to the application)
Showing posts with label opencv. Show all posts
Showing posts with label opencv. Show all posts
Tuesday, November 24, 2009
Sunday, April 12, 2009
converting 8bit image to 32 bit image
If you have an 8bit source image and you want to convert it to a 32 bit image you do it using cvConvertScale:
newim = cvCreateImage (cvSize (src.rows, src.cols, 32, 1)
cvConvertScale(src,newim)
newim = cvCreateImage (cvSize (src.rows, src.cols, 32, 1)
cvConvertScale(src,newim)
How to crop images with opencv in python
Found this helpful tip from a fellow python-opencv user:
find it here
find it here
Labels:
crop image,
opencv,
python,
python example,
python image processing
Saturday, April 11, 2009
Opencv example
Here's a short example showing how to use openCV with Python.It reads an image from a file, displays the image, the Harris corner detector on that image and the Canny edge image:
(save this in a file named tmp.py and run with: python tmp.py)
import Image
import os
import sys
from opencv.cv import *
from opencv.highgui import *
def analyzeImage(f,name):
f = open(sys.argv[1],'r')
analyzeImage(f,sys.argv[1])
(save this in a file named tmp.py and run with: python tmp.py
import Image
import os
import sys
from opencv.cv import *
from opencv.highgui import *
def analyzeImage(f,name):
im=Image.open(f)
try:
- if(im.size[0]==1 or im.size[1]==1):
- return
print (name+' : '+str(im.size[0])+','+ str(im.size[1]))
le=1
if(type(im.getpixel((0,0)))==type((1,2))):
- le=len(im.getpixel((0,0)))
gray = cvCreateImage (cvSize (im.size[0], im.size[1]), 8, 1)
edge1 = cvCreateImage (cvSize (im.size[0], im.size[1]), 32, 1)
edge2 = cvCreateImage (cvSize (im.size[0], im.size[1]), 8, 1)
edge3 = cvCreateImage (cvSize (im.size[0], im.size[1]), 32, 3)
for h in range(im.size[1]):
- for w in range(im.size[0]):
- p=im.getpixel((w,h))
if(type(p)==type(1)):
- gray[h][w] = im.getpixel((w,h))
else:
- gray[h][w] = im.getpixel((w,h))[0]
cvCornerHarris(gray,edge1,5,5,0.1)
cvCanny(gray,edge2,20,100)
cvNamedWindow("win")
cvShowImage("win", gray);
cvNamedWindow("win2")
cvShowImage("win2", edge1);
cvNamedWindow("win3")
cvShowImage("win3", edge2);
cvWaitKey()
f.close()
except Exception,e:
- print e
print 'ERROR: problem handling '+ name
f = open(sys.argv[1],'r')
analyzeImage(f,sys.argv[1])
Image processing tools for python
The most basic library is PIL. it provides pretty basic tools for reading,writing and displaying images, some tools for drawing. In terms of image processing it has some functions for cropping, resizing, sharpening images. For more complex operations I found it insufficient.
The library I found to be useful so far is the Python binding for OpenCV. It can be found here. Installing it should not be too difficult, though I could not get it working until I installed the following:
sudo apt-get install python-opencv
The library I found to be useful so far is the Python binding for OpenCV. It can be found here. Installing it should not be too difficult, though I could not get it working until I installed the following:
sudo apt-get install python-opencv
Subscribe to:
Posts (Atom)