Exemple #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
Exemple #2
0
def main():
    picture = 'shot.png'
    at = get_access_token()
    cam = Camera()
    display = Display((800, 600))
    while display.isNotDone():
        img = cam.getImage()
        img.save(picture)
        img.save(display)
        content = FaceRecognization(at, picture)
        print(content)
        print(content['height'])
Exemple #3
0
    def live(self):
        """
        **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
        """

        start_time = time.time()

        from SimpleCV.Display import Display
        i = self.getImage()
        d = Display(i.size())
        i.save(d)
        col = Color.RED

        while d.isNotDone():
            i = self.getImage()
            elapsed_time = time.time() - start_time

            if d.mouseLeft:
                txt = "coord: (" + str(d.mouseX) + "," + str(d.mouseY) + ")"
                i.dl().text(txt, (10, i.height / 2), color=col)
                txt = "color: " + str(i.getPixel(d.mouseX, d.mouseY))
                i.dl().text(txt, (10, (i.height / 2) + 10), color=col)
                print "coord: (" + str(d.mouseX) + "," + str(
                    d.mouseY) + "), color: " + str(
                        i.getPixel(d.mouseX, d.mouseY))

            if elapsed_time > 0 and elapsed_time < 5:

                i.dl().text("In live mode", (10, 10), color=col)
                i.dl().text("Left click will show mouse coordinates and color",
                            (10, 20),
                            color=col)
                i.dl().text("Right click will kill the live image", (10, 30),
                            color=col)

            i.save(d)
            if d.mouseRight:
                print "Closing Window"
                d.done = True

        pg.quit()
Exemple #4
0
    def live(self):
        """
        **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
        """

        start_time = time.time()
        
        from SimpleCV.Display import Display
        i = self.getImage()
        d = Display(i.size())
        i.save(d)
        col = Color.RED

        while d.isNotDone():
          i = self.getImage()
          elapsed_time = time.time() - start_time
          

          if d.mouseLeft:
            txt = "coord: (" + str(d.mouseX) + "," + str(d.mouseY) + ")"
            i.dl().text(txt, (10,i.height / 2), color=col)
            txt = "color: " + str(i.getPixel(d.mouseX,d.mouseY))
            i.dl().text(txt, (10,(i.height / 2) + 10), color=col)
            print "coord: (" + str(d.mouseX) + "," + str(d.mouseY) + "), color: " + str(i.getPixel(d.mouseX,d.mouseY))


          if elapsed_time > 0 and elapsed_time < 5:
            
            i.dl().text("In live mode", (10,10), color=col)
            i.dl().text("Left click will show mouse coordinates and color", (10,20), color=col)
            i.dl().text("Right click will kill the live image", (10,30), color=col)

          
          i.save(d)
          if d.mouseRight:
            print "Closing Window"
            d.done = True

        
        pg.quit()
Exemple #5
0
def main():
    while (IfWIFI()):
        print("No WIFI")
    picture = 'shot.jpg'
    at = get_access_token()
    cam = Camera()
    display = Display((800, 600))
    a = 1
    b = 0
    while display.isNotDone():
        count = ser.inWaiting()
        if count != 0:
            recv = ser.read(count)
            print(type(recv))
            if recv[0] == '*' and recv[-1] == '#':
                print("detected")
                img = cam.getImage()
                img.save(picture)
                img.save(display)
                name = MarketRecognization(at, picture)
                print(name)
                if name == "Bread":
                    b = 1
                if name == "Cookies":
                    b = 2
                if name == "HotStrips":
                    b = 3
                if name == "Sepals":
                    b = 4
                if name == "EggRolls":
                    b = 5
                if name == "Beans":
                    b = 6
                ser.write("*,%s,%s,#" % (a, b))
        ser.flushInput()
        time.sleep(0.1)
Exemple #6
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)
from SimpleCV import *
from numpy import *
from SimpleCV.Display import Display, pg
from SimpleCV import EdgeHistogramFeatureExtractor
from SimpleCV import MorphologyFeatureExtractor 

def thresholdOp(in_image):
    return in_image.hueDistance(60).binarize(thresh=70).invert().dilate(2)

cam = Camera(1)

