Beispiel #1
0
def thresholding(x):
    global thres, value, maxValue, img, tipo
    imgO = img
    if (x == 0):
        thres = None
        filtro = img
        value = 0
        maxValue = 255
        cv2.createTrackbar('Value', windowTitle, value, maxValue, fValue)
        cv2.createTrackbar('MaxValue', windowTitle, maxValue, maxValue, fMaxValue)


    elif (x == 1):
        thres = cv2.THRESH_BINARY+cv2.THRESH_OTSU
    elif (x==2):
        thres = cv2.THRESH_BINARY+cv2.THRESH_OTSU
        img  = cv2.GaussianBlur(img,(5,5),0)
    if (x != 0):
        ret, filtro = cv2.threshold(img,value, maxValue, thres)
    tipo = x
    img = imgO
    blobImg = Image(filtro)
    invImg = blobImg.invert()
    blobImg = blobImg.rotate90()
    invImg = blobImg.invert()
    blobs = invImg.findBlobs()
    for blob in blobs:
        #print blob.coordinates()
        invImg.dl().circle(blob.coordinates(), 3, Color.RED, filled = True)
    blobImg.addDrawingLayer(invImg.dl())
    blobs.show(color=Color.GREEN,width=1)
    cv2.imshow(windowTitle, filtro)
Beispiel #2
0
def adaptative_thresholding(x):
    global thres, na, cons, maxValue, tipo, img, windoTitle
    if x == 0:
        thres = img
        maxValue = 255
        na = 11
        cons = 2;
        cv2.createTrackbar('Neighbourhood area (odds)', windowTitle, na, maxValue, fneighbourdhood_area)
        cv2.createTrackbar('Constant', windowTitle, -maxValue, maxValue, fConstant)
        cv2.createTrackbar('MaxValue', windowTitle, maxValue, maxValue, fMaxValue)
    elif x == 1:
        thres = cv2.adaptiveThreshold(img, maxValue,cv2.ADAPTIVE_THRESH_MEAN_C,cv2.THRESH_BINARY, na, cons)
    elif x == 2:
        thres = cv2.adaptiveThreshold(img, maxValue, cv2.ADAPTIVE_THRESH_GAUSSIAN_C, cv2.THRESH_BINARY,na,cons)
    tipo = x
    blobImg = Image(thres)
    invImg = blobImg.invert()
    blobImg = blobImg.rotate90()
    invImg = blobImg.invert()
    blobs = invImg.findBlobs()
    for blob in blobs:
        #print blob.coordinates()
        invImg.dl().circle(blob.coordinates(), 3, Color.RED, filled = True)
    blobImg.addDrawingLayer(invImg.dl())
    blobs.show(color=Color.GREEN,width=1)
    cv2.imshow(windowTitle, thres)
Beispiel #3
0
def fneighbourdhood_area(x):
    global na, thres, windowTitle, tipo
    if x % 2 ==0:
        na = x+1
    else:
        na = x
    if na == 0 or na == 1:
        na = 3
    if tipo == 0:
        thres = img
    elif tipo == 1:
        thres = cv2.adaptiveThreshold(img, maxValue,cv2.ADAPTIVE_THRESH_MEAN_C,cv2.THRESH_BINARY, na, cons)
    elif tipo == 2:
        thres = cv2.adaptiveThreshold(img, maxValue, cv2.ADAPTIVE_THRESH_GAUSSIAN_C, cv2.THRESH_BINARY,na,cons)
    blobImg = Image(thres)
    invImg = blobImg.invert()
    blobImg = blobImg.rotate90()
    invImg = blobImg.invert()
    blobs = invImg.findBlobs()
    for blob in blobs:
        #print blob.coordinates()
        invImg.dl().circle(blob.coordinates(), 3, Color.RED, filled = True)
    blobImg.addDrawingLayer(invImg.dl())
    blobs.show(color=Color.GREEN,width=1)
    
    cv2.imshow(windowTitle, thres)
Beispiel #4
0
    def getConvolvedImage(self, kern, rep, bias):
        ''' Return a simple cv compatiable 8bit greyscaled image that has had 
        the specified kernel applied rep times with bias supplied'''

        conv = ds.convolveColourMap(kern, rep, bias)
        iE = Image(conv.transpose())
        return iE.invert()
