Example #1
0
def main():
    """Finds and interprets feature points"""

    # Initialize Camera
    print "Starting Webcam..."
    try:
        cam = Camera()
    except:
	print "Unable to initialize camera"
	sys.exit(1)

    display = Display(resolution = (RES_WIDTH, RES_HEIGHT))
    while not display.isDone():
        # capture the current frame
        try: 
	    capture = cam.getImage()
	    img = capture.smooth()
	except cv.error:
	    print "Camera unsupported by OpenCV"
	    sys.exit(1)

        # Build face and interpret expression
	face_image = FaceImage(img)
	if face_image.face:
	  #s  face_image.interpret()
	    pass

	capture.save(display)
	time.sleep(0.01)
	if display.mouseLeft:
	    display.done = True
Example #2
0
def main():
    # Try to connect to the camera.
    cam  = Camera()

    if not cam:
        print 'Error opening camera. Exiting...'
        sys.exit(1)

    # Create PyGame display.
    disp = Display()

    # Main processing loop.
    while not disp.isDone():
        # Get an image from the camera.
        img = cam.getImage()

        faces = img.findHaarFeatures("face.xml")
        i = 0
        if not faces is None:
            for f in faces:
                f.draw(Color.GREEN)

        # Show the camera image.
        img.save(disp)
Example #3
0
from SimpleCV import Color, ColorCurve, Kinect, Image, pg, np
from SimpleCV.Display import Display

d = Display()
#create video streams

cam = Kinect()
#initialize the camera

compositeframe = Image((640, 480))
#populate the compositeframe

offtime = 5.0
laststroke = time.time()

while not d.isDone():
    img = cam.getImage()
    imgscene = img.copy()

    depth = cam.getDepth()
    mindepth = np.min(depth.getNumpy())

    if mindepth < 180:
        depthbin = depth.binarize(np.min(depth.getNumpy()) + np.std(depth.getNumpy()) / 4).erode(3)
        #take the front 1/4 stdev of the depth map

        img = img.crop(0,25, 605, 455).scale(640,480)
        #img.dl().blit(img.crop(100, 25, 515, 455), (125,0))
        #this is a bit of a hack to compensate for the offset between cam and depth sensor
        #img = img.applyLayers()
        img = img - depthbin.invert()
Example #4
0
def main(camindex = 0, capture_width = 800, capture_height = 600, chessboard_width = 9, chessboard_height = 6, planemode = False, gridsize = 0.029, calibrationFile = "default"):
    global save_location

    if planemode:
        mode = 7
    else:
        mode = 0

    dims = (chessboard_width, chessboard_height)

    cam = Camera(camindex, prop_set = { "width": capture_width, "height": capture_height })
    d = Display((capture_width, capture_height))

    save_location = "" #change this if you want to save your calibration images

    calibration_set = [] #calibration images
    fc_set = []

    introMessage()


    while not d.isDone():
        time.sleep(0.01)
        i = cam.getImage().flipHorizontal()
        cb = i.findChessboard(dims, subpixel = False)


        if cb:
            cb = cb[0]
        elif mode != 6:
            showText(i, "Put a chessboard in the green outline")

        if mode == 0:  #10 pictures, chessboard filling 80% of the view space
            findLargeFlat(cb, i, calibration_set, dims)
            if (len(calibration_set) == 10):
                mode = 1
        elif mode == 1:  #5 pictures, chessboard filling 60% of screen, at 45 deg horiz
            findHorizTilted(cb, i, calibration_set, dims)
            if (len(calibration_set) == 15):
                mode = 2
        elif mode == 2:  #5 pictures, chessboard filling 60% of screen, at 45 deg vert
            findVertTilted(cb, i, calibration_set, dims)
            if (len(calibration_set) == 20):
                mode = 3
        elif mode == 3:  #5 pictures, chessboard filling 40% of screen, corners at 45
            findCornerTilted(cb, i, calibration_set, dims)
            if (len(calibration_set) == 25):
                mode = 4
        elif mode == 4:  #10 pictures, chessboard filling 12% - 25% of view space
            findSmallFlat(cb, i, calibration_set, dims)
            if (len(calibration_set) == 35):
                mode = 5
        elif mode == 5:
            cam.calibrate(calibration_set, gridsize, dims)
            cam.saveCalibration(calibrationFile)
            mode = 6
        elif mode == 6:
            showText(i,  "Saved calibration to " + calibrationFile)
        elif mode == 7:
            findPlane(cb, i, calibration_set, dims)
            if (len(calibration_set) == 25):
                mode = 5

        if cb:
            cb.draw()

        i.save(d)