#classifier.load(saveFile)
blobber = BlobMaker()
disp = Display(resolution=(1440,900))
#these params are to save the image
count = 0
path = ''
file = './data/bolts/bolts'
ext = '.png'
img = cam.getImage()

minsize = 350#   img.width*img.height/200
maxsize = img.width*img.height/8
avgColorThresh = 85
count = 0
while not disp.isDone():
    img = cam.getImage() 
    blobs = []
    w = img.width
    h = img.height
    hthresh = w*h*0.05
import time
from SimpleCV import *
from SimpleCV.Display import Display, pg
from SimpleCV.Segmentation import ColorSegmentation
segmentation = ColorSegmentation()
cam = Camera()
SegmentMode = False
x0 = 0
y0 = 0
x1 = 0
y1 = 0
img = cam.getImage()
display = Display((img.width,img.height))
mouse_down = False
while not display.isDone():
    img = cam.getImage()
    img = img.scale(160,120)
    dl = DrawingLayer((img.width,img.height))
    mystring = "( " +str(display.mouseX)+" , "+str(display.mouseY)+" )"
    #print((display.mouseX,display.mouseY))
    if SegmentMode:
        segmentation.addImage(img)
        if(segmentation.isReady()):
            img = segmentation.getSegmentedImage()
            img = img.erode(iterations = 2).dilate().invert()
            img.dl().ezViewText(mystring, (30,30))
            img = img.applyLayers()
            display.writeFrame(img)
        if(display.mouseLeft):
            SegmentMode = False
            segmentation.reset()
Exemple #9
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
Exemple #10
0
# (re) load the SVM and feature extractors
classifierSVM = SVMClassifier.load("nutbolt.pkl")


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
import cv2
from operator import add
from SimpleCV import *
from SimpleCV.Display import Display


def to_rgb1a(im):
    # This should be fsater than 1, as we only
    # truncate to uint8 once (?)
    w, h = im.shape
    ret = np.empty((w, h, 3), dtype=np.uint8)
    ret[:, :, 2] = ret[:, :, 1] = ret[:, :, 0] = im
    return ret


d = Display()
#create video streams

cam = Kinect()
#initialize the camera

#cap = cv2.VideoCapture('vtest.avi')

fgbg = cv2.BackgroundSubtractorMOG2(1, 5)

while not d.isDone():
    #ret, frame = cap.read()
    frame = cam.getImage()
    print frame
    frame_np = frame.getNumpyCv2()
Exemple #12
0
#!/usr/bin/python

import time, webbrowser
from operator import add
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)
#!/usr/bin/env python
# author: Powen Ko
print __doc__
import time
import csv
from SimpleCV import Color, ColorCurve, Camera, Image, pg, np, cv
from SimpleCV.Display import Display
cam = Camera()
display = Display((800,600))
data = "None"
mydict = dict()
myfile = "barcode-list.csv"
while display.isNotDone():
    display.checkEvents()
    img = cam.getImage()
    img.drawRectangle(img.width/4,img.height/4,img.width/2,img.height/2,color=Color.RED,width=3)
      if display.mouseLeft:     #當用戶按下左鍵時
        img.drawText("reading barcode... wait",10,10)
        img.save(display)
        barcode = img.findBarcode()   #辨識條碼
        if barcode:
           print barcode
           data = str(barcode[0].data)   #取得條碼資料
           print data
           if mydict.has_key(data):
              mydict[data] = mydict[data] + 1
           else:
              mydict[data] = 1
                      
        elif display.mouseRight:     #當用戶按下右鍵時
           print "save to CVS"
Exemple #14
0
#!/usr/bin/python

import time, webbrowser
from operator import add
from SimpleCV import Color, ColorCurve, Kinect, Image, pg, np
from SimpleCV.Display import Display

d = Display(flags=pg.FULLSCREEN)
#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
Exemple #15
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
Exemple #16
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