Beispiel #5
0
    def getDepth(self):
        ''' Return a simple cv compatiable 8bit depth image '''

        depth = ds.getDepthMap()
        np.clip(depth, 0, 2**10 - 1, depth)
        depth >>= 2
        depth = depth.astype(np.uint8)
        iD = Image(depth.transpose())
        return iD.invert()
Beispiel #6
0
    def getDepth(self):
        ''' Return a simple cv compatiable 8bit depth image '''

        depth = ds.getDepthMap()
        np.clip(depth, 0, 2**10 - 1, depth)
        depth >>=2
        depth = depth.astype(np.uint8)
        iD = Image(depth.transpose())
        return iD.invert()
Beispiel #7
0
def fMaxValue(x):
    global maxValue, value, thres, img, filtro
    maxValue = x
    if (thres is None):
        filtro = img

    else:
        ret, filtro = cv2.threshold(img,value, maxValue, thres)
    blobImg = Image(filtro)
    invImg = blobImg.invert()
    blobImg = blobImg.rotate90()
    invImg = blobImg.invert()
    blobs = invImg.findBlobs()
    for blob in blobs:
        #print blob.coordinates()
        invImg.dl().circle(blob.coordinates(), 3, Color.RED, filled = True)
    blobImg.addDrawingLayer(invImg.dl())
    blobs.show(color=Color.GREEN,width=1)
    cv2.imshow(windowTitle, filtro)
Beispiel #8
0
    def getConvolvedDepth(self, kern, rep, bias):
        ''' Return a simple cv compatiable 8bit depth map that has had 
        the specified kernel applied rep times '''

        conv = ds.convolveDepthMap(kern, rep, bias)
        np.clip(conv, 0, 2**10 - 1, conv)
        conv >>=2
        conv = conv.astype(np.uint8)
        iE = Image(conv.transpose())
        return iE.invert()
Beispiel #9
0
def fMaxValue(x):
    global maxValueAdaptative, windowTitle, thresAdaptative, img, naAdaptative, consAdaptative, filtro
    maxValueAdaptative = x
    if tipoAdaptative == 0:
        thresAdaptative = img
    elif tipoAdaptative == 1:
        thresAdaptative = cv2.adaptiveThreshold(filtro, maxValueAdaptative,cv2.ADAPTIVE_THRESH_MEAN_C,cv2.THRESH_BINARY, naAdaptative, consAdaptative)
    elif tipoAdaptative == 2:
        thresAdaptative = cv2.adaptiveThreshold(filtro, maxValueAdaptative, cv2.ADAPTIVE_THRESH_GAUSSIAN_C, cv2.THRESH_BINARY,naAdaptative,consAdaptative)
    blobImg = Image(thresAdaptative)
    invImg = blobImg.invert()
    blobImg = blobImg.rotate90()
    invImg = blobImg.invert()
    blobs = invImg.findBlobs()
    for blob in blobs:
        #print blob.coordinates()
        invImg.dl().circle(blob.coordinates(), 3, Color.RED, filled = True)
    blobImg.addDrawingLayer(invImg.dl())
    blobs.show(color=Color.GREEN,width=1)
    cv2.imshow(windowTitle, thresAdaptative)
Beispiel #10
0
def fConstant(x):
    global cons, thres, windowTitle, tipo, maxValue, na, img
    # const positive to white, otherwise, to black
    cons = x
    if tipo == 0:
        thres = img
    elif tipo == 1:
        thres = cv2.adaptiveThreshold(img, maxValue,cv2.ADAPTIVE_THRESH_MEAN_C,cv2.THRESH_BINARY, na, cons)
    elif tipo == 2:
        thres = cv2.adaptiveThreshold(img, maxValue, cv2.ADAPTIVE_THRESH_GAUSSIAN_C, cv2.THRESH_BINARY,na,cons)
    
    blobImg = Image(thres)
    invImg = blobImg.invert()
    blobImg = blobImg.rotate90()
    invImg = blobImg.invert()
    blobs = invImg.findBlobs()
    for blob in blobs:
        #print blob.coordinates()
        invImg.dl().circle(blob.coordinates(), 3, Color.RED, filled = True)
    blobImg.addDrawingLayer(invImg.dl())
    blobs.show(color=Color.GREEN,width=1)
    cv2.imshow(windowTitle, thres)
