Bases: SimpleCV.Camera.FrameSource
SUMMARY
The Camera class is the class for managing input from a basic camera. Note that once the camera is initialized, it will be locked from being used by other processes. You can check manually if you have compatable devices on linux by looking for /dev/video* devices.
This class wrappers OpenCV’s cvCapture class and associated methods. Read up on OpenCV’s CaptureFromCAM method for more details if you need finer control than just basic frame retrieval
SUMMARY
Return all properties from the camera.
RETURNS
A dict of all the camera properties.
SUMMARY
Retrieve an Image-object from the camera. If you experience problems with stale frames from the camera’s hardware buffer, increase the flushcache number to dequeue multiple frames before retrieval
We’re working on how to solve this problem.
RETURNS
A SimpleCV Image from the camera.
EXAMPLES
>>> cam = Camera()
>>> while True:
>>> cam.getImage().show()
SUMMARY
Retrieve the value of a given property, wrapper for cv.GetCaptureProperty
Warning
For most web cameras only the width and height properties are supported. Support for all of the other parameters varies by camera and operating system.
PARAMETERS
RETURNS
The specified property. If it can’t be found the method returns False.
EXAMPLE
>>> cam = Camera()
>>> prop = cam.getProperty("width")
Bases: threading.Thread
SUMMARY
This is a helper thread which continually debuffers the camera frames. If you don’t do this, cameras may constantly give you a frame behind, which causes problems at low sample rates. This makes sure the frames returned by your camera are fresh.
SUMMARY
An abstract Camera-type class, for handling multiple types of video input. Any sources of images inheirit from it
SUMMARY
Camera calibration will help remove distortion and fisheye effects It is agnostic of the imagery source, and can be used with any camera
The easiest way to run calibration is to run the calibrate.py file under the tools directory for SimpleCV. This will walk you through the calibration process.
PARAMETERS
RETURNS
The camera’s intrinsic matrix.
EXAMPLE
See :py:module:calibrate.py
SUMMARY
This function returns a cvMat of the camera’s intrinsic matrix. If there is no matrix defined the function returns None.
SUMMARY
Using the overridden getImage method we retrieve the image and apply the undistortion operation.
RETURNS
The latest image from the camera after applying undistortion.
EXAMPLE
>>> cam = Camera()
>>> cam.loadCalibration("mycam.xml")
>>> while True:
>>> img = cam.getImageUndistort()
>>> img.show()
SUMMARY
This shows a live view of the camera.
EXAMPLE
To use it’s as simple as:
>>> cam = Camera()
>>> cam.live()
Left click will show mouse coordinates and color Right click will kill the live image
SUMMARY
Load a calibration matrix from file. The filename should be the stem of the calibration files names. e.g. If the calibration files are MyWebcamIntrinsic.xml and MyWebcamDistortion.xml then load the calibration file “MyWebcam”
PARAMETERS
RETURNS
Returns true if the file was loaded , false otherwise.
EXAMPLE
See :py:module:calibrate.py
SUMMARY
Save the calibration matrices to file. The file name should be without the extension. The default extension is .xml.
PARAMETERS
RETURNS
Returns true if the file was saved , false otherwise.
EXAMPLE
See :py:module:calibrate.py
SUMMARY
If given an image, apply the undistortion given my the camera’s matrix and return the result.
If given a 1xN 2D cvmat or a 2xN numpy array, it will un-distort points of measurement and return them in the original coordinate system.
PARAMETERS
RETURNS
The undistorted image or the undistorted points. If the camera is un-calibrated we return None.
EXAMPLE
>>> img = cam.getImage()
>>> result = cam.undistort(img)
Bases: SimpleCV.Camera.FrameSource
SUMMARY
The JpegStreamCamera takes a URL of a JPEG stream and treats it like a camera. The current frame can always be accessed with getImage()
Requires the Python Imaging Library: http://www.pythonware.com/library/pil/handbook/index.htm
EXAMPLE
Using your Android Phone as a Camera. Softwares like IP Webcam can be used.
>>> cam = JpegStreamCamera("http://192.168.65.101:8080/videofeed") # your IP may be different.
>>> img = cam.getImage()
>>> img.show()
SUMMARY
Return the current frame of the JpegStream being monitored
Bases: threading.Thread
SUMMARY
A Threaded class for pulling down JPEG streams and breaking up the images. This is handy for reading the stream of images from a IP CAmera.
Bases: SimpleCV.Camera.FrameSource
SUMMARY
This is an experimental wrapper for the Freenect python libraries you can getImage() and getDepth() for separate channel images
SUMMARY
This method returns the Kinect depth image.
RETURNS
The Kinect’s depth camera image as a grayscale image.
EXAMPLE
>>> k = Kinect()
>>> while True:
>>> d = k.getDepth()
>>> img = k.getImage()
>>> result = img.sideBySide(d)
>>> result.show()
SUMMARY
This method returns the Kinect camera image.
RETURNS
The Kinect’s color camera image.
EXAMPLE
>>> k = Kinect()
>>> while True:
>>> k.getImage().show()
Bases: SimpleCV.Camera.FrameSource
SUMMARY
The virtual camera lets you test algorithms or functions by providing a Camera object which is not a physically connected device.
Currently, VirtualCamera supports “image”, “imageset” and “video” source types.
USAGE
SUMMARY
Retrieve an Image-object from the virtual camera. RETURNS
A SimpleCV Image from the camera.
EXAMPLES
>>> cam = VirtualCamera()
>>> while True:
>>> cam.getImage().show()
SUMMARY
Color is a class that stores commonly used colors in a simple and easy to remember format, instead of requiring you to remember a colors specific RGB value.
EXAMPLES
To use the color in your code you type: Color.RED
To use Red, for instance if you want to do a line.draw(Color.RED)
SUMMARY
Returns a random color in tuple format.
RETURNS
A random color tuple.
EXAMPLE
>>> img = Image("lenna")
>>> kp = img.findKeypoints()
>>> for k in kp:
>>> k.draw(color=Color.getRandom())
>>> img.show()
SUMMARY
Convert any color to HSV, OpenCV style (0-180 for hue)
PARAMETERS
RETURNS
A color tuple in HSV format.
EXAMPLE
>>> c = Color.RED
>>> hsvc = Color.hsv(c)
SUMMARY
ColorCurve is a color spline class for performing color correction. It can takeas parameters a SciPy Univariate spline, or an array with at least 4 point pairs. Either of these must map in a 255x255 space. The curve can then be used in the applyRGBCurve, applyHSVCurve, and applyInstensityCurve functions.
EXAMPLE
>>> clr = ColorCurve([[0,0], [100, 120], [180, 230], [255, 255]])
>>> image.applyIntensityCurve(clr)
the only property, mCurve is a linear array with 256 elements from 0 to 255
SUMMARY
A color map takes a start and end point in 3D space and lets you map a range of values to it. Using the colormap like an array gives you the mapped color.
EXAMPLE
This is useful for color coding elements by an attribute:
>>> blobs = image.findBlobs()
>>> cm = ColorMap(startcolor = Color.RED, endcolor = Color.Blue,
>>> startmap = min(blobs.area()) , endmap = max(blobs.area())
>>> for b in blobs:
>>> b.draw(cm[b.area()])
SUMMARY
The color model is used to model the color of foreground and background objects by using a a training set of images.
You can create the color model with any number of “training” images, or add images to the model with add() and remove(). Then for your data images, you can useThresholdImage() to return a segmented picture.
SUMMARY
Add an image, array, or tuple to the color model.
PARAMETERS
RETURNS
Nothings.
EXAMPLE
>>> cm = ColorModel()
>>> cm.add(Image("lenna))>>>
cm.clear()
SUMMARY
Return true if a particular color is in our color model.
PARAMETERS
RETURNS
Returns True if the color is in the model, False otherwise.
EXAMPLE
>>> cm = ColorModel()
>>> cm.add(Color.RED)
>>> cm.add(Color.BLUE)
>>> if( cm.contains(Color.RED) )
>>> print "Yo - we gots red y'all."
SUMMARY
Load the color model from the specified file.
TO DO
This should be converted to pickle.
PARAMETERS
RETURNS
Nothing.
EXAMPLE
>>> cm = ColorModel()
>>> cm.load("myColors.txt")
>>> cm.add(Color.RED)
>>> cm.add(Color.BLUE)
>>> cm.save("mymodel)
SUMMARY
Remove an image, array, or tuple from the model.
PARAMETERS
RETURNS
Nothings.
EXAMPLE
>>> cm = ColorModel()
>>> cm.add(Image("lenna))>>>
cm.remove(Color.BLACK)
SUMMARY Resets the color model. I.e. clears it out the stored values.
RETURNS
Nothing.
EXAMPLE
>>> cm = ColorModel()
>>> cm.add(Image("lenna))>>>
cm.clear()
SUMMARY
Save a color model file.
PARAMETERS
RETURNS
Nothing.
EXAMPLE
>>> cm = ColorModel()
>>> cm.add(Color.RED)
>>> cm.add(Color.BLUE)
>>> cm.save("mymodel.txt")
TO DO
This should be converted to pickle.
SUMMARY
Set our model as being background imagery. I.e. things in the model are the background and will be marked as black during the threhsold operation.
RETURNS
Nothing.
SUMMARY
Set our model as being foreground imagery. I.e. things in the model are the foreground and will be marked as white during the threhsold operation.
RETURNS
Nothing.
SUMMARY
Perform a threshold operation on the given image. This involves iterating over the image and comparing each pixel to the model. If the pixel is in the model it is set to be either the foreground (white) or background (black) based on the setting of mIsBackground.
PARAMETERS
RETURNS
The thresholded image.
EXAMPLE
>>> cm = ColorModel()
>>> cm.add(color.RED)
>>> cm.add(color.BLUE)
>>> result = cm.threshold(Image("lenna")
>>> result.show()
SUMMARY
WindowStream opens a window (Pygame Display Surface) to which you can write images. The default resolution is 640, 480 – but you can also specify 0,0 which will maximize the display. Flags are pygame constants, including:
By default display will attempt to scale the input image to fit neatly on the screen with minimal distorition. This means that if the aspect ratio matches the screen it will scale cleanly. If your image does not match the screen aspect ratio we will scale it to fit nicely while maintining its natural aspect ratio.
Because SimpleCV performs this scaling there are two sets of input mouse coordinates, the (mousex,mousey) which scale to the image, and (mouseRawX, mouseRawY) which do are the actual screen coordinates.
Display should be used in a while loop with the isDone() method, which checks events and sets the following internal state controls:
NOTES
The mouse position on the screen is not the mouse position on the image. If you are trying to draw on the image or take in coordinates use mousex and mousey as these values are scaled along with the image.
EXAMPLE
>>> display = Display(resolution = (800, 600)) #create a new display to draw images on
>>> cam = Camera() #initialize the camera
>>> done = False # setup boolean to stop the program
>>> while not display.isDone():
>>> cam.getImage().flipHorizontal().save(display) # get image, flip it so it looks mirrored, save to display
>>> time.sleep(0.01) # Let the program sleep for 1 millisecond so the computer can do other things
>>> if display.mouseLeft:
>>> display.done = True
SUMMARY
CheckEvents checks the pygame event queue and sets the internal display values based on any new generated events.
Warning
This method must be called (or isDone() or isNotDone()) to perform mouse event checking.
RETURNS
Nothing.
SUMMARY
Checks the event queue and returns True if a quit event has been issued.
RETURNS
True on a quit event, False otherwise.
EXAMPLE
>>> disp = Display()
>>> cam = Camera()
>>> while not disp.isDone():
>>> img = cam.getImage()
>>> img.save(disp)
SUMMARY
Checks the event queue and returns False as long as the quit event hasn’t been issued.
RETURNS
False on a quit event, True otherwise.
EXAMPLE
>>> disp = Display()
>>> cam = Camera()
>>> while disp.isNotDone():
>>> img = cam.getImage()
>>> img.save(disp)
SUMMARY
Returns the position where the left mouse button went down.
Warning
You must call checkEvents() or isDone() in your main display loop for this method to work.
RETURNS
An (x,y) mouse postion tuple where the mouse went up.
EXAMPLE
>>> disp = Display((600,800))
>>> cam = Camera()
>>> while(disp.isNotDone()):
>>> img = cam.getImage()
>>> dwn = disp.leftButtonDownPosition()
>>> up = disp.leftButtonUpPosition()
>>> if( up is not None and dwn is not None):
>>> bb = disp.pointsToBoundingBox(up,dwn)
>>> img.drawRectangle(bb[0],bb[1],bb[2],bb[3])
>>> img.save(disp)
SEE ALSO
leftButtonUpPostion() rightButtonUpPostion() rightButtonDownPostion() pointsToBoundingBox() checkEvents()
SUMMARY
Returns the position where the left mouse button went up.
Warning
You must call checkEvents() or isDone() in your main display loop for this method to work.
RETURNS
An (x,y) mouse postion tuple where the mouse went up.
EXAMPLE
>>> disp = Display((600,800))
>>> cam = Camera()
>>> while(disp.isNotDone()):
>>> img = cam.getImage()
>>> dwn = disp.leftButtonDownPosition()
>>> up = disp.leftButtonUpPosition()
>>> if( up is not None and dwn is not None):
>>> bb = disp.pointsToBoundingBox(up,dwn)
>>> img.drawRectangle(bb[0],bb[1],bb[2],bb[3])
>>> img.save(disp)
SEE ALSO
rightButtonUpPostion() leftButtonDownPostion() rightButtonDownPostion() pointsToBoundingBox()
SUMMARY
Given two screen cooridnates return the bounding box in x,y,w,h format. This is helpful for drawing regions on the display.
RETURNS
The bounding box from two coordinates as a ( x,y,w,h) tuple.
EXAMPLE
>>> disp = Display((600,800))
>>> cam = Camera()
>>> while(disp.isNotDone()):
>>> img = cam.getImage()
>>> dwn = disp.leftButtonDownPosition()
>>> up = disp.leftButtonUpPosition()
>>> if( up is not None and dwn is not None):
>>> bb = disp.pointsToBoundingBox(up,dwn)
>>> img.drawRectangle(bb[0],bb[1],bb[2],bb[3])
>>> img.save(disp)
SEE ALSO
leftButtonUpPostion() leftButtonDownPostion() rightButtonDownPostion() rightButtonUpPostion() checkEvents()
quit the pygame instance
Example: >>> img = Image(“simplecv”) >>> d = img.show() >>> time.sleep(5) >>> d.quit()
SUMMARY
Returns the position where the right mouse button went down.
Warning
You must call checkEvents() or isDone() in your main display loop for this method to work.
RETURNS
An (x,y) mouse postion tuple where the mopuse went down.
EXAMPLE
>>> disp = Display((600,800))
>>> cam = Camera()
>>> while(disp.isNotDone()):
>>> img = cam.getImage()
>>> dwn = disp.rightButtonDownPosition()
>>> up = disp.rightButtonUpPosition()
>>> if( up is not None and dwn is not None):
>>> bb = disp.pointsToBoundingBox(up,dwn)
>>> img.drawRectangle(bb[0],bb[1],bb[2],bb[3])
>>> img.save(disp)
SEE ALSO
leftButtonUpPostion() leftButtonDownPostion() rightButtonDownPostion() pointsToBoundingBox() checkEvents()
SUMMARY
Returns the position where the right mouse button went up.
Warning
You must call checkEvents() or isDone() in your main display loop for this method to work.
RETURNS
An (x,y) mouse postion tuple where the mouse went up.
EXAMPLE
>>> disp = Display((600,800))
>>> cam = Camera()
>>> while(disp.isNotDone()):
>>> img = cam.getImage()
>>> dwn = disp.rightButtonDownPosition()
>>> up = disp.rightButtonUpPosition()
>>> if( up is not None and dwn is not None):
>>> bb = disp.pointsToBoundingBox(up,dwn)
>>> img.drawRectangle(bb[0],bb[1],bb[2],bb[3])
>>> img.save(disp)
>>> disp = Display((600,800))
>>> dwn = disp.rightButtonDownPosition()
>>> up = disp.rightButtonUpPosition()
>>> bb = disp.pointsToBoundingBox(up,dwn)
>>> #draw bb
SEE ALSO
leftButtonUpPostion() leftButtonDownPostion() rightButtonDownPostion() pointsToBoundingBox() checkEvents()
SUMMARY
writeFrame copies the given Image object to the display, you can also use Image.save()
Write frame trys to fit the image to the display with the minimum ammount of distortion possible. When fit=True write frame will decide how to scale the image such that the aspect ratio is maintained and the smallest amount of distorition possible is completed. This means the axis that has the minimum scaling needed will be shrunk or enlarged to match the display.
PARAMETERS
RETURNS
Nothing.
EXAMPLE
>>> img = Image("lenna")
>>> disp = Display((512,512))
>>> disp.writeFrame(img)
DrawingLayer gives you a way to mark up Image classes without changing the image data itself. This class wraps pygame’s Surface class and provides basic drawing and text rendering functions
Example: image = Image(“/path/to/image.png”) image2 = Image(“/path/to/image2.png”) image.dl().blit(image2) #write image 2 on top of image
Draw a bezier curve based on a control point and the a number of stapes
Blit one image onto the drawing layer at upper left coordinates
Draw a rectangle given the center (x,y) of the rectangle and dimensions (width, height)
- color - The object’s color as a simple CVColor object, if no value is sepcified
- the default is used.
- alpha - The alpha blending for the object. If this value is -1 then the
- layer default value is used. A value of 255 means opaque, while 0 means transparent.
w - The line width in pixels. This does not work if antialiasing is enabled.
filled -The rectangle is filled in
Draw a circle given a location and a radius.
width - The line width in pixels. This does not work if antialiasing is enabled.
filled -The object is filled in
This method removes all of the drawing on this layer (i.e. the layer is erased completely)
Draw an ellipse given a location and a dimensions.
width - The line width in pixels. This does not work if antialiasing is enabled.
filled -The object is filled in
ezViewText works just like text but it sets both the foreground and background color and overwrites the image pixels. Use this method to make easily viewable text on a dynamic video stream.
fgcolor - The color of the text.
bgcolor - The background color for the text are.
Returns the default alpha value.
Draw a single line from the (x,y) tuple start to the (x,y) tuple stop. Optional parameters:
width - The line width in pixels.
antialias - Draw an antialiased object of width one.
Draw a set of lines from the list of (x,y) tuples points. Lines are draw between each successive pair of points.
Optional parameters:
width - The line width in pixels.
antialias - Draw an antialiased object of width one.
This method returns a list of strings corresponding to the fonts available on the current system.
Draw a polygon from a list of (x,y)
width - The width in pixels. This does not work if antialiasing is enabled.
filled -The object is filled in
antialias - Draw the edges of the object antialiased. Note this does not work when the object is filled.
Draw a rectangle given the topLeft the (x,y) coordinate of the top left corner and dimensions (w,h) tge width and height
w - The line width in pixels. This does not work if antialiasing is enabled.
filled -The rectangle is filled in
Draw a rectangle given two (x,y) points
w - The line width in pixels. This does not work if antialiasing is enabled.
filled -The rectangle is filled in
Add this layer to another layer.
Blit this layer to another surface.
This method allows you to set the surface manually.
This method attempts to set the font from a font file. It is advisable to use one of the fonts listed by the listFonts() method. The input is a string with the font name.
This method sets the default alpha value for all methods called on this layer. The default value starts out at 255 which is completely transparent.
This method sets the default rendering color.
This method sets and unsets the current font to be bold.
This method sets and unsets the current font to be italic.
This method sets the font size roughly in points. A size of 10 is almost too small to read. A size of 20 is roughly 10 pixels high and a good choice.
This method sets and unsets the current font to be underlined
This method sets the alpha value of the entire layer in a single pass. This is helpful for merging layers with transparency.
sprite draws a sprite (a second small image) onto the current layer. The sprite can be loaded directly from a supported image file like a gif, jpg, bmp, or png, or loaded as a surface or SCV image.
pos - the (x,y) position of the upper left hand corner of the sprite
scale - a scale multiplier as a float value. E.g. 1.1 makes the sprite 10% bigger
rot = a rotation angle in degrees
alpha = an alpha value 255=opaque 0=transparent.
Write the a text string at a given location
text - A text string to print.
location-The location to place the top right corner of the text
The textDimensions function takes a string and returns the dimensions (width, height) of this text being rendered on the screen.
The Font class allows you to create a font object to be used in drawing or writing to images. There are some defaults available, to see them, just type Font.printFonts()
Get the font from the object to be used in drawing
Returns: PIL Image Font
This returns the list of fonts built into SimpleCV
Gets the size of the current font
Returns: Integer
This prints a list of fonts built into SimpleCV
Set the name of the font listed in the font family if the font isn’t listed in the font family then pass it the absolute path of the truetype font file. Example: Font.setFont(“/home/simplecv/my_font.ttf”)
Set the font point size. i.e. 16pt
SUMMARY
The colorspace class is used to encapsulate the color space of a given image. This class acts like C/C++ style enumerated type.
See: http://stackoverflow.com/questions/2122706/detect-color-space-with-opencv
SUMMARY
The Image class is the heart of SimpleCV and allows you to convert to and from a number of source types with ease. It also has intelligent buffer management, so that modified copies of the Image required for algorithms such as edge detection, etc can be cached and reused when appropriate.
Image are converted into 8-bit, 3-channel images in RGB colorspace. It will automatically handle conversion from other representations into this standard format. If dimensions are passed, an empty image is created.
EXAMPLE
>>> i = Image("/path/to/image.png")
>>> i = Camera().getImage()
You can also just load the SimpleCV logo using:
>>> img = Image("simplecv")
>>> img = Image("logo")
>>> img = Image("logo_inverted")
>>> img = Image("logo_transparent")
Or you can load an image from a URL:
>>> img = Image("http://www.simplecv.org/image.png")
SUMMARY
This method provides a way of performing an inverse discrete Fourier transform on a real/imaginary image pair and obtaining the result as a SimpleCV image. This method is helpful if you wish to perform custom filter development.
PARAMETERS
RETURNS
A simpleCV image.
EXAMPLE
Note that this is an example, I don’t recommend doing this unless you know what you are doing.
>>> raw = img.getRawDFT()
>>> cv.SomeOperation(raw)
>>> result = img.InverseDFT(raw)
>>> result.show()
SEE ALSO
rawDFTImage() getDFTLogMagnitude() applyDFTFilter() highPassFilter() lowPassFilter() bandPassFilter() InverseDFT() applyButterworthFilter() InverseDFT() applyGaussianFilter() applyUnsharpMask()
SUMMARY
Adapative Scale is used in the Display to automatically adjust image size to match the display size. This method attempts to scale an image to the desired resolution while keeping the aspect ratio the same. If fit is False we simply crop and center the image to the resolution. In general this method should look a lot better than arbitrary cropping and scaling.
PARAMETERS
RETURNS
A SimpleCV Image.
EXAMPLE
This is typically used in this instance:
>>> d = Display((800,600))
>>> i = Image((640, 480))
>>> i.save(d)
Where this would scale the image to match the display size of 800x600
SUMMARY
Push a new drawing layer onto the back of the layer stack
PARAMETERS
RETURNS
The index of the new layer as an integer.
EXAMPLE
>>> img = Image("Lenna")
>>> myLayer = DrawingLayer((img.width,img.height))
>>> img.addDrawingLayer(myLayer)
SEE ALSO
DrawingLayer insertDrawinglayer() addDrawinglayer() dl() toPygameSurface() getDrawingLayer() removeDrawingLayer() clearLayers() layers() mergedLayers() applyLayers() drawText() drawRectangle() drawCircle() blit()
SUMMARY
Apply a binary mask to the image. The white areas of the mask will be kept, and the black areas removed. The removed areas will be set to the color of bg_color.
PARAMETERS
RETURNS
A binary (black/white) image mask as a SimpleCV Image.
EXAMPLE
>>> img = Image("lenna")
>>> mask = img.createBinaryMask(color1=(0,128,128),color2=(255,255,255)
>>> result = img.applyBinaryMask(mask)
>>> result.show()
SEE ALSO
createBinaryMask() createAlphaMask() applyBinaryMask() blit() threshold()
SUMMARY
Creates a butterworth filter of 64x64 pixels, resizes it to fit image, applies DFT on image using the filter. Returns image with DFT applied on it
PARAMETERS
EXAMPLE
>>> im = Image("lenna")
>>> img = applyButterworth(im, dia=400,order=2,highpass=True,grayscale=False)
Output image: http://i.imgur.com/5LS3e.png
>>> img = applyButterworth(im, dia=400,order=2,highpass=False,grayscale=False)
Output img: http://i.imgur.com/QlCAY.png
>>> im = Image("grayscale_lenn.png") #take image from here: http://i.imgur.com/O0gZn.png
>>> img = applyButterworth(im, dia=400,order=2,highpass=True,grayscale=True)
Output img: http://i.imgur.com/BYYnp.png
>>> img = applyButterworth(im, dia=400,order=2,highpass=False,grayscale=True)
Output img: http://i.imgur.com/BYYnp.png
SEE ALSO
rawDFTImage() getDFTLogMagnitude() applyDFTFilter() highPassFilter() lowPassFilter() bandPassFilter() InverseDFT() applyButterworthFilter() InverseDFT() applyGaussianFilter() applyUnsharpMask()
SUMMARY
This function allows you to apply an arbitrary filter to the DFT of an image. This filter takes in a gray scale image, whiter values are kept and black values are rejected. In the DFT image, the lower frequency values are in the corners of the image, while the higher frequency components are in the center. For example, a low pass filter has white squares in the corners and is black everywhere else.
PARAMETERS
RETURNS
A SimpleCV image after applying the filter.
EXAMPLE
>>> filter = Image("MyFilter.png")
>>> myImage = Image("MyImage.png")
>>> result = myImage.applyDFTFilter(filter)
>>> result.show()
SEE ALSO
rawDFTImage() getDFTLogMagnitude() applyDFTFilter() highPassFilter() lowPassFilter() bandPassFilter() InverseDFT() applyButterworthFilter() InverseDFT() applyGaussianFilter() applyUnsharpMask()
TODO
Make this function support a separate filter image for each channel.
SUMMARY
Creates a gaussian filter of 64x64 pixels, resizes it to fit image, applies DFT on image using the filter. Returns image with DFT applied on it
PARAMETERS
EXAMPLE
>>> im = Image("lenna")
>>> img = applyGaussianfilter(im, dia=400,highpass=True,grayscale=False)
Output image: http://i.imgur.com/DttJv.png
>>> img = applyGaussianfilter(im, dia=400,highpass=False,grayscale=False)
Output img: http://i.imgur.com/PWn4o.png
>>> im = Image("grayscale_lenn.png") #take image from here: http://i.imgur.com/O0gZn.png
>>> img = applyGaussianfilter(im, dia=400,highpass=True,grayscale=True)
Output img: http://i.imgur.com/9hX5J.png
>>> img = applyGaussianfilter(im, dia=400,highpass=False,grayscale=True)
Output img: http://i.imgur.com/MXI5T.png
SEE ALSO
rawDFTImage() getDFTLogMagnitude() applyDFTFilter() highPassFilter() lowPassFilter() bandPassFilter() InverseDFT() applyButterworthFilter() InverseDFT() applyGaussianFilter() applyUnsharpMask()
SUMMARY
Apply a color correction curve in HSL space. This method can be used to change values for each channel. The curves are ColorCurve class objects.
PARAMETERS
RETURNS
A SimpleCV Image
EXAMPLE
>>> img = Image("lenna")
>>> hc = ColorCurve([[0,0], [100, 120], [180, 230], [255, 255]])
>>> lc = ColorCurve([[0,0], [90, 120], [180, 230], [255, 255]])
>>> sc = ColorCurve([[0,0], [70, 110], [180, 230], [240, 255]])
>>> img2 = img.applyHLSCurve(hc,lc,sc)
SEE ALSO
ColorCurve applyRGBCurve()
SUMMARY
Intensity applied to all three color channels
PARAMETERS
RETURNS
A SimpleCV Image
EXAMPLE
>>> img = Image("lenna")
>>> rc = ColorCurve([[0,0], [100, 120], [180, 230], [255, 255]])
>>> gc = ColorCurve([[0,0], [90, 120], [180, 230], [255, 255]])
>>> bc = ColorCurve([[0,0], [70, 110], [180, 230], [240, 255]])
>>> img2 = img.applyRGBCurve(rc,gc,bc)
SEE ALSO
ColorCurve applyHLSCurve()
SUMMARY
Apply LUT allows you to apply a LUT (look up table) to the pixels in a image. Each LUT is just an array where each index in the array points to its value in the result image. For example rLUT[0]=255 would change all pixels where the red channel is zero to the value 255.
PARAMETERS
Warning
The dtype is very important. Will throw the following error without it: error: dst.size() == src.size() && dst.type() == CV_MAKETYPE(lut.depth(), src.channels())
RETURNS
The SimpleCV image remapped using the LUT.
EXAMPLE
This example saturates the red channel:
>>> rlut = np.ones((256,1),dtype=uint8)*255
>>> img=img.applyLUT(rLUT=rlut)
NOTE:
-==== BUG NOTE ====- This method seems to error on the LUT map for some versions of OpenCV. I am trying to figure out why. -KAS
SUMMARY
Render all of the layers onto the current image and return the result. Indicies can be a list of integers specifying the layers to be used.
PARAMETERS
RETURNS
The image after applying the drawing layers.
EXAMPLE
>>> img = Image("Lenna")
>>> myLayer1 = DrawingLayer((img.width,img.height))
>>> myLayer2 = DrawingLayer((img.width,img.height))
>>> #Draw some stuff
>>> img.insertDrawingLayer(myLayer1,1) # on top
>>> img.insertDrawingLayer(myLayer2,2) # on the bottom
>>> derp = img.applyLayers()
SEE ALSO
DrawingLayer dl() toPygameSurface() getDrawingLayer() removeDrawingLayer() layers() drawText() drawRectangle() drawCircle() blit()
SUMMARY
apply a function to every pixel and return the result The function must be of the form int (r,g,b)=func((r,g,b))
PARAMETERS
RETURNS
A simpleCV image after mapping the function to the image.
EXAMPLE
>>> def derp(pixels):
>>> return (int(b*.2),int(r*.3),int(g*.5))
>>>
>>> img = Image("lenna")
>>> img2 = img.applyPixelFunction(derp)
SUMMARY
Apply a color correction curve in RGB space. This method can be used to change values for each channel. The curves are ColorCurve class objects.
PARAMETERS
RETURNS
A SimpleCV Image
EXAMPLE
>>> img = Image("lenna")
>>> rc = ColorCurve([[0,0], [100, 120], [180, 230], [255, 255]])
>>> gc = ColorCurve([[0,0], [90, 120], [180, 230], [255, 255]])
>>> bc = ColorCurve([[0,0], [70, 110], [180, 230], [240, 255]])
>>> img2 = img.applyRGBCurve(rc,gc,bc)
SEE ALSO
ColorCurve applyHLSCurve()
SUMMARY
This method applies unsharp mask or highboost filtering on image depending upon the boost value provided. DFT is applied on image using gaussian lowpass filter. A mask is created subtracting the DFT image from the original iamge. And then mask is added in the image to sharpen it. unsharp masking => image + mask highboost filtering => image + (boost)*mask
PARAMETERS
EXAMPLE
Gaussian Filters:
>>> im = Image("lenna")
>>> img = applyUnsharpMask(im,2,grayscale=False) #highboost filtering
output image: http://i.imgur.com/A1pZf.png
>>> img = applyUnsharpMask(im,1,grayscale=False) #unsharp masking
output image: http://i.imgur.com/smCdL.png
>>> im = Image("grayscale_lenn.png") #take image from here: http://i.imgur.com/O0gZn.png
>>> img = applyUnsharpMask(im,2,grayscale=True) #highboost filtering
output image: http://i.imgur.com/VtGzl.png
>>> img = applyUnsharpMask(im,1,grayscale=True) #unsharp masking
output image: http://i.imgur.com/bywny.png
SEE ALSO
rawDFTImage() getDFTLogMagnitude() applyDFTFilter() highPassFilter() lowPassFilter() bandPassFilter() InverseDFT() applyButterworthFilter() InverseDFT() applyGaussianFilter() applyUnsharpMask()
SUMMARY
This method applies a simple band pass DFT filter. This filter enhances the a range of frequencies and removes all of the other frequencies. This allows a user to precisely select a set of signals to display . The frequencies are defined as going between 0.00 and 1.00 and where 0 is the lowest frequency in the image and 1.0 is the highest possible frequencies. Each of the frequencies are defined with respect to the horizontal and vertical signal. This filter isn’t perfect and has a harsh cutoff that causes ringing artifacts.
PARAMETERS
RETURNS
A SimpleCV Image after applying the filter.
EXAMPLE
>>> img = Image("SimpleCV/sampleimages/RedDog2.jpg")
>>> img.getDFTLogMagnitude().show()
>>> lpf = img.bandPassFilter([0.2,0.2,0.05],[0.3,0.3,0.2])
>>> lpf.show()
>>> lpf.getDFTLogMagnitude().show()
NOTES
This filter is far from perfect and will generate a lot of ringing artifacts.
See: http://en.wikipedia.org/wiki/Ringing_(signal)
SEE ALSO
rawDFTImage() getDFTLogMagnitude() applyDFTFilter() highPassFilter() lowPassFilter() bandPassFilter() InverseDFT() applyButterworthFilter() InverseDFT() applyGaussianFilter() applyUnsharpMask()
SUMMARY
Convience function derived from the smooth() method Perform a bilateral filtering operation to denoise/despeckle the image. The optional parameter is the window size.
NOTES
Bilateral Filter http://en.wikipedia.org/wiki/Bilateral_filter
SUMMARY
Do a binary threshold the image, changing all values below thresh to maxv and all above to black. If a color tuple is provided, each color channel is thresholded separately.
If threshold is -1 (default), an adaptive method (OTSU’s method) is used. If then a blocksize is specified, a moving average over each region of block*block pixels a threshold is applied where threshold = local_mean - p.
PARAMETERS
Warning
This parameter must be an odd number.
RETURNS
A binary (two colors, usually black and white) SimpleCV image. This works great for the findBlobs family of functions.
EXAMPLE
Example of a vanila threshold versus an adaptive threshold:
>>> img = Image("orson_welles.jpg")
>>> b1 = img.binarize(128)
>>> b2 = img.binarize(blocksize=11,p=7)
>>> b3 = b1.sideBySide(b2)
>>> b3.show()
NOTES
Otsu’s Method Description<http://en.wikipedia.org/wiki/Otsu’s_method>
SEE ALSO
SUMMARY
This method uses the color palette to generate a binary (black and white) image. Palaette selection is a list of color tuples retrieved from img.getPalette(). The provided values will be drawn white while other values will be black.
PARAMETERS
palette_selection - color triplets selected from our palette that will serve turned into blobs These values can either be a 3xN numpy array, or a list of RGB triplets.
RETURNS
This method returns a black and white images, where colors that are close to the colors in palette_selection are set to white
EXAMPLE
>>> img = Image("lenna")
>>> p = img.getPalette()
>>> b = img.binarizeFromPalette( (p[0],p[1],[6]) )
>>> b.show()
SEE ALSO
rePalette() drawPaletteColors() palettize() getPalette() binarizeFromPalette() findBlobsFromPalette()
SUMMARY
Blit aka bit blit - which in ye olden days was an acronym for bit-block transfer. In other words blit is when you want to smash two images together, or add one image to another. This method takes in a second SimpleCV image, and then allows you to add to some point on the calling image. A general blit command will just copy all of the image. You can also copy the image with an alpha value to the source image is semi-transparent. A binary mask can be used to blit non-rectangular image onto the souce image. An alpha mask can be used to do and arbitrarily transparent image to this image. Both the mask and alpha masks are SimpleCV Images.
PARAMETERS
RETURNS
A SimpleCV Image. The size will remain the same.
EXAMPLE
>>> topImg = Image("top.png")
>>> bottomImg = Image("bottom.png")
>>> mask = Image("mask.png")
>>> aMask = Image("alpphaMask.png")
>>> bottomImg.blit(top,pos=(100,100)).show()
>>> bottomImg.blit(top,alpha=0.5).show()
>>> bottomImg.blit(top,pos=(100,100),mask=mask).show()
>>> bottomImg.blit(top,pos=(-10,-10)alphaMask=aMask).show()
SEE ALSO
SUMMARY
This is a slightly unsafe method that clears out the entire image state it is usually used in conjunction with the drawing blobs to fill in draw a single large blob in the image.
SUMMARY
Remove all of the drawing layers.
RETURNS
None.
EXAMPLE
>>> img = Image("Lenna")
>>> myLayer1 = DrawingLayer((img.width,img.height))
>>> myLayer2 = DrawingLayer((img.width,img.height))
>>> img.insertDrawingLayer(myLayer1,1) # on top
>>> img.insertDrawingLayer(myLayer2,2) # on the bottom
>>> img.clearLayers()
SEE ALSO
DrawingLayer dl() toPygameSurface() getDrawingLayer() removeDrawingLayer() layers() mergedLayers() applyLayers() drawText() drawRectangle() drawCircle() blit()
SUMMARY
Returns an image representing the distance of each pixel from a given color tuple, scaled between 0 (the given color) and 255. Pixels distant from the given tuple will appear as brighter and pixels closest to the target color will be darker.
By default this will give image intensity (distance from pure black)
PARAMETERS
RETURNS
A SimpleCV Image.
EXAMPLE
>>> img = Image("logo")
>>> img2 = img.colorDistance(color=Color.BLACK)
>>> img2.show()
SEE ALSO
SUMMARY
Convolution performs a shape change on an image. It is similiar to something like a dilate. You pass it a kernel in the form of a list, np.array, or cvMat
PARAMETERS
RETURNS
The image after we apply the convolution.
EXAMPLE
>>> img = Image("sampleimages/simplecv.png")
>>> kernel = [[1,0,0],[0,1,0],[0,0,1]]
>>> conv = img.convolve()
SEE ALSO
SUMMARY
Return a full copy of the Image’s bitmap. Note that this is different from using python’s implicit copy function in that only the bitmap itself is copied. This method essentially performs a deep copy.
RETURNS
A copy of this SimpleCV image.
EXAMPLE
>>> img = Image("logo")
>>> img2 = img.copy()
SUMMARY
Generate a grayscale or binary mask image based either on a hue or an RGB triplet that can be used like an alpha channel. In the resulting mask, the hue/rgb_color will be treated as transparent (black).
When a hue is used the mask is treated like an 8bit alpha channel. When an RGB triplet is used the result is a binary mask. rgb_thresh is a distance measure between a given a pixel and the mask value that we will add to the mask. For example, if rgb_color=(0,255,0) and rgb_thresh=5 then any pixel winthin five color values of the rgb_color will be added to the mask (e.g. (0,250,0),(5,255,0)....)
Invert flips the mask values.
PARAMETERS
RETURNS
A grayscale alpha mask as a SimpleCV Image.
>>> img = Image("lenna")
>>> mask = img.createAlphaMask(hue_lb=50,hue_ub=70)
>>> mask.show()
SEE ALSO
createBinaryMask() createAlphaMask() applyBinaryMask() blit() threshold()
SUMMARY
Generate a binary mask of the image based on a range of rgb values. A binary mask is a black and white image where the white area is kept and the black area is removed.
This method is used by specifying two colors as the range between the minimum and maximum values that will be masked white.
PARAMETERS
RETURNS
A binary (black/white) image mask as a SimpleCV Image.
EXAMPLE
>>> img = Image("lenna")
>>> mask = img.createBinaryMask(color1=(0,128,128),color2=(255,255,255)
>>> mask.show()
SEE ALSO
SUMMARY
Crop attempts to use the x and y position variables and the w and h width and height variables to crop the image. When centered is false, x and y define the top and left of the cropped rectangle. When centered is true the function uses x and y as the centroid of the cropped region.
You can also pass a feature into crop and have it automatically return the cropped image within the bounding outside area of that feature
PARAMETERS
RETURNS
A SimpleCV Image cropped to the specified width and height.
EXAMPLE
>>> img = Image('lenna')
>>> img.crop(50,40,128,128).show()
SEE ALSO
SUMMARY
Apply a morphological dilation. An dilation has the effect of smoothing blobs while intensifying the amount of noise blobs. This implementation uses the default openCV 3X3 square kernel Erosion is effectively a local maxima detector, the kernel moves over the image and takes the maxima value inside the kernel.
PARAMETERS
RETURNS
A SimpleCV image.
EXAMPLE
>>> img = Image("lenna")
>>> derp = img.binarize()
>>> derp.dilate(3).show()
SEE ALSO
erode() binarize() morphOpen() morphClose() morphGradient() findBlobsFromMask()
SUMMARY
Alias for getDrawingLayer()
SUMMARY
Draw a circle on the image.
PARAMETERS
RETURNS
Warning
This is an inline operation. Nothing is returned, but a circle is drawn on the images’s drawing layer.
EXAMPLE
>>> img = Image("lenna")
>>> img.drawCircle((img.width/2,img.height/2),r=50,color=Colors.RED,width=3)
>>> img.show()
NOTES
Warning
Note that this function is depricated, try to use DrawingLayer.circle() instead.
SEE ALSO
drawLine() drawText() dl() drawRectangle() DrawingLayer
SUMMARY
Draw keypoints draws a side by side representation of two images, calculates keypoints for both images, determines the keypoint correspondences, and then draws the correspondences. This method is helpful for debugging keypoint calculations and also looks really cool :) . The parameters mirror the parameters used for findKeypointMatches to assist with debugging
PARAMETERS
RETURNS
A side by side image of the template and source image with each feature correspondence draw in a different color.
EXAMPLE
>>> img = cam.getImage()
>>> template = Image("myTemplate.png")
>>> result = img.drawKeypointMatches(self,template,300.00,0.4):
NOTES
If you would prefer to work with the raw keypoints and descriptors each image keeps a local cache of the raw values. These are named:
self._mKeyPoints # A tuple of keypoint objects See: http://opencv.itseez.com/modules/features2d/doc/common_interfaces_of_feature_detectors.html#keypoint-keypoint self._mKPDescriptors # The descriptor as a floating point numpy array self._mKPFlavor = “NONE” # The flavor of the keypoints as a string.
SEE ALSO
SUMMARY Draw a line on the image.
PARAMETERS
RETURNS
Warning
This is an inline operation. Nothing is returned, but a circle is drawn on the images’s drawing layer.
EXAMPLE
>>> img = Image("lenna")
>>> img.drawLine((0,0),(img.width,img.height),color=Color.RED,thickness=3)
>>> img.show()
NOTES
Warning
Note that this function is depricated, try to use DrawingLayer.line() instead.
SEE ALSO
SUMMARY
This method returns the visual representation (swatches) of the palette in an image. The palette is orientated either horizontally or vertically, and each color is given an area proportional to the number of pixels that have that color in the image. The palette is arranged as it is returned from the clustering algorithm. When size is left to its default value, the palette size will match the size of the orientation, and then be 10% of the other dimension. E.g. if our image is 640X480 the horizontal palette will be (640x48) likewise the vertical palette will be (480x64)
If a Hue palette is used this method will return a grayscale palette.
PARAMETERS
RETURNS
A palette swatch image.
EXAMPLE
>>> p = img1.drawPaletteColors()
>>> img2 = img1.sideBySide(p,side="bottom")
>>> img2.show()
NOTES
The hue calculations should be siginificantly faster than the generic RGB calculation as it works in a one dimensional space. Sometimes the underlying scipy method freaks out about k-means initialization with the following warning:
Warning
One of the clusters is empty. Re-run kmean with a different initialization. This shouldn’t be a real problem.
SEE ALSO
rePalette() drawPaletteColors() palettize() getPalette() binarizeFromPalette() findBlobsFromPalette()
SUMMARY
Draw a rectangle on the screen given the upper left corner of the rectangle and the width and height.
PARAMETERS
RETURNS
None - this operation is in place and adds the rectangle to the drawing layer.
EXAMPLE
>>> img = Image("lenna")
>>> img.drawREctange( 50,50,100,123)
>>> img.show()
SEE ALSO
dl() drawCircle() drawRectangle() applyLayers() DrawingLayer
SUMMARY
Draw the minimum bouding rectangle. This rectangle is a series of four points.
TODO
KAT FIX THIS
SUMMARY
This function draws the string that is passed on the screen at the specified coordinates.
The Default Color is blue but you can pass it various colors
The text will default to the center of the screen if you don’t pass it a value
PARAMETERS
RETURNS
Nothing. This is an in place function. Text is added to the Images drawing layer.
EXAMPLE
>>> img = Image("lenna")
>>> img.writeText("xamox smells like cool ranch doritos.", 50,50,color=Color.BLACK,fontSize=48)
>>> img.show()
SEE ALSO
SUMMARY
Finds an edge map Image using the Canny edge detection method. Edges will be brighter than the surrounding area.
The t1 parameter is roughly the “strength” of the edge required, and the value between t1 and t2 is used for edge linking.
For more information:
PARAMETERS
RETURNS
A SimpleCV image where the edges are white on a black background.
EXAMPLE
>>> cam = Camera()
>>> while True:
>>> cam.getImage().edges().show()
SEE ALSO
SUMMARY
Make the canvas larger but keep the image the same size.
PARAMETERS
RETURNS
The enlarged SimpleCV Image.
EXAMPLE
>>> img = Image("lenna")
>>> img = img.embiggen((1024,1024),color=Color.BLUE)
>>> img.show()
SUMMARY
Perform a histogram equalization on the image.
RETURNS
Returns a grayscale SimpleCV image.
EXAMPLE
>>> img = Image("lenna")
>>> img = img.equalize()
SUMMARY
Apply a morphological erosion. An erosion has the effect of removing small bits of noise and smothing blobs.
This implementation uses the default openCV 3X3 square kernel
Erosion is effectively a local minima detector, the kernel moves over the image and takes the minimum value inside the kernel. iterations - this parameters is the number of times to apply/reapply the operation
PARAMETERS
RETURNS
A SimpleCV image.
EXAMPLE
>>> img = Image("lenna")
>>> derp = img.binarize()
>>> derp.erode(3).show()
SEE ALSO dilate() binarize() morphOpen() morphClose() morphGradient() findBlobsFromMask()
SUMMARY
If you have the python-zxing library installed, you can find 2d and 1d barcodes in your image. These are returned as Barcode feature objects in a FeatureSet. The single parameter is the ZXing_path, if you don’t have the ZXING_LIBRARY env parameter set.
You can clone python-zxing at:
http://github.com/oostendo/python-zxing
INSTALLING ZEBRA CROSSING
Download the latest version of zebra crossing from: http://code.google.com/p/zxing/
unpack the zip file where ever you see fit
>>> cd zxing-x.x, where x.x is the version number of zebra crossing
>>> ant -f core/build.xml
>>> ant -f javase/build.xml
This should build the library, but double check the readme
Get our helper library
>>> git clone git://github.com/oostendo/python-zxing.git
>>> cd python-zxing
>>> python setup.py install
it to your path variables. On OSX/Linux use a text editor to modify your shell file (e.g. .bashrc)
export ZXING_LIBRARY=<FULL PATH OF ZXING LIBRARY - (i.e. step 2)> for example:
export ZXING_LIBRARY=/my/install/path/zxing-x.x/
On windows you will need to add these same variables to the system variable, e.g.
On OSX/Linux source your shell rc file (e.g. source .bashrc). Windows users may need to restart.
Go grab some barcodes!
Warning
Users on OSX may see the following error:
RuntimeWarning: tmpnam is a potential security risk to your program
We are working to resolve this issue. For normal use this should not be a problem.
PARAMETERS
Returns
A FeatureSet of Barcode objects. If no barcodes are detected the method returns None.
EXAMPLE
>>> bc = cam.getImage()
>>> barcodes = img.findBarcodes()
>>> for b in barcodes:
>>> b.draw()
SEE ALSO
FeatureSet Barcode
SUMMARY
Find blobs will look for continuous light regions and return them as Blob features in a FeatureSet. Parameters specify the binarize filter threshold value, and minimum and maximum size for blobs. If a threshold value is -1, it will use an adaptive threshold. See binarize() for more information about thresholding. The threshblocksize and threshconstant parameters are only used for adaptive threshold.
PARAMETERS
Warning
This parameter must be an odd number.
RETURNS
Returns a featureset (basically a list) of blob features. If no blobs are found this method returns None.
EXAMPLE
>>> img = Image("lenna")
>>> fs = img.findBlobs()
>>> if( fs is not None ):
>>> fs.draw()
NOTES
Warning
For blobs that live right on the edge of the image OpenCV reports the position and width height as being one over for the true position. E.g. if a blob is at (0,0) OpenCV reports its position as (1,1). Likewise the width and height for the other corners is reported as being one less than the width and height. This is a known bug.
SEE ALSO threshold() binarize() invert() dilate() erode() findBlobsFromPalette() smartFindBlobs()
SUMMARY
This method acts like findBlobs, but it lets you specifiy blobs directly by providing a mask image. The mask image must match the size of this image, and the mask should have values > threshold where you want the blobs selected. This method can be used with binarize, dialte, erode, floodFill, edges etc to get really nice segmentation.
PARAMETERS
RETURNS
A featureset of blobs. If no blobs are found None is returned.
EXAMPLE
>>> img = Image("Foo.png")
>>> mask = img.binarize().dilate(2)
>>> blobs = img.findBlobsFromMask(mask)
>>> blobs.show()
SEE ALSO
SUMMARY
This method attempts to use palettization to do segmentation and behaves similar to the findBlobs blob in that it returs a feature set of blob objects. Once a palette has been extracted using getPalette() we can then select colors from that palette to be labeled white within our blobs.
PARAMETERS
- palette_selection - color triplets selected from our palette that will serve turned into blobs These values can either be a 3xN numpy array, or a list of RGB triplets.
- dilate - the optional number of dilation operations to perform on the binary image prior to performing blob extraction.
- minsize - the minimum blob size in pixels
- maxsize - the maximim blob size in pixels.
RETURNS
If the method executes successfully a FeatureSet of Blobs is returned from the image. If the method fails a value of None is returned.
EXAMPLE
>>> img = Image("lenna") >>> p = img.getPalette() >>> blobs = img.findBlobsFromPalette( (p[0],p[1],[6]) ) >>> blobs.draw() >>> img.show()SEE ALSO
rePalette() drawPaletteColors() palettize() getPalette() binarizeFromPalette() findBlobsFromPalette()
SUMMARY
Given an image, finds a chessboard within that image. Returns the Chessboard featureset. The Chessboard is typically used for calibration because of its evenly spaced corners.
The single parameter is the dimensions of the chessboard, typical one can be found in SimpleCV oolsCalibGrid.png
PARAMETERS
RETURNS
A FeatureSet of Chessboard objects. If no chessboards are found None is returned.
EXAMPLE
>>> img = cam.getImage()
>>> cb = img.findChessboard()
>>> cb.draw()
SEE ALSO
FeatureSet Chessboard
SUMMARY
Perform the Hough Circle transform to extract _perfect_ circles from the image canny - the upper bound on a canny edge detector used to find circle edges.
PARAMETERS
RETURNS
A feature set of Circle objects.
EXAMPLE
>>> img = Image("lenna")
>>> circs = img.findCircles()
>>> for c in circs:
>>> print c
SUMMARY
This will find corner Feature objects and return them as a FeatureSet strongest corners first. The parameters give the number of corners to look for, the minimum quality of the corner feature, and the minimum distance between corners.
PARAMETERS
RETURNS
A featureset of Corner features or None if no corners are found.
EXAMPLE
Standard Test:
>>> img = Image("sampleimages/simplecv.png")
>>> corners = img.findCorners()
>>> if corners: True
True
Validation Test:
>>> img = Image("sampleimages/black.png")
>>> corners = img.findCorners()
>>> if not corners: True
True
SEE ALSO
Corner findKeypoints()
SUMMARY
This method lets you use a flood fill operation and pipe the results to findBlobs. You provide the points to seed floodFill and the rest is taken care of.
floodFill works just like ye olde paint bucket tool in your favorite image manipulation program. You select a point (or a list of points), a color, and a tolerance, and floodFill will start at that point, looking for pixels within the tolerance from your intial pixel. If the pixel is in tolerance, we will convert it to your color, otherwise the method will leave the pixel alone. The method accepts both single values, and triplet tuples for the tolerance values. If you require more control over your tolerance you can use the upper and lower values. The fixed range parameter let’s you toggle between setting the tolerance with repect to the seed pixel, and using a tolerance that is relative to the adjacent pixels. If fixed_range is true the method will set its tolerance with respect to the seed pixel, otherwise the tolerance will be with repsect to adjacent pixels.
PARAMETERS
RETURNS
A featureset of blobs. If no blobs are found None is returned.
An Image where the values similar to the seed pixel have been replaced by the input color.
EXAMPLE
>>> img = Image("lenna")
>>> blerbs = img.findFloodFillBlobs(((10,10),(20,20),(30,30)),tolerance=30)
>>> blerbs.show()
SEE ALSO
SUMMARY
A Haar like feature cascase is a really robust way of finding the location of a known object. This technique works really well for a few specific applications like face, pedestrian, and vehicle detection. It is worth noting that this approach IS NOT A MAGIC BULLET . Creating a cascade file requires a large number of images that have been sorted by a human.vIf you want to find Haar Features (useful for face detection among other purposes) this will return Haar feature objects in a FeatureSet.
For more information, consult the cv.HaarDetectObjects documentation.
To see what features are available run img.listHaarFeatures() or you can provide your own haarcascade file if you have one available.
Note that the cascade parameter can be either a filename, or a HaarCascade loaded with cv.Load(), or a SimpleCV HaarCascade object.
PARAMETERS
RETURNS
A feature set of HaarFeatures
EXAMPLE
>>> faces = HaarCascade("./SimpleCV/Features/HaarCascades/face.xml","myFaces")
>>> cam = Camera()
>>> while True:
>>> f = cam.getImage().findHaarFeatures(faces)
>>> if( f is not None ):
>>> f.show()
NOTES
http://en.wikipedia.org/wiki/Haar-like_features
The video on this pages shows how Haar features and cascades work to located faces:
http://dismagazine.com/dystopia/evolved-lifestyles/8115/anti-surveillance-how-to-hide-from-machines/
SUMMARY
findKeypointMatch allows you to match a template image with another image using SURF keypoints. The method extracts keypoints from each image, uses the Fast Local Approximate Nearest Neighbors algorithm to find correspondences between the feature points, filters the correspondences based on quality, and then, attempts to calculate a homography between the two images. This homography allows us to draw a matching bounding box in the source image that corresponds to the template. This method allows you to perform matchs the ordinarily fail when using the findTemplate method. This method should be able to handle a reasonable changes in camera orientation and illumination. Using a template that is close to the target image will yield much better results.
Warning
This method is only capable of finding one instance of the template in an image. If more than one instance is visible the homography calculation and the method will fail.
PARAMETERS
RETURNS
If a homography (match) is found this method returns a feature set with a single KeypointMatch feature. If no match is found None is returned.
EXAMPLE
>>> template = Image("template.png")
>>> img = camera.getImage()
>>> fs = img.findKeypointMatch(template)
>>> if( fs is not None ):
>>> fs[0].draw()
>>> img.show()
NOTES
If you would prefer to work with the raw keypoints and descriptors each image keeps a local cache of the raw values. These are named:
SEE ALSO
_getRawKeypoints() _getFLANNMatches() drawKeypointMatches() findKeypoints()
SUMMARY
This method finds keypoints in an image and returns them as a feature set. Keypoints are unique regions in an image that demonstrate some degree of invariance to changes in camera pose and illumination. They are helpful for calculating homographies between camera views, object rotations, and multiple view overlaps.
We support four keypoint detectors and only one form of keypoint descriptors. Only the surf flavor of keypoint returns feature and descriptors at this time.
PARAMETERS
min_quality - The minimum quality metric for SURF descriptors. Good values range between about 300.00 and 600.00
flavor - a string indicating the method to use to extract features. A good primer on how feature/keypoint extractiors can be found in feature detection on wikipedia and this tutorial.
“SURF” - extract the SURF features and descriptors. If you don’t know what to use, use this.
“STAR” - The STAR feature extraction algorithm
“FAST” - The FAST keypoint extraction algorithm
See: http://en.wikipedia.org/wiki/Corner_detection#AST_based_feature_detectors
highQuality - The SURF descriptor comes in two forms, a vector of 64 descriptor values and a vector of 128 descriptor values. The latter are “high” quality descriptors.
RETURNS
A feature set of KeypointFeatures. These KeypointFeatures let’s you draw each feature, crop the features, get the feature descriptors, etc.
EXAMPLE
>>> img = Image("aerospace.jpg")
>>> fs = img.findKeypoints(flavor="SURF",min_quality=500,highQuality=True)
>>> fs = fs.sortArea()
>>> fs[-1].draw()
>>> img.draw()
NOTES
If you would prefer to work with the raw keypoints and descriptors each image keeps a local cache of the raw values. These are named:
_getRawKeypoints() _getFLANNMatches() drawKeypointMatches() findKeypoints()
SUMMARY
findLines will find line segments in your image and returns line feature objects in a FeatureSet. This method uses the Hough (pronounced “HUFF”) transform.
See http://en.wikipedia.org/wiki/Hough_transform
PARAMETERS
RETURNS
Returns a FeatureSet of Line objects. If no lines are found the method returns None.
EXAMPLE
>>> img = Image("lenna")
>>> lines = img.findLines()
>>> lines.draw()
>>> img.show()
SEE ALSO FeatureSet Line edges()
SUMMARY
findMotion performs an optical flow calculation. This method attempts to find motion between two subsequent frames of an image. You provide it with the previous frame image and it returns a feature set of motion fetures that are vectors in the direction of motion.
PARAMETERS
RETURNS
A featureset of motion objects.
EXAMPLES
>>> cam = Camera()
>>> img1 = cam.getImage()
>>> img2 = cam.getImage()
>>> motion = img2.findMotion(img1)
>>> motion.draw()
>>> img2.show()
SEE ALSO
Motion FeatureSet
SUMMARY
This function searches an image for a template image. The template image is a smaller image that is searched for in the bigger image. This is a basic pattern finder in an image. This uses the standard OpenCV template (pattern) matching and cannot handle scaling or rotation
Template matching returns a match score for every pixel in the image. Often pixels that are near to each other and a close match to the template are returned as a match. If the threshold is set too low expect to get a huge number of values. The threshold parameter is in terms of the number of standard deviations from the mean match value you are looking
For example, matches that are above three standard deviations will return 0.1% of the pixels. In a 800x600 image this means there will be 800*600*0.001 = 480 matches.
This method returns the locations of wherever it finds a match above a threshold. Because of how template matching works, very often multiple instances of the template overlap significantly. The best approach is to find the centroid of all of these values. We suggest using an iterative k-means approach to find the centroids.
PARAMETERS
EXAMPLE
>>> image = Image("/path/to/img.png")
>>> pattern_image = image.crop(100,100,100,100)
>>> found_patterns = image.findTemplate(pattern_image)
>>> found_patterns.draw()
>>> image.show()
RETURNS
This method returns a FeatureSet of TemplateMatch objects.
SUMMARY
Horizontally mirror an image.
Warning
Note that flip does not mean rotate 180 degrees! The two are different.
RETURNS
The flipped SimpleCV image.
EXAMPLE
>>> img = Image("lenna")
>>> upsidedown = img.flipHorizontal()
SEE ALSO
SUMMARY
Vertically mirror an image.
Warning
Note that flip does not mean rotate 180 degrees! The two are different.
RETURNS
The flipped SimpleCV image.
EXAMPLE
>>> img = Image("lenna")
>>> upsidedown = img.flipHorizontal()
SEE ALSO
SUMMARY
FloodFill works just like ye olde paint bucket tool in your favorite image manipulation program. You select a point (or a list of points), a color, and a tolerance, and floodFill will start at that point, looking for pixels within the tolerance from your intial pixel. If the pixel is in tolerance, we will convert it to your color, otherwise the method will leave the pixel alone. The method accepts both single values, and triplet tuples for the tolerance values. If you require more control over your tolerance you can use the upper and lower values. The fixed range parameter let’s you toggle between setting the tolerance with repect to the seed pixel, and using a tolerance that is relative to the adjacent pixels. If fixed_range is true the method will set its tolerance with respect to the seed pixel, otherwise the tolerance will be with repsect to adjacent pixels.
PARAMETERS
RETURNS
An Image where the values similar to the seed pixel have been replaced by the input color.
EXAMPLE
>>> img = Image("lenna")
>>> img2 = img.floodFill(((10,10),(54,32)),tolerance=(10,10,10),color=Color.RED)
>>> img2.show()
SEE ALSO
SUMMARY
floodFillToMask works sorta paint bucket tool in your favorite image manipulation program. You select a point (or a list of points), a color, and a tolerance, and floodFill will start at that point, looking for pixels within the tolerance from your intial pixel. If the pixel is in tolerance, we will convert it to your color, otherwise the method will leave the pixel alone. Unlike regular floodFill, floodFillToMask, will return a binary mask of your flood fill operation. This is handy if you want to extract blobs from an area, or create a selection from a region. The method takes in an optional mask. Non-zero values of the mask act to block the flood fill operations. This is handy if you want to use an edge image to “stop” the flood fill operation within a particular region.
The method accepts both single values, and triplet tuples for the tolerance values. If you require more control over your tolerance you can use the upper and lower values. The fixed range parameter let’s you toggle between setting the tolerance with repect to the seed pixel, and using a tolerance that is relative to the adjacent pixels. If fixed_range is true the method will set its tolerance with respect to the seed pixel, otherwise the tolerance will be with repsect to adjacent pixels.
PARAMETERS
RETURNS
An Image where the values similar to the seed pixel have been replaced by the input color.
EXAMPLE
>>> img = Image("lenna")
>>> mask = img.edges()
>>> mask= img.floodFillToMask(((10,10),(54,32)),tolerance=(10,10,10),mask=mask)
>>> mask.show
SEE ALSO
SUMMARY
Retrieve the bitmap (iplImage) of the Image. This is useful if you want to use functions from OpenCV with SimpleCV’s image class
RETURNS
Returns black OpenCV IplImage from this image.
EXAMPLE
>>> img = Image("lenna")
>>> rawImg = img.getBitmap()
>>> rawOut = img.getEmpty()
>>> cv.SomeOpenCVFunc(rawImg,rawOut)
SEE ALSO
getEmpty() getFPMatrix() getPIL() getNumpy() getGrayNumpy() getGrayscaleMatrix()
SUMMARY
Returns the value matched in the color space class
RETURNS
Integer corresponding to the color space.
EXAMPLE
>>> if(image.getColorSpace() == ColorSpace.RGB)
SEE ALSO
SUMMARY
This method returns the log value of the magnitude image of the DFT transform. This method is helpful for examining and comparing the results of DFT transforms. The log component helps to “squish” the large floating point values into an image that can be rendered easily.
In the image the low frequency components are in the corners of the image and the high frequency components are in the center of the image.
PARAMETERS
RETURNS
Returns a SimpleCV image corresponding to the log magnitude of the input image.
EXAMPLE
>>> img = Image("RedDog2.jpg")
>>> img.getDFTLogMagnitude().show()
>>> lpf = img.lowPassFilter(img.width/10.img.height/10)
>>> lpf.getDFTLogMagnitude().show()
NOTES
SEE ALSO
rawDFTImage() getDFTLogMagnitude() applyDFTFilter() highPassFilter() lowPassFilter() bandPassFilter() InverseDFT() applyButterworthFilter() InverseDFT() applyGaussianFilter() applyUnsharpMask()
SUMMARY
Return a drawing layer based on the provided index. If not provided, will default to the top layer. If no layers exist, one will be created
PARAMETERS
RETURNS
A drawing layer.
EXAMPLE
>>> img = Image("Lenna")
>>> myLayer1 = DrawingLayer((img.width,img.height))
>>> myLayer2 = DrawingLayer((img.width,img.height))
>>> #Draw on the layers
>>> img.insertDrawingLayer(myLayer1,1) # on top
>>> img.insertDrawingLayer(myLayer2,2) # on the bottom
>>> layer2 =img.getDrawingLayer(2)
SEE ALSO
DrawingLayer addDrawinglayer() dl() toPygameSurface() getDrawingLayer() removeDrawingLayer() clearLayers() layers() mergedLayers() applyLayers() drawText() drawRectangle() drawCircle() blit()
SUMMARY
This function extracts the exif data from an image file like JPEG or TIFF. The data is returned as a dict.
RETURNS
A dictionary of key value pairs. The value pairs are defined in the EXIF.py file.
EXAMPLE
>>> img = Image("./SimpleCV/sampleimages/OWS.jpg")
>>> data = img.getEXIFData()
>>> data['Image GPSInfo'].values
NOTES
See Also
EXIF
SUMMARY
Create a new, empty OpenCV bitmap with the specified number of channels (default 3). This method basically creates an empty copy of the image. This is handy for interfacing with OpenCV functions directly.
PARAMETERS
RETURNS
Returns an black OpenCV IplImage that matches the width, height, and color depth of the source image.
EXAMPLE
>>> img = Image("lenna")
>>> rawImg = img.getEmpty()
>>> cv.SomeOpenCVFunc(img.getBitmap(),rawImg)
SEE ALSO
getBitmap() getFPMatrix() getPIL() getNumpy() getGrayNumpy() getGrayscaleMatrix()
SUMMARY
Converts the standard int bitmap to a floating point bitmap. This is handy for some OpenCV functions.
RETURNS
Returns the floating point OpenCV CvMat version of this image.
EXAMPLE
>>> img = Image("lenna")
>>> rawImg = img.getFPMatrix()
>>> rawOut = img.getEmpty()
>>> cv.SomeOpenCVFunc(rawImg,rawOut)
SEE ALSO
getEmpty() getBitmap() getMatrix() getPIL() getNumpy() getGrayNumpy() getGrayscaleMatrix()
SUMMARY
Return a grayscale Numpy array of the image.
RETURNS
Returns the image, converted first to grayscale and then converted to a 2D numpy array.
EXAMPLE
>>> img = Image("lenna")
>>> rawImg = img.getGrayNumpy()
SEE ALSO
getEmpty() getBitmap() getMatrix() getPIL() getNumpy() getGrayNumpy() getGrayscaleMatrix()
SUMMARY
This function returns the gray value for a particular image pixel given a specific row and column.
Warning
This function will always return pixels in RGB format even if the image is BGR format.
PARAMETERS
RETURNS
A gray value integer between 0 and 255.
EXAMPLE
>>> img = Image(logo)
>>> color = img.getGrayPixel(10,10)
Warning
We suggest that this method be used sparingly. For repeated pixel access use python array notation. I.e. img[x][y].
SUMMARY
Get the grayscale matrix (cvMat) version of the image, required for some OpenCV algorithms.
RETURNS
Returns the OpenCV CvMat version of this image.
EXAMPLE
>>> img = Image("lenna")
>>> rawImg = img.getGrayscaleMatrix()
>>> rawOut = img.getEmpty()
>>> cv.SomeOpenCVFunc(rawImg,rawOut)
SEE ALSO
getEmpty() getBitmap() getFPMatrix() getPIL() getNumpy() getGrayNumpy() getMatrix()
SUMMARY
This function returns a single row of RGB values from the image. This is handy if you want to crawl the image looking for an edge.
PARAMETERS
RETURNS
A a lumpy numpy array of the pixel values. Ususally this is in BGR format.
EXAMPLE
>>> img = Image("lenna")
>>> myColor = [0,0,0]
>>> sl = img.getHorzScanline(422)
>>> sll = sl.tolist()
>>> for p in sll:
>>> if( p == myColor ):
>>> # do something
SEE ALSO
getHorzScanlineGray() getVertScanlineGray() getVertScanline()
SUMMARY
This function returns a single row of gray values from the image as a numpy array. This is handy if you want to crawl the image looking for an edge.
PARAMETERS
RETURNS
A a lumpy numpy array of the pixel values.
EXAMPLE
>>> img = Image("lenna")
>>> myColor = [255]
>>> sl = img.getHorzScanlineGray(420)
>>> sll = sl.tolist()
>>> for p in sll:
>>> if( p == myColor ):
>>> # do something
SEE ALSO
getHorzScanlineGray() getHorzScanline() getVertScanlineGray() getVertScanline()
SUMMARY
Get the matrix (cvMat) version of the image, required for some OpenCV algorithms.
RETURNS
Returns the OpenCV CvMat version of this image.
EXAMPLE
>>> img = Image("lenna")
>>> rawImg = img.getMatrix()
>>> rawOut = img.getEmpty()
>>> cv.SomeOpenCVFunc(rawImg,rawOut)
SEE ALSO
getEmpty() getBitmap() getFPMatrix() getPIL() getNumpy() getGrayNumpy() getGrayscaleMatrix()
SUMMARY
Get a Numpy array of the image in width x height x RGB dimensions
RETURNS
Returns the image, converted first to grayscale and then converted to a 3D numpy array.
EXAMPLE
>>> img = Image("lenna")
>>> rawImg = img.getNumpy()
SEE ALSO
getEmpty() getBitmap() getMatrix() getPIL() getGrayNumpy() getGrayscaleMatrix()
SUMMARY
Returns the image as a pygame surface. This is used for rendering the display
RETURNS
A pygame surface object used for rendering.
SUMMARY
Get a PIL Image object for use with the Python Image Library This is handy for some PIL functions.
RETURNS
Returns the Python Imaging Library (PIL) version of this image.
EXAMPLE
>>> img = Image("lenna")
>>> rawImg = img.getPIL()
SEE ALSO
getEmpty() getBitmap() getMatrix() getFPMatrix() getNumpy() getGrayNumpy() getGrayscaleMatrix()
SUMMARY
This method returns the colors in the palette of the image. A palette is the set of the most common colors in an image. This method is helpful for segmentation.
PARAMETERS
RETURNS
A numpy array of the BGR color tuples.
EXAMPLE
>>> p = img.getPalette(bins=42)
>>> print p[2]
NOTES
The hue calculations should be siginificantly faster than the generic RGB calculation as it works in a one dimensional space. Sometimes the underlying scipy method freaks out about k-means initialization with the following warning:
Warning
One of the clusters is empty. Re-run kmean with a different initialization. This shouldn’t be a real problem.
SEE ALSO
rePalette() drawPaletteColors() palettize() getPalette() binarizeFromPalette() findBlobsFromPalette()
SUMMARY
This function returns the RGB value for a particular image pixel given a specific row and column.
Warning
this function will always return pixels in RGB format even if the image is BGR format.
PARAMETERS
- x - Int the x pixel coordinate.
- y - Int the y pixel coordinate.
RETURNS
A color value that is a three element integer tuple.
EXAMPLE
>>> img = Image(logo)
>>> color = img.getPixel(10,10)
Warning
We suggest that this method be used sparingly. For repeated pixel access use python array notation. I.e. img[x][y].
SUMMARY
This function returns a single column of RGB values from the image as a numpy array. This is handy if you want to crawl the image looking for an edge.
PARAMETERS
RETURNS
A numpy array of the pixel values. Ususally this is in BGR format.
EXAMPLE
>>> img = Image("lenna")
>>> myColor = [0,0,0]
>>> sl = img.getVertScanline(423)
>>> sll = sl.tolist()
>>> for p in sll:
>>> if( p == myColor ):
>>> # do something
SEE ALSO
getHorzScanlineGray() getHorzScanline() getVertScanlineGray() getVertScanline()
SUMMARY
This function returns a single column of gray values from the image as a numpy array. This is handy if you want to crawl the image looking for an edge.
PARAMETERS
RETURNS
A a lumpy numpy array of the pixel values.
EXAMPLE
>>> img = Image("lenna")
>>> myColor = [255]
>>> sl = img.getVertScanlineGray(421)
>>> sll = sl.tolist()
>>> for p in sll:
>>> if( p == myColor ):
>>> # do something
SEE ALSO
SUMMARY
This method returns a gray scale version of the image. It makes everything look like an old movie.
RETURNS
A grayscale SimpleCV image.
EXAMPLE
>>> img = Image("lenna")
>>> img.grayscale().binarize().show()
SEE ALSO
SUMMARY
This method returns a gray scale version of the image. It makes everything look like an old movie.
RETURNS
A grayscale SimpleCV image.
EXAMPLE
>>> img = Image("lenna")
>>> img.grayscale().binarize().show()
SEE ALSO
SUMMARY
This method applies a high pass DFT filter. This filter enhances the high frequencies and removes the low frequency signals. This has the effect of enhancing edges. The frequencies are defined as going between 0.00 and 1.00 and where 0 is the lowest frequency in the image and 1.0 is the highest possible frequencies. Each of the frequencies are defined with respect to the horizontal and vertical signal. This filter isn’t perfect and has a harsh cutoff that causes ringing artifacts.
PARAMETERS
RETURNS
A SimpleCV Image after applying the filter.
EXAMPLE
>>> img = Image("SimpleCV/sampleimages/RedDog2.jpg")
>>> img.getDFTLogMagnitude().show()
>>> lpf = img.lowPassFilter([0.2,0.1,0.2])
>>> lpf.show()
>>> lpf.getDFTLogMagnitude().show()
NOTES
This filter is far from perfect and will generate a lot of ringing artifacts. * See: http://en.wikipedia.org/wiki/Ringing_(signal) * See: http://en.wikipedia.org/wiki/High-pass_filter#Image
SEE ALSO
rawDFTImage() getDFTLogMagnitude() applyDFTFilter() highPassFilter() lowPassFilter() bandPassFilter() InverseDFT() applyButterworthFilter() InverseDFT() applyGaussianFilter() applyUnsharpMask()
SUMMARY
Return a numpy array of the 1D histogram of intensity for pixels in the image Single parameter is how many “bins” to have.
PARAMETERS
RETURNS
A list of histogram bin values.
EXAMPLE
>>> img = Image('lenna')
>>> hist = img.histogram()
SEE ALSO
SUMMARY
Returns an image representing the distance of each pixel from the given hue of a specific color. The hue is “wrapped” at 180, so we have to take the shorter of the distances between them – this gives a hue distance of max 90, which we’ll scale into a 0-255 grayscale image.
The minsaturation and minvalue are optional parameters to weed out very weak hue signals in the picture, they will be pushed to max distance [255]
PARAMETERS
RETURNS
A simpleCV image.
EXAMPLE
>>> img = Image("logo")
>>> img2 = img.hueDistance(color=Color.BLACK)
>>> img2.show()
SEE ALSO
binarize() hueDistance() morphOpen() morphClose() morphGradient() findBlobsFromMask()
SUMMARY
Returns the histogram of the hue channel for the image
PARAMETERS
RETURNS
A list of histogram bin values.
SEE ALSO
SUMMARY
Takes the histogram of hues, and returns the peak hue values, which can be useful for determining what the “main colors” in a picture.
The bins parameter can be used to lump hues together, by default it is 179 (the full resolution in OpenCV’s HSV format)
Peak detection code taken from https://gist.github.com/1178136 Converted from/based on a MATLAB script at http://billauer.co.il/peakdet.html
Returns a list of tuples, each tuple contains the hue, and the fraction of the image that has it.
PARAMETERS
RETURNS
A list of (hue,fraction) tuples.
SUMMARY
Insert a new layer into the layer stack at the specified index.
PARAMETERS
RETURNS
None - that’s right - nothing.
EXAMPLE
>>> img = Image("Lenna")
>>> myLayer1 = DrawingLayer((img.width,img.height))
>>> myLayer2 = DrawingLayer((img.width,img.height))
>>> #Draw on the layers
>>> img.insertDrawingLayer(myLayer1,1) # on top
>>> img.insertDrawingLayer(myLayer2,2) # on the bottom
SEE ALSO
DrawingLayer addDrawinglayer() dl() toPygameSurface() getDrawingLayer() removeDrawingLayer() clearLayers() layers() mergedLayers() applyLayers() drawText() drawRectangle() drawCircle() blit()
SUMMARY
Calculate the integral image and return it as a numpy array. The integral image gives the sum of all of the pixels above and to the right of a given pixel location. It is useful for computing Haar cascades. The return type is a numpy array the same size of the image. The integral image requires 32Bit values which are not easily supported by the SimpleCV Image class.
PARAMETERS
RETURNS
A numpy array of the values.
EXAMPLE
>>> img = Image("logo")
>>> derp = img.integralImage()
SEE ALSO
SUMMARY
Invert (negative) the image note that this can also be done with the unary minus (-) operator. For binary image this turns black into white and white into black (i.e. white is the new black).
RETURNS
The opposite of the current image.
EXAMPLE
>>> img = Image("polar_bear_in_the_snow.png")
>>> img.invert().save("black_bear_at_night.png")
SEE ALSO
SUMMARY
Returns true if this image uses the BGR colorspace.
RETURNS
True if the image uses the BGR colorspace, False otherwise.
EXAMPLE
>>> if( img.isBGR() ):
>>> b,g,r = img.splitChannels()
SEE ALSO
SUMMARY
Returns true if this image uses the BGR colorspace.
RETURNS
True if the image uses the BGR colorspace, False otherwise.
EXAMPLE
>>> if( img.isBGR() ):
>>> b,g,r = img.splitChannels()
SEE ALSO
SUMMARY
Returns true if this image uses the HLS colorspace.
RETURNS
True if the image uses the HLS colorspace, False otherwise.
EXAMPLE
>>> if( img.isHLS() ):
>>> h,l,s = img.splitChannels()
SEE ALSO
SUMMARY
Returns true if this image uses the HSV colorspace.
RETURNS
True if the image uses the HSV colorspace, False otherwise.
EXAMPLE
>>> if( img.isHSV() ):
>>> h,s,v = img.splitChannels()
SEE ALSO
SUMMARY
Returns true if this image uses the RGB colorspace.
RETURNS
True if the image uses the RGB colorspace, False otherwise.
EXAMPLE
>>> if( img.isRGB() ):
>>> r,g,b = img.splitChannels()
SEE ALSO
SUMMARY
Returns true if this image uses the XYZ colorspace.
RETURNS
True if the image uses the XYZ colorspace, False otherwise.
EXAMPLE
>>> if( img.isXYZ() ):
>>> x,y,z = img.splitChannels()
SEE ALSO
SUMMARY
Return the array of DrawingLayer objects associated with the image.
RETURNS
A list of of drawing layers.
SEE ALSO
DrawingLayer addDrawingLayer() dl() toPygameSurface() getDrawingLayer() removeDrawingLayer() mergedLayers() applyLayers() drawText() drawRectangle() drawCircle() blit()
This is used to list the built in features available for HaarCascade feature detection. Just run this function as:
>>> img.listHaarFeatures()
Then use one of the file names returned as the input to the findHaarFeature() function. So you should get a list, more than likely you will see face.xml, to use it then just
>>> img.findHaarFeatures('face.xml')
SUMMARY
This shows a live view of the camera. * Left click will show mouse coordinates and color. * Right click will kill the live image.
RETURNS
Nothing. In place method.
EXAMPLE
>>> cam = Camera()
>>> cam.live()
SUMMARY
This method applies a low pass DFT filter. This filter enhances the low frequencies and removes the high frequency signals. This has the effect of reducing noise. The frequencies are defined as going between 0.00 and 1.00 and where 0 is the lowest frequency in the image and 1.0 is the highest possible frequencies. Each of the frequencies are defined with respect to the horizontal and vertical signal. This filter isn’t perfect and has a harsh cutoff that causes ringing artifacts.
PARAMETERS
RETURNS
A SimpleCV Image after applying the filter.
EXAMPLE
>>> img = Image("SimpleCV/sampleimages/RedDog2.jpg")
>>> img.getDFTLogMagnitude().show()
>>> lpf = img.highPassFilter([0.2,0.2,0.05])
>>> lpf.show()
>>> lpf.getDFTLogMagnitude().show()
NOTES
This filter is far from perfect and will generate a lot of ringing artifacts. See: http://en.wikipedia.org/wiki/Ringing_(signal) See: http://en.wikipedia.org/wiki/Low-pass_filter
SEE ALSO
rawDFTImage() getDFTLogMagnitude() applyDFTFilter() highPassFilter() lowPassFilter() bandPassFilter() InverseDFT() applyButterworthFilter() InverseDFT() applyGaussianFilter() applyUnsharpMask()
SUMMARY
The maximum value of my image, and the other image, in each channel If other is a number, returns the maximum of that and the number
PARAMETERS
RETURNS
A SimpelCV image.
SUMMARY
This method finds the average color of all the pixels in the image.
RETURNS
A tuple of the average image values. Tuples are in the channel order. For most images this means the results are (B,G,R).
EXAMPLE
>>> img = Image('lenna')
>>> colors = img.meanColor()
SUMMARY
Convience function derived from the smooth() method Perform a median filtering operation to denoise/despeckle the image. The optional parameter is the window size.
NOTES
SUMMARY
Merge channels is the oposite of splitChannels. The image takes one image for each of the R,G,B channels and then recombines them into a single image. Optionally any of these channels can be None.
PARAMETERS
RETURNS
A SimpleCV Image.
EXAMPLE
>>> img = Image("lenna")
>>> [r,g,b] = img.splitChannels()
>>> r = r.binarize()
>>> g = g.binarize()
>>> b = b.binarize()
>>> result = img.mergeChannels(r,g,b)
>>> result.show()
SEE ALSO splitChannels()
SUMMARY
Return all DrawingLayer objects as a single DrawingLayer.
RETURNS
Returns a drawing layer with all of the drawing layers of this image merged into one.
EXAMPLE
>>> img = Image("Lenna")
>>> myLayer1 = DrawingLayer((img.width,img.height))
>>> myLayer2 = DrawingLayer((img.width,img.height))
>>> img.insertDrawingLayer(myLayer1,1) # on top
>>> img.insertDrawingLayer(myLayer2,2) # on the bottom
>>> derp = img.mergedLayers()
SEE ALSO
DrawingLayer addDrawingLayer() dl() toPygameSurface() getDrawingLayer() removeDrawingLayer() layers() applyLayers() drawText() drawRectangle() drawCircle() blit()
SUMMARY
The minimum value of my image, and the other image, in each channel If other is a number, returns the minimum of that and the number
Parameter
Returns
IMAGE
SUMMARY
morphologyClose applies a morphological close operation which is effectively a dilation operation followed by a morphological erosion. This operation helps to ‘bring together’ or ‘close’ binary regions which are close together.
RETURNS
A SimpleCV image.
EXAMPLE
>>> img = Image("lenna")
>>> derp = img.binarize()
>>> derp.morphClose.show()
SEE ALSO
erode() dilate() binarize() morphOpen() morphGradient() findBlobsFromMask()
SUMMARY
The morphological gradient is the difference betwen the morphological dilation and the morphological gradient. This operation extracts the edges of a blobs in the image.
RETURNS
A SimpleCV image.
EXAMPLE
>>> img = Image("lenna")
>>> derp = img.binarize()
>>> derp.morphGradient.show()
SEE ALSO
erode() dilate() binarize() morphOpen() morphClose() findBlobsFromMask()
SUMMARY
morphologyOpen applies a morphological open operation which is effectively an erosion operation followed by a morphological dilation. This operation helps to ‘break apart’ or ‘open’ binary regions which are close together.
RETURNS
A SimpleCV image.
EXAMPLE
>>> img = Image("lenna")
>>> derp = img.binarize()
>>> derp.morphOpen.show()
SEE ALSO
erode() dilate() binarize() morphClose() morphGradient() findBlobsFromMask()
SUMMARY
This method analyzes an image and determines the most common colors using a k-means algorithm. The method then goes through and replaces each pixel with the centroid of the clutsters found by k-means. This reduces the number of colors in an image to the number of bins. This can be particularly handy for doing segementation based on color.
PARAMETERS
RETURNS
An image matching the original where each color is replaced with its palette value.
EXAMPLE
>>> img2 = img1.palettize()
>>> img2.show()
NOTES
The hue calculations should be siginificantly faster than the generic RGB calculation as it works in a one dimensional space. Sometimes the underlying scipy method freaks out about k-means initialization with the following warning:
Warning
UserWarning: One of the clusters is empty. Re-run kmean with a different initialization. This shouldn’t be a real problem.
SEE ALSO
rePalette() drawPaletteColors() palettize() getPalette() binarizeFromPalette() findBlobsFromPalette()
SUMMARY
Pixelation blur, like the kind used to hide naughty bits on your favorite tv show.
PARAMETERS
RETURNS
Returns the image with the pixelation blur applied.
EXAMPLE
>>> img = Image("lenna")
>>> result = img.pixelize( 16, (200,180,250,250), levels=4)
>>> img.show()
SUMMARY
This method returns the RAW DFT transform of an image as a list of IPL Images. Each result image is a two channel 64f image where the first channel is the real component and the second channel is teh imaginary component. If the operation is performed on an RGB image and grayscale is False the result is a list of these images of the form [b,g,r].
PARAMETERS
RETURNS
A list of the DFT images (see above). Note that this is a shallow copy operation.
EXAMPLE
>>> img = Image('logo.png')
>>> myDFT = img.rawDFTImage()
>>> for c in myDFT:
>>> #do some operation on the DFT
NOTES
http://en.wikipedia.org/wiki/Discrete_Fourier_transform http://math.stackexchange.com/questions/1002/fourier-transform-for-dummies
SEE ALSO
rawDFTImage() getDFTLogMagnitude() applyDFTFilter() highPassFilter() lowPassFilter() bandPassFilter() InverseDFT() applyButterworthFilter() InverseDFT() applyGaussianFilter() applyUnsharpMask()
SUMMARY
rePalette takes in the palette from another image and attempts to apply it to this image. This is helpful if you want to speed up the palette computation for a series of images (like those in a video stream.
PARAMETERS
RETURNS
A SimpleCV Image.
EXAMPLE
>>> img = Image("lenna")
>>> img2 = Image("logo")
>>> p = img.getPalette()
>>> result = img2.rePalette(p)
>>> result.show()
SEE ALSO
rePalette() drawPaletteColors() palettize() getPalette() binarizeFromPalette() findBlobsFromPalette()
SUMMARY
This function will return any text it can find using OCR on the image.
Please note that it does not handle rotation well, so if you need it in your application try to rotate and/or crop the area so that the text would be the same way a document is read
RETURNS
A String
EXAMPLE
>>> img = Imgae("somethingwithtext.png")
>>> text = img.readText()
>>> print text
NOTE
If you’re having run-time problems I feel bad for your son, I’ve got 99 problems but dependencies ain’t one:
http://code.google.com/p/tesseract-ocr/ http://code.google.com/p/python-tesseract/
SUMMARY
Region select is similar to crop, but instead of taking a position and width and height values it simply takes to points on the image and returns the selected region. This is very helpful for creating interactive scripts that require the user to select a region.
PARAMETERS
RETURNS
A cropped SimpleCV Image.
EXAMPLE
>>> img = Image("lenna")
>>> subreg = img.regionSelect(10,10,100,100) # often this comes from a mouse click
>>> subreg.show()
SEE ALSO
SUMMARY
Remove a layer from the layer stack based on the layer’s index.
PARAMETERS
RETURNS
This method returns the removed drawing layer.
SUMMARY
Insert a new layer into the layer stack at the specified index.
PARAMETERS
RETURNS
None - that’s right - nothing.
EXAMPLE
>>> img = Image("Lenna")
>>> myLayer1 = DrawingLayer((img.width,img.height))
>>> myLayer2 = DrawingLayer((img.width,img.height))
>>> #Draw on the layers
>>> img.insertDrawingLayer(myLayer1,1) # on top
>>> img.insertDrawingLayer(myLayer2,2) # on the bottom
SEE ALSO
DrawingLayer addDrawinglayer() dl() toPygameSurface() getDrawingLayer() removeDrawingLayer() clearLayers() layers() mergedLayers() applyLayers() drawText() drawRectangle() drawCircle() blit()
SUMMARY
This method resizes an image based on a width, a height, or both. If either width or height is not provided the value is inferred by keeping the aspect ratio. If both values are provided then the image is resized accordingly.
PARAMETERS
RETURNS
Returns a resized image, if the size is invalid a warning is issued and None is returned.
EXAMPLE
>>> img = Image("lenna")
>>> img2 = img.resize(w=1024) # h is guessed from w
>>> img3 = img.resize(h=1024) # w is guessed from h
>>> img4 = img.resize(w=200,h=100)
SUMMARY*
This function rotates an image around a specific point by the given angle By default in “fixed” mode, the returned Image is the same dimensions as the original Image, and the contents will be scaled to fit. In “full” mode the contents retain the original size, and the Image object will scale by default, the point is the center of the image. you can also specify a scaling parameter
PARAMETERS
RETURNS
The rotated SimpleCV image.
EXAMPLE
>>> img = Image('logo')
>>> img2 = rotate( 73.00, point=(img.width/2,img.height/2))
>>> img3 = rotate( 73.00, fixex=False, point=(img.width/2,img.height/2))
>>> img4 = img2.sideBySide(img3)
>>> img4.show()
SEE ALSO
SUMMARY
Does a fast 90 degree rotation to the right. Generally this method should be faster than img.rotate(90)
Warning
Subsequent calls to this function WILL NOT keep rotating it to the right!!! This function just does a matrix transpose so following one transpose by another will just yield the original image.
RETURNS
The rotated SimpleCV Image.
EXAMPLE
>>> img = Image("logo")
>>> img2 = img.rotate90()
>>> img2.show()
SEE ALSO
SUMMARY
Save the image to the specified filename. If no filename is provided then then it will use the filename the Image was loaded from or the last place it was saved to. You can save to lots of places, not just files. For example you can save to the Display, a JpegStream, VideoStream, temporary file, or Ipython Notebook.
Save will implicitly render the image’s layers before saving, but the layers are not applied to the Image itself.
PARAMETERS
EXAMPLES
To save as a temporary file just use:
>>> img = Image('simplecv')
>>> img.save(temp=True)
It will return the path that it saved to.
Save also supports IPython Notebooks when passing it a Display object that has been instainted with the notebook flag.
To do this just use:
>>> disp = Display(displaytype='notebook')
>>> img.save(disp)
Note
You must have IPython notebooks installed for this to work
Attention
We need examples for all save methods as they are unintuitve.
SUMMARY
Scale the image to a new width and height.
If no height is provided, the width is considered a scaling value.
PARAMETERS
RETURNS
The resized image.
EXAMPLE
>>> img.scale(200, 100) #scales the image to 200px x 100px
>>> img.scale(2.0) #enlarges the image to 2x its current size
Warning
The two value scale command is deprecated. To set width and height use the resize function.
SUMMARY
Given a set of new corner points in clockwise order, return a shear-ed image that transforms the image contents. The returned image is the same dimensions.
PARAMETERS
RETURNS
A simpleCV image.
EXAMPLE
>>> img = Image("lenna")
>>> points = ((50,0),(img.width+50,0),(img.width,img.height),(0,img.height))
>>> img.shear(points).show()
SEE ALSO
SUMMARY
This function automatically pops up a window and shows the current image.
PARAMETERS
RETURNS
This method returns the display object. In the case of the window this is a JpegStreamer object. In the case of a window a display object is returned.
EXAMPLE
>>> img = Image("lenna")
>>> img.show()
>>> img.show('browser')
SEE ALSO
JpegStreamer Display
SUMMARY
Combine two images as a side by side images. Great for before and after images.
PARAMETERS
RETURNS
A new image that is a combination of the two images.
EXAMPLE
>>> img = Image("lenna")
>>> img2 = Image("orson_welles.jpg")
>>> img3 = img.sideBySide(img2)
TODO
Make this accept a list of images.
SUMMARY
Returns a tuple that lists the width and height of the image.
RETURNS
The width and height as a tuple.
SUMMARY
Skeletonization is the process of taking in a set of blobs (here blobs are white on a black background) and finding a squigly line that would be the back bone of the blobs were they some sort of vertebrate animal. Another way of thinking about skeletonization is that it finds a series of lines that approximates a blob’s shape.
A good summary can be found here:
http://www.inf.u-szeged.hu/~palagyi/skel/skel.html
PARAMETERS
EXAMPLE
>>> cam = Camera()
>>> while True:
>>> img = cam.getImage()
>>> b = img.binarize().invert()
>>> s = img.skeletonize()
>>> r = b-s
>>> r.show()
NOTES
This code was a suggested improvement by Alex Wiltchko, check out his awesome blog here:
SUMMARY
smartFindBlobs uses a method called grabCut, also called graph cut, to automagically determine the boundary of a blob in the image. The dumb find blobs just uses color threshold to find the boundary, smartFindBlobs looks at both color and edges to find a blob. To work smartFindBlobs needs either a rectangle that bounds the object you want to find, or a mask. If you use a rectangle make sure it holds the complete object. In the case of a mask, it need not be a normal binary mask, it can have the normal white foreground and black background, but also a light and dark gray values that correspond to areas that are more likely to be foreground and more likely to be background. These values can be found in the color class as Color.BACKGROUND, Color.FOREGROUND, Color.MAYBE_BACKGROUND, and Color.MAYBE_FOREGROUND.
PARAMETERS
RETURNS
A featureset of blobs. If everything went smoothly only a couple of blobs should be present.
EXAMPLE
>>> img = Image("RatTop.png")
>>> mask = Image((img.width,img.height))
>>> mask.dl().circle((100,100),80,color=Color.MAYBE_BACKGROUND,filled=True
>>> mask.dl().circle((100,100),60,color=Color.MAYBE_FOREGROUND,filled=True)
>>> mask.dl().circle((100,100),40,color=Color.FOREGROUND,filled=True)
>>> mask = mask.applyLayers()
>>> blobs = img.smartFindBlobs(mask=mask)
>>> blobs.draw()
>>> blobs.show()
NOTES
http://en.wikipedia.org/wiki/Graph_cuts_in_computer_vision
SEE ALSO
SUMMARY
smartThreshold uses a method called grabCut, also called graph cut, to automagically generate a grayscale mask image. The dumb version of threshold just uses color, smartThreshold looks at both color and edges to find a blob. To work smartThreshold needs either a rectangle that bounds the object you want to find, or a mask. If you use a rectangle make sure it holds the complete object. In the case of a mask, it need not be a normal binary mask, it can have the normal white foreground and black background, but also a light and dark gray values that correspond to areas that are more likely to be foreground and more likely to be background. These values can be found in the color class as Color.BACKGROUND, Color.FOREGROUND, Color.MAYBE_BACKGROUND, and Color.MAYBE_FOREGROUND.
PARAMETERS
RETURNS
A grayscale image with the foreground / background values assigned to:
EXAMPLE
>>> img = Image("RatTop.png")
>>> mask = Image((img.width,img.height))
>>> mask.dl().circle((100,100),80,color=Color.MAYBE_BACKGROUND,filled=True)
>>> mask.dl().circle((100,100),60,color=Color.MAYBE_FOREGROUND,filled=True)
>>> mask.dl().circle((100,100),40,color=Color.FOREGROUND,filled=True)
>>> mask = mask.applyLayers()
>>> new_mask = img.smartThreshold(mask=mask)
>>> new_mask.show()
NOTES
http://en.wikipedia.org/wiki/Graph_cuts_in_computer_vision
SEE ALSO
SUMMARY
Smooth the image, by default with the Gaussian blur. If desired, additional algorithms and aperatures can be specified. Optional parameters are passed directly to OpenCV’s cv.Smooth() function.
If grayscale is true the smoothing operation is only performed on a single channel otherwise the operation is performed on each channel of the image.
PARAMETERS
Warning
These must be odd numbers.
RETURNS
The smoothed image.
EXAMPLE
>>> img = Image("Lenna")
>>> img2 = img.smooth()
>>> img3 = img.smooth('median')
SEE ALSO
SUMMARY
This method can be used to brak and image into a series of image chunks. Given number of cols and rows, splits the image into a cols x rows 2d array of cropped images
PARAMETERS
RETURNS
A list of SimpleCV images.
EXAMPLE
>>> img = Image("lenna")
>>> quadrant =img.split(2,2)
>>> for f in quadrant:
>>> f.show()
>>> time.sleep(1)
NOTES
TODO: This should return and ImageList
SUMMARY
Split the channels of an image into RGB (not the default BGR) single parameter is whether to return the channels as grey images (default) or to return them as tinted color image
PARAMETERS
RETURNS
A tuple of of 3 image objects.
EXAMPLE
>>> img = Image("lenna")
>>> data = img.splitChannels()
>>> for d in data:
>>> d.show()
>>> time.sleep(1)
SEE ALSO
SUMMARY
The stretch filter works on a greyscale image, if the image is color, it returns a greyscale image. The filter works by taking in a lower and upper threshold. Anything below the lower threshold is pushed to black (0) and anything above the upper threshold is pushed to white (255)
PARAMETERS
RETURNS
A gray scale version of the image with the appropriate histogram stretching.
EXAMPLE
>>> img = Image("orson_welles.jpg")
>>> img2 = img.stretch(56.200)
>>> img2.show()
NOTES
TODO - make this work on RGB images with thresholds for each channel.
SEE ALSO
SUMMARY
We roll old school with this vanilla threshold function. It takes your image converts it to grayscale, and applies a threshold. Values above the threshold are white, values below the threshold are black (note this is in contrast to binarize... which is a stupid function that drives me up a wall). The resulting black and white image is returned.
PARAMETERS
RETURNS
A black and white SimpleCV image.
EXAMPLE
>>> img = Image("purplemonkeydishwasher.png")
>>> result = img.threshold(42)
NOTES
THRESHOLD RULES BINARIZE DROOLS!
SEE ALSO
SUMMARY
This method attemps to convert the image to the BGR colorspace. If the color space is unknown we assume it is in the BGR format.
RETURNS
Returns the converted image if the conversion was successful, otherwise None is returned.
EXAMPLE
>>> img = Image("lenna")
>>> BGRImg = img.toBGR()
SEE ALSO
SUMMARY
This method attemps to convert the image to the grayscale colorspace. If the color space is unknown we assume it is in the BGR format
RETURNS
Returns the converted image if the conversion was successful, otherwise None is returned.
EXAMPLE
>>> img = Image("lenna")
>>> GrayImg = img.toGray()
SEE ALSO
SUMMARY
This method attempts to convert the image to the HLS colorspace. If the color space is unknown we assume it is in the BGR format.
RETURNS
Returns the converted image if the conversion was successful, otherwise None is returned.
EXAMPLE
>>> img = Image("lenna")
>>> HLSImg = img.toHLS()
SEE ALSO
SUMMARY
This method attempts to convert the image to the HSV colorspace. If the color space is unknown we assume it is in the BGR format
RETURNS
Returns the converted image if the conversion was successful, otherwise None is returned.
EXAMPLE
>>> img = Image("lenna")
>>> HSVImg = img.toHSV()
SEE ALSO
SUMMARY
Converts this image to a pygame surface. This is useful if you want to treat an image as a sprite to render onto an image. An example would be rendering blobs on to an image.
Warning
THIS IS EXPERIMENTAL. We are plannng to remove this functionality sometime in the near future.
RETURNS
The image as a pygame surface.
SEE ALSO
DrawingLayer insertDrawingLayer() addDrawingLayer() dl() toPygameSurface() getDrawingLayer() removeDrawingLayer() clearLayers() layers() mergedLayers() applyLayers() drawText() drawRectangle() drawCircle() blit()
SUMMARY
This method attemps to convert the image to the RGB colorspace. If the color space is unknown we assume it is in the BGR format
RETURNS
Returns the converted image if the conversion was successful, otherwise None is returned.
EXAMPLE
>>> img = Image("lenna")
>>> RGBImg = img.toRGB()
SEE ALSO
SUMMARY
Returns the image as a string, useful for moving data around.
RETURNS
The image, converted to rgb, then converted to a string.
SUMMARY
This method attemps to convert the image to the XYZ colorspace. If the color space is unknown we assume it is in the BGR format
RETURNS
Returns the converted image if the conversion was successful, otherwise None is returned.
EXAMPLE
>>> img = Image("lenna")
>>> XYZImg = img.toXYZ()
SEE ALSO
SUMMARY
This helper function for shear performs an affine rotation using the supplied matrix. The matrix can be a either an openCV mat or an np.ndarray type. The matrix should be a 2x3
PARAMETERS
RETURNS
The rotated image. Note that the rotation is done in place, i.e. the image is not enlarged to fit the transofmation.
EXAMPLE
>>> img = Image("lenna")
>>> points = ((50,0),(img.width+50,0),(img.width,img.height),(0,img.height))
>>> src = ((0, 0), (img.width-1, 0), (img.width-1, img.height-1))
>>> result = cv.createMat(2,3,cv.CV_32FC1)
>>> cv.GetAffineTransform(src,points,result)
>>> img.transformAffine(result).show()
SEE ALSO
shear() :py:meth`warp` transformPerspective() rotate()
SUMMARY
This helper function for warp performs an affine rotation using the supplied matrix. The matrix can be a either an openCV mat or an np.ndarray type. The matrix should be a 3x3
- rotMatrix - Numpy Array or CvMat
RETURNS
The rotated image. Note that the rotation is done in place, i.e. the image is not enlarged to fit the transofmation.
EXAMPLE
>>> img = Image("lenna")
>>> points = ((50,0),(img.width+50,0),(img.width,img.height),(0,img.height))
>>> src = ((30, 30), (img.width-10, 70), (img.width-1-40, img.height-1+30),(20,img.height+10))
>>> result = cv.createMat(3,3,cv.CV_32FC1)
>>> cv.GetPerspectiveTransform(src,points,result)
>>> img.transformPerspective(result).show()
SEE ALSO
SUMMARY This function is used to upload image to both imgur and flickr.
PARAMETERS If dest is ‘imgur’ :
- api_key - a string of the API key. You must register
with imgur to get an API key.
- verbose - If verbose is true all values are printed to the
screen
with flickr to get an API key.
with Flickr to get an API secret key.
RETURNS if dest is ‘imgur’ : If uploading is successful we return a list of the upload URL, the original image URL, and the delete image URL. If the upload fails we return None.
EXAMPLE
>>> img = Image("lenna")
>>> result = img.upload( 'imgur',"MY_API_KEY1234567890" )
>>> print "Uploaded To: " + result[0]
>>> img.upload('flickr','ccfa805e5c7693b96fb548fa0f7a36da','db1479dbba974633')
NOTES .. Warning:
This method requires that you have PyCurl installed as well as Flickr.
Warning
You must supply your own API key. See here: http://imgur.com/register/api_anon or http://www.flickr.com/services/api/misc.api_keys.html
SUMMARY
This method performs and arbitrary perspective transform. Given a new set of corner points in clockwise order frin top left, return an Image with the images contents warped to the new coordinates. The returned image will be the same size as the original image
PARAMETERS
RETURNS
A simpleCV Image with the warp applied. Note that this operation does not enlarge the image.
EXAMPLE
>>> img = Image("lenna")
>>> points = ((30, 30), (img.width-10, 70), (img.width-1-40, img.height-1+30),(20,img.height+10))
>>> img.warp(points).show()
SEE ALSO
SUMMARY
Attempts to perform automatic white balancing. Gray World see: http://scien.stanford.edu/pages/labsite/2000/psych221/projects/00/trek/GWimages.html Robust AWB: http://scien.stanford.edu/pages/labsite/2010/psych221/projects/2010/JasonSu/robustawb.html http://scien.stanford.edu/pages/labsite/2010/psych221/projects/2010/JasonSu/Papers/Robust%20Automatic%20White%20Balance%20Algorithm%20using%20Gray%20Color%20Points%20in%20Images.pdf Simple AWB: http://www.ipol.im/pub/algo/lmps_simplest_color_balance/ http://scien.stanford.edu/pages/labsite/2010/psych221/projects/2010/JasonSu/simplestcb.html
PARAMETERS
RETURNS
A SimpleCV Image.
EXAMPLE
>>> img = Image("lenna")
>>> img2 = img.whiteBalance()
Bases: list
SUMMARY
This is an abstract class for keeping a list of images. It has a few advantages in that you can use it to auto load data sets from a directory or the net.
Keep in mind it inherits from a list too, so all the functionality a normal python list has this will too.
EXAMPLES
>>> imgs = ImageSet()
>>> imgs.download("ninjas")
>>> imgs.show(ninjas)
or you can load a directory path:
>>> imgs = ImageSet('/path/to/imgs/')
>>> imgs.show()
This will download and show a bunch of random ninjas. If you want to save all those images locally then just use:
>>> imgs.save()
You can also load up the sample images that come with simplecv as:
>>> imgs = ImageSet('samples')
>>> imgs.filelist
>>> logo = imgs.find('simplecv.png')
TO DO
Eventually this should allow us to pull image urls / paths from csv files. The method also allow us to associate an arbitraty bunch of data with each image, and on load/save pickle that data or write it to a CSV file.
SUMMARY
This function downloads images from Google Image search based on the tag you provide. The number is the number of images you want to have in the list. Valid values for size are ‘thumb’, ‘small’, ‘medium’, ‘large’ or a tuple of exact dimensions i.e. (640,480). Note that ‘thumb’ is exceptionally faster than others.
Warning
This requires the python library Beautiful Soup to be installed http://www.crummy.com/software/BeautifulSoup/
PARAMETERS
RETURNS
Nothing - but caches local copy of images.
EXAMPLE
>>> imgs = ImageSet()
>>> imgs.download("ninjas")
>>> imgs.show(ninjas)
SUMMARY
This function loads up files automatically from the directory you pass it. If you give it an extension it will only load that extension otherwise it will try to load all know file types in that directory.
extension should be in the format: extension = ‘png’
PARAMETERS
RETURNS
The number of images in the image set.
EXAMPLE
>>> imgs = ImageSet()
>>> imgs.load("images/faces")
>>> imgs.load("images/eyes", "png")
SUMMARY
This is a quick way to save all the images in a data set. Or to Display in webInterface.
If you didn’t specify a path one will randomly be generated. To see the location the files are being saved to then pass verbose = True.
PARAMETERS
RETURNS
Nothing.
EXAMPLE
>>> imgs = ImageSet()
>>> imgs.download("ninjas")
>>> imgs.save(True)
TO DO
This should save to a specified path.
SUMMARY
This is a quick way to show all the items in a ImageSet. The time is in seconds. You can also provide a decimal value, so showtime can be 1.5, 0.02, etc. to show each image.
PARAMETERS
RETURNS
Nothing.
EXAMPLE
>>> imgs = ImageSet()
>>> imgs.download("ninjas")
>>> imgs.show()
SUMMARY
This shows the file paths of all the images in the set.
If they haven’t been saved to disk then they will not have a filepath
RETURNS
Nothing.
EXAMPLE
>>> imgs = ImageSet()
>>> imgs.download("ninjas")
>>> imgs.save(True)
>>> imgs.showPaths()
TO DO
This should return paths as a list too.
Bases: SimpleHTTPServer.SimpleHTTPRequestHandler
The JpegStreamHandler handles requests to the threaded HTTP server. Once initialized, any request to this port will receive a multipart/replace jpeg.
The JpegStreamer class allows the user to stream a jpeg encoded file to a HTTP port. Any updates to the jpg file will automatically be pushed to the browser via multipart/replace content type.
To initialize: js = JpegStreamer()
to update: img.save(js)
to open a browser and display: import webbrowser webbrowser.open(js.url)
Note 3 optional parameters on the constructor: - port (default 8080) which sets the TCP port you need to connect to - sleep time (default 0.1) how often to update. Above 1 second seems to cause dropped connections in Google chrome
Once initialized, the buffer and sleeptime can be modified and will function properly – port will not.
Returns the URL of the MJPEG stream. If host and port are not set in the constructor, defaults to “http://localhost:8080/stream/“
Returns the JpegStreams Webbrowser-appropriate URL, if not provided in the constructor, it defaults to “http://localhost:8080“
Bases: SocketServer.ThreadingMixIn, SocketServer.TCPServer
The VideoStream lets you save video files in a number of different formats.
You can initialize it by specifying the file you want to output:
vs = VideoStream("hello.avi")
You can also specify a framerate, and if you want to “fill” in missed frames. So if you want to record a realtime video you may want to do this:
vs = VideoStream("myvideo.avi", 25, True) #note these are default values
Where if you want to do a stop-motion animation, you would want to turn fill off:
vs_animation = VideoStream("cartoon.avi", 15, False)
If you select a fill, the VideoStream will do its best to stay close to “real time” by duplicating frames or dropping frames when the clock doesn’t sync up with the file writes.
You can save a frame to the video by using the Image.save() function:
my_camera.getImage().save(vs)
This writes a frame to the display object this is automatically called by image.save() but you can use this function to save just the bitmap as well so image markup is not implicit,typically you use image.save() but this allows for more finer control
This function takes in a URL for a zip file, extracts it and returns the temporary path it was extracted to
Search for item in a list
Returns: Boolean
This function prints the current logging level of the main logger.
Determines if it is a number or not
Returns: Type
Determines if it is a tuple or not
Returns: Boolean
This function is a utility for converting numpy arrays to the cv.cvMat format.
Returns: cvMatrix
Reverses a tuple
Returns: Tuple
This function sets the threshold for the logging system and, if desired, directs the messages to a logfile. Level options:
‘DEBUG’ or 1 ‘INFO’ or 2 ‘WARNING’ or 3 ‘ERROR’ or 4 ‘CRITICAL’ or 5
If the user is on the interactive shell and wants to log to file, a custom excepthook is set. By default, if logging to file is not enabled, the way errors are displayed on the interactive shell is not changed.
This function is meant to run builtin unittests