Then line up the item in the red box and left click the mouse to tell
the program to try and read the barcode
'''

print __doc__


import time
import csv
from SimpleCV import Color, ColorCurve, Camera, Image, pg, np, cv
from SimpleCV.Display import Display

cam = Camera()
display = Display((800,600))
data = "None"
mydict = dict()
myfile = "barcode-list.csv"

while display.isNotDone():
    display.checkEvents()#check for mouse clicks
    img = cam.getImage()
    img.drawRectangle(img.width/4,img.height/4,img.width/2,img.height/2,color=Color.RED,width=3)
    if display.mouseLeft: # click the mouse to read
        img.drawText("reading barcode... wait",10,10)
        img.save(display)
        barcode = img.findBarcode()
        if barcode: # if we have a barcode
            data = str(barcode.data)
            print data
Exemple #18
0
#!/usr/bin/python
#
# This example rotates through a few of the image morphology examples
#
from SimpleCV import *
from numpy import linspace
from scipy.interpolate import UnivariateSpline
import sys, time, socket
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
max_threshold = 1  # this is used for the edge detection
threshold_step = 1  # this is the amount to adjust the threshold by each time the display is updated
threshold = max_threshold
example = 1

# Loop until not needed
while not display.isDone():
    image = cam.getImage().flipHorizontal()  # get image (or frame) from camera

    # This just automatically cycles through threshold levels
    if (threshold >= 20):
        threshold = max_threshold
        if (example >= 4):
            example = 1
        else:
Exemple #19
0
from pygame.locals import *
from random import randrange
from helper_classes import Bird, Pipe
import os

####################

import SimpleCV
from SimpleCV import *
from SimpleCV.Display import Display
import numpy as np

cam = Camera(0)
i = cam.getImage()
#print i.size()
d = Display(i.size())
col = Color.RED

######################

SCORE_COLOR = (255, 25, 20)
HIGHSCORE_COLOR = (0, 0, 255)
Y_SCORE_COLOR = (0, 255, 0)

DISPLAY_WIDTH = 1200
DISPLAY_HEIGHT = 700

factor = float(DISPLAY_HEIGHT) / 480

FONT = None
FONT_SIZE = 100
Exemple #20
0
from SimpleCV import *
import numpy as np
from SimpleCV.Display import Display
cam = Camera()
import time
from mouse_api import *
m = Mouse()
nf = 2
h = 0
fl = []
reset = 0

while h < nf:
    h = h + 1
    snap = cam.getImage()
    d = Display(snap.size())
    snap.save(d)
    col = Color.RED
    start_time = time.time()
    i = 0
    while d.isNotDone():
        elapsed_time = time.time() - start_time
        if d.mouseLeft:
            txt = "coord: (" + str(d.mouseX) + "," + str(d.mouseY) + ")"
            snap.dl().text(txt, (10, snap.height / 2), color=col)
            txt = "color: " + str(snap.getPixel(d.mouseX, d.mouseY))
            snap.dl().text(txt, (10, (snap.height / 2) + 10), color=col)
            print "coord: (" + str(d.mouseX) + "," + str(
                d.mouseY) + "), color: " + str(
                    snap.getPixel(d.mouseX, d.mouseY))
            if i == 1:
Exemple #21
0
#!/usr/bin/python 

import time, webbrowser
from operator import add
from SimpleCV import Color, ColorCurve, Camera, Image, pg, np, cv, HaarCascade
from SimpleCV.Display import Display

cam = Camera(1)
time.sleep(.1) # uhg
display = Display((800,600))
counter = 0
# load the cascades
face_cascade = HaarCascade("./../Features/HaarCascades/face.xml")
nose_cascade = HaarCascade("./../Features/HaarCascades/nose.xml")
stache = Image("./stache.png") # load the stache
mask = stache.createAlphaMask() # load the stache mask
count = 0
while( display.isNotDone() ):
    #count = count + 1
    img = cam.getImage()
    img = img.scale(.5) #use a smaller image
    faces = img.findHaarFeatures(face_cascade) #find faces
    if( faces is not None ): # if we have a face
        faces = faces.sortArea() #get the biggest one
        face = faces[-1]
        myFace = face.crop() # get the face image
        noses = myFace.findHaarFeatures(nose_cascade) #find the nose
        if( noses is not None ):# if we have a nose
            noses = noses.sortArea()
            nose = noses[0] # get the biggest
            # these get the upper left corner of the face/nose
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()
Exemple #23
0
import time
from SimpleCV import *
from SimpleCV.Display import Display, pg
w = 400
h = 300
t=1
display = Display(resolution = (w,h)) #create a new display to draw images on
img = Image('../sampleimages/aerospace.jpg')
img = img.scale(800,600)
img2 = img.scale(w,h)
smallWbigH = img.scale(100,400)
smallHbigW = img2.scale(500,100)
smallW = img2.scale(100,h)
smallH = img2.scale(w,100)
small = img2.scale(99,23)
big = img2.scale(555,432)

foo = "Image:"+str((img.width,img.height))
print(foo)
print('Image should scale clean')
display.writeFrame(img)
time.sleep(t)

foo = "Image:"+str((img2.width,img2.height))
print(foo)
print('Image should scale clean')
display.writeFrame(img2)
time.sleep(t)

foo = "Image:"+str((smallWbigH.width,smallWbigH.height))
print(foo)
Exemple #24
0
then click the right lower corner of what you want to train.

This will give you a template.  For instance if you wanted to train
a face to recognize in the image you would click on the upper left corner
of the face, then click in the lower right corner of the face.  If you
want to retrain then just right click to reset.

'''

print __doc__

import time
from SimpleCV import Color, Image, np, Camera
from SimpleCV.Display import Display
cam = Camera(0)
display = Display((640, 480))  # create our display

quality = 400.00
minDist = 0.35
minMatch = 0.2
template_img = None
mode = "untrained"
startX = None
startY = None
endY = None
endX = None

while (display.isNotDone()):
    img = cam.getImage().resize(640, 480)

    #Display this if a template has not been trained yet
Exemple #25
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
        crop_y = display_height - crop_height

    cropped_image = image.crop(crop_x, crop_y, crop_width, crop_height)  # crop out the section of image we want
    xray_image = cropped_image.edges().smooth()  # get the edges of cropped region
Exemple #26
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)
#!/usr/bin/python

from operator import add
from SimpleCV import *
from SimpleCV.Display import Display

d = Display()
#create video streams

cam = Kinect()
#initialize the camera
frames_to_blur = 4
frames = ImageSet()

depth = cam.getDepth().stretch(0,200)
while True:
    new_depth = cam.getDepth().stretch(0,200)
    img = cam.getImage()
    diff_1 = new_depth - depth
    diff_2 = depth - new_depth
    diff = diff_1 + diff_2
    img_filter = diff.binarize(0)

    motion_img = img - img_filter
    motion_img_open = motion_img.morphOpen()

    frames.append(motion_img_open)
    if len(frames) > frames_to_blur:
        frames.pop(0)

    pic = reduce(add, [i / float(len(frames)) for i in frames])
#!/usr/bin/python 

import time, webbrowser
from operator import add
from SimpleCV import Color, ColorCurve, Camera, Image, pg, np, cv
from SimpleCV.Display import Display

cam = Camera(0)
time.sleep(.1) # uhg
display = Display((800,600))
counter = 0
# load the cascades
face_cascade = cv.Load("./../Features/HaarCascades/face.xml")
nose_cascade = cv.Load("./../Features/HaarCascades/nose.xml")
stache = Image("./stache.png") # load the stache
mask = stache.createAlphaMask() # load the stache mask
count = 0
while( display.isNotDone() ):
    #count = count + 1
    img = cam.getImage()
    img = img.scale(.5) #use a smaller image
    faces = img.findHaarFeatures(face_cascade) #find faces
    if( faces is not None ): # if we have a face
        faces = faces.sortArea() #get the biggest one
        face = faces[-1]
        myFace = face.crop() # get the face image
        noses = myFace.findHaarFeatures(nose_cascade) #find the nose
        if( noses is not None ):# if we have a nose
            noses = noses.sortArea()
            nose = noses[0] # get the biggest
            # these get the upper left corner of the face/nose
Exemple #29
0
from SimpleCV import *
from numpy import *
from SimpleCV.Display import Display, pg
from SimpleCV import EdgeHistogramFeatureExtractor
from SimpleCV import MorphologyFeatureExtractor


def thresholdOp(in_image):
    return in_image.hueDistance(60).binarize(thresh=70).invert().dilate(2)