Beispiel #11
0
def thresholding(x):
    global thres, value, maxValue, img, filtro
    if (x == 0):
        thres = None
        filtro = img
        value = 127
        maxValue = 255
        cv2.createTrackbar('Value', windowThres, value, maxValue, fValue)
        cv2.createTrackbar('MaxValue', windowThres, maxValue, maxValue, fMaxValue)

    elif (x == 1):
        thres = cv2.THRESH_BINARY
    elif (x==2):
        thres = cv2.THRESH_BINARY_INV

    elif (x==3):
        thres = cv2.THRESH_TRUNC

    elif (x==4):
        thres = cv2.THRESH_TOZERO

    elif (x==5):
        thres = cv2.THRESH_TOZERO_INV
    if (x != 0):
        ret, filtro = cv2.threshold(img,value, maxValue, thres)
    blobImg = Image(filtro)
    invImg = blobImg.invert()
    blobImg = blobImg.rotate90()
    invImg = blobImg.invert()
    blobs = invImg.findBlobs()
    for blob in blobs:
        #print blob.coordinates()
        invImg.dl().circle(blob.coordinates(), 3, Color.RED, filled = True)
    blobImg.addDrawingLayer(invImg.dl())
    blobs.show(color=Color.GREEN,width=1)
    cv2.imshow(windowTitle, filtro)
Beispiel #12
0
def process_image(image_url):
    # Print the url for image that is being processed.
    print "Processing image: {}".format(image_url)

    # Construct the Image object from the image URL
    img = Image(image_url)

    # Find the coin blobs from the image after inverting the image
    coins = img.invert().findBlobs(minsize=500)

    # Use a quarter to calibrate the largest coin in the coin blobs.
    # Logic:
    # coin_diameter_values[3,0] is the size of the US Mint Quarter.
    # Find the largest radius of all the coins in the image. This will be our reference Quarter.
    # usmint_quarter/radius_of_our_quarter will provide the calibration factor.
    # In other words: convert pixels to millimeter.
    px2mm = coin_diameter_values[3, 0] / max([c.radius() * 2 for c in coins])

    # Initialize index & total value
    i = 0
    value = 0.0

    # For each blob in the coins blob list
    for c in coins:
        i = i + 1
        # Find the diameter of this coin blob & normalize to the calibration factor
        # ie., find the diameter in millimeter of this coin.
        diameter_in_mm = c.radius() * 2 * px2mm
        # Get an array of values for difference between this coin and all the US Mint coins.
        distance = np.abs(diameter_in_mm - coin_diameter_values[:, 0])
        #print "Coin diameter: " , diameter_in_mm, " Distance: ", distance
        # Find the coin with the smallest difference. This is our best guess on the coin type.
        index = np.where(distance == np.min(distance))[0][0]

        # Get the value of the coin and add it to the total amount
        coinValue = coin_diameter_values[index, 1]
        value += coinValue
        #coinImg = c.crop()
        #coinImg.drawText(str(coinValue))
        #coinImg.save("Results/coin"+str(i)+".png")

    message = "The total value of the coins in the image is ${0}".format(value)
    print message
    return "{}".format(value)
Beispiel #13
0
def get_pan_info(img_path):
    if img_path == None:
        img_path = sys.argv[1]
    print "Reading from file: " + img_path
    img = Image(img_path).toRGB()

    min_pan_area = img.width * img.height / 10
    pan_rects = img.invert().findBlobs((25, 0, 0), min_pan_area)

    if pan_rects and len(pan_rects) > 0:
        img = img.crop(pan_rects[0])

    if img.width < 350 or img.height < 200:
        print "Error too small PAN image"
        exit(1)

    cropped_img = img.crop(0, img.height / 4.60, img.width / 1.4,
                           img.height / 4 * 2.3)
    if cropped_img.width < 550:
        cropped_img = cropped_img.resize(
            550, 550 * cropped_img.height / cropped_img.width)

    t_img = cropped_img.threshold(100)
    img_text = pytesseract.image_to_string(t_img.getPIL(), lang='eng')
    context = {}
    learn_text(context, img_text)

    t_img = cropped_img
    img_text = pytesseract.image_to_string(t_img.getPIL(), lang='eng')
    learn_text(context, img_text)

    t_img = cropped_img.threshold(90)
    img_text = pytesseract.image_to_string(t_img.getPIL(), lang='eng')
    learn_text(context, img_text)

    t_img = cropped_img.threshold(110)
    img_text = pytesseract.image_to_string(t_img.getPIL(), lang='eng')
    learn_text(context, img_text)

    #print context['best_list']
    pan_info = get_fields(context['best_list'])
    #print json.dumps(pan_info, indent=2)
    return pan_info