Example #5
0
#!/usr/bin/python

import time
from SimpleCV import *
from SimpleCV.Display import Display, pg

display_width = 640
display_height = 480
display = Display(
    resolution=(display_width,
                display_height))  #create a new display to draw images on
cam = Camera()  #initialize the camera
done = False  # setup boolean to stop the program

# Loop until not needed
while not display.isDone():
    image = cam.getImage().flipHorizontal()
    crop_width = 200  #set the width of the crop window
    crop_height = 200  #set the height of the crop window
    crop_x = display.mouseX * image.width / display_width  #set the x location to scale
    crop_y = display.mouseY * image.height / display_height  #set the y location to scale

    if (display.mouseX <= 1):  #mouse outside the left of the screen
        crop_x = 1
    if (display.mouseY <= 1):  #mouse outside the top of the screen
        crop_y = 1
    if (display.mouseX + crop_width >=
            display_width):  #region outside the right side of the screen
        crop_x = (display_width - crop_width)
    if (display.mouseY + crop_height >=
            display_height):  #region below the bottom of the screen
Example #6
0
#!/usr/bin/python 

import time
from SimpleCV import *
from SimpleCV.Display import Display, pg

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

# Loop until not needed
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 #if the left arrow is pressed, close the program
from SimpleCV import *
from SimpleCV.Display import Display 
import xaut
mouse = xaut.mouse()
delay = mouse.move_delay(0)
custom_red = (121.0, 41.0, 37.0)
disp = Display(resolution=(640,480))
white_img = Image((640,480)).invert()
YELLOW=(179.0, 195.0, 112.0)
cam = Camera()

while not disp.isDone():
	original_img = cam.getImage().flipHorizontal()
	red_distance_img = original_img.colorDistance(color=Color.RED)
	red_bin = red_distance_img.threshold(100).invert()
	blobs = red_bin.findBlobs(minsize=50,maxsize=10720)
	if(blobs is not None):
		blob = max(blobs)
		mouse.move(15*(blob.x-256),12.5*(blob.y-192))
	red_bin.save(disp)
	if disp.mouseLeft:
		disp.done = True
		xaut.cleanup()
Example #8
0
def thresholdOpGreen(in_image):
    return in_image.hueDistance(60).binarize(thresh=70).invert().dilate(2)


morph_extractor = MorphologyFeatureExtractor()
morph_extractor.setThresholdOperation(thresholdOp)
classifierSVM.setFeatureExtractors([morph_extractor])

count = 0
cam = Camera(0)
blobber = BlobMaker()
disp = Display(resolution=(800, 600))
minsize = 100
maxsize = (800 * 600) / 10
while not disp.isDone():
    img = cam.getImage().resize(800, 600)
    blobs = []
    w = img.width
    h = img.height
    dl = DrawingLayer((w, h))
    #segment our items from the background
    bw = thresholdOpGreen(img)
    #extract the blobs
    blobs = blobber.extractFromBinary(bw, img, minsize, maxsize)
    # if we get a blob
    if (len(blobs) > 0):
        # sort the blobs by size
        blobs = blobs.sortArea()
        biggest = blobs[-1].mArea
        # if we get a big blob ... ignore the frame