cam = Camera(1)

#classifier.load(saveFile)
blobber = BlobMaker()
disp = Display(resolution=(1440, 900))
#these params are to save the image
count = 0
path = ''
file = './data/bolts/bolts'
ext = '.png'
img = cam.getImage()

minsize = 350  #   img.width*img.height/200
maxsize = img.width * img.height / 8
avgColorThresh = 85
count = 0
while not disp.isDone():
    img = cam.getImage()
    blobs = []
    w = img.width
Exemple #30
0
#!/usr/bin/python

from SimpleCV import Kinect, Image, pg, np, time
from SimpleCV.Display import Display

d = Display(flags=pg.FULLSCREEN)
#create video streams

cam = Kinect()
#initialize the camera

depth = cam.getDepth().stretch(0, 200)
while True:
    new_depth = cam.getDepth().stretch(0, 200)
    img = cam.getImage()
    diff_1 = new_depth - depth
    diff_2 = depth - new_depth
    diff = diff_1 + diff_2
    img_filter = diff.binarize(0)

    motion_img = img - img_filter
    motion_img_open = motion_img.morphOpen()
    motion_img_open.show()
    depth = new_depth
Exemple #31
0
import time
from SimpleCV import *
from SimpleCV.Display import Display, pg
from SimpleCV.Segmentation import ColorSegmentation

segmentation = ColorSegmentation()
cam = Camera()
SegmentMode = False
x0 = 0
y0 = 0
x1 = 0
y1 = 0
img = cam.getImage()
display = Display((img.width, img.height))
mouse_down = False
while not display.isDone():
    img = cam.getImage()
    img = img.scale(160, 120)
    dl = DrawingLayer((img.width, img.height))
    mystring = "( " + str(display.mouseX) + " , " + str(display.mouseY) + " )"
    #print((display.mouseX,display.mouseY))
    if SegmentMode:
        segmentation.addImage(img)
        if (segmentation.isReady()):
            img = segmentation.getSegmentedImage()
            img = img.erode(iterations=2).dilate().invert()
            img.dl().ezViewText(mystring, (30, 30))
            img = img.applyLayers()
            display.writeFrame(img)
        if (display.mouseLeft):
            SegmentMode = False
Exemple #32
0
sudo apt-get install python-zbar


Then line up the item in the red box and left click the mouse to tell
the program to try and read the barcode
'''

print __doc__

import time
import csv
from SimpleCV import Color, ColorCurve, Camera, Image, pg, np, cv
from SimpleCV.Display import Display

cam = Camera()
display = Display((800, 600))
data = "None"
mydict = dict()
myfile = "barcode-list.csv"

while display.isNotDone():
    display.checkEvents()  #check for mouse clicks
    img = cam.getImage()
    img.drawRectangle(img.width / 4,
                      img.height / 4,
                      img.width / 2,
                      img.height / 2,
                      color=Color.RED,
                      width=3)
    if display.mouseLeft:  # click the mouse to read
        img.drawText("reading barcode... wait", 10, 10)
Exemple #33
0
from SimpleCV import *
import numpy as np
from SimpleCV.Display import Display
cam=Camera()
import time
from mouse_api import *
m = Mouse()
nf = 2
h = 0
fl=[]
reset = 0

while h<nf:
	h = h + 1
	snap = cam.getImage()                
	d = Display(snap.size())
	snap.save(d)
	col = Color.RED
	start_time = time.time()
	i=0
	while d.isNotDone():
	    elapsed_time = time.time() - start_time
	    if d.mouseLeft:
	        txt = "coord: (" + str(d.mouseX) + "," + str(d.mouseY) + ")"
	        snap.dl().text(txt, (10,snap.height / 2), color=col)
	        txt = "color: " + str(snap.getPixel(d.mouseX,d.mouseY))
	        snap.dl().text(txt, (10,(snap.height / 2) + 10), color=col)
	        print "coord: (" + str(d.mouseX) + "," + str(d.mouseY) + "), color: " + str(snap.getPixel(d.mouseX,d.mouseY))
	        if i==1:    
	            x2=d.mouseX
	            y2=d.mouseY