from SimpleCV import Camera, Image,Color
import time

'''exemplo que carrega uma imagem totalmente vermelha e substiui o fundo do rotate
que e sempre preto por vermelho'''

cam = Camera(1)
img = cam.getImage()
vermelho = Image('/home/administrador-x/vermelho.png').resize(img.width,img.height)
rotate = img.rotate(-65)


mask = rotate.hueDistance(color=Color.BLACK,minsaturation=1,minvalue=1).erode(3).binarize(254)


img2 = mask+vermelho.invert()
img3 = img2.invert()+rotate

img3.show()
time.sleep(5)
Beispiel #15
0
from SimpleCV import Image, Blob
import numpy as np
img = Image("coins.jpg")
coins = img.invert().findBlobs(minsize=500)
value = 0.0
# The value of the coins in order of their size
# http://www.usmint.gov/about_the_mint/?action=coin_specifications
coin_diameter_values = np.array([[19.05, 0.10], [21.21, 0.01], [17.91, 0.05],
                                 [24.26, 0.25]])

# Use a quarter to calibrate (in this example we must have one)
px2mm = coin_diameter_values[3, 0] / max([c.radius() * 2 for c in coins])
for c in coins:
    diameter_in_mm = c.radius() * 2 * px2mm
    distance = np.abs(diameter_in_mm - coin_diameter_values[:, 0])
    index = np.where(distance == np.min(distance))[0][0]
    value += coin_diameter_values[index, 1]
print "The total value of the coins is $", value
Beispiel #16
0
from SimpleCV import Camera, Image, Color
import time
'''exemplo que carrega uma imagem totalmente vermelha e substiui o fundo do rotate
que e sempre preto por vermelho'''

cam = Camera(1)
img = cam.getImage()
vermelho = Image('/home/administrador-x/vermelho.png').resize(
    img.width, img.height)
rotate = img.rotate(-65)

mask = rotate.hueDistance(color=Color.BLACK, minsaturation=1,
                          minvalue=1).erode(3).binarize(254)

img2 = mask + vermelho.invert()
img3 = img2.invert() + rotate

img3.show()
time.sleep(5)
Beispiel #17
0
# -*- coding: cp1252 -*-
from SimpleCV import Camera,Image,Display
from math import *
display=Display()
cam=Camera()
sung=Image("E:/sung2.png")
sung2=Image("E:/RAY-BAN-Mens-Unisex-Designer-Genuine-Sunglasses-Aviator-RayBan-RB-4180-RRP-£165-For-Sale-at-UsedLux.com-Preowned-Used-designer-clothing-in-London-3-182103112013w.jpg")
sung2=sung2.invert()
sungar=[sung,sung2]
i=0
img3=sungar[i]
while display.isNotDone:
    img=cam.getImage()
    faces=img.findHaarFeatures('face.xml')
    if faces is not None:
        faces=faces.sortArea()
        bigface=faces[-1]
        bigeye=img.findHaarFeatures('two_eyes_big.xml')
        if(bigeye is not None):
          bigeye=bigeye.sortArea()
          bigeye=bigeye[-1]
          print "yo"
        lefteye=img.findHaarFeatures('lefteye.xml')
        righteye=img.findHaarFeatures('right_eye.xml')
        if lefteye is not None and righteye is not None:
             if bigeye is not None:
               a=int((bigeye.width()))
               b=int((bigeye.height()))
               print a,b
               sungar[i]=sungar[i].resize(a+20,b+15)
             if bigeye is not None: