示例#1
0
def processQuote(src):
	try:
		img = Image(src)
		text = img.binarize().readText()
	except Exception as e:
		print e
		print '###'
	else:
		cleantext = cleanText(text)
		translated = trans.translate(cleantext, langpair)
		if translated:
			img.drawText(translated, 0, 0, color=Color.BLACK, fontsize=24)
			print lan1 + ": " + cleantext
			print lan2 + ": " + translated.encode('utf-8')
			print '###'
		img.show()
示例#2
0
    def _removeAllButCentralGalaxyCluster(self):
        e = self.ellipse
        img = self.image

        emask = Image(np.zeros((img.width, img.height), dtype=np.uint8))

        if e and e.a and e.b and e.a != np.nan and e.b != np.nan:
            try:
                e.drawOntoLayer(emask)
            except:
                print "Got exception while processing %s" % self.id
                pass

        emask = emask.applyLayers().floodFill((img.width/2, img.height/2), color=Color.BLUE)
        mask = emask.binarize().invert()
        return img.applyBinaryMask(mask)
示例#3
0
def find_shapes(img):
    markupImage = Image(img)
    bwImage = markupImage.binarize() 
    blobs = bwImage.findBlobs()
    rectangles = [] 
    for b in blobs:
        info = b.boundingBox()
        x = info[0]
        y = info[1]
        w = info[2]
        h = info[3]
        c = find_color(x, y, markupImage)
        markupImage.drawRectangle(x, y, w, h)
        rectangles.append(Rectangle(*((x, y, w, h) + c)))
    max_rectangle = max(rectangles, key=lambda rect: rect.w * rect.h) 
    #markupImage.drawRectangle(max_rectangle.x, max_rectangle.y, max_rectangle.w, max_rectangle.h, Color.ORANGE) 
    return rectangles, markupImage 
示例#4
0
#!/usr/bin/env python encoding: latin1
import sys
from SimpleCV import Image

#Creo la imatge a partir del bmp
imatge = Image('/Ccalc/ServidorCcalc/ServidorCcalc/imatges/'+sys.argv[1])
#La binaritzo, li trec totes les sombres i la natejo
imgBin = imatge.binarize(-1,255,37,8)
#I la inverteixo, la paso de fons negre i lletres blanques a fons blanc a lletres negres
imgInver = imgBin.invert()
#la guardo
imgInver.save('/Ccalc/ServidorCcalc/ServidorCcalc/imatges/'+ sys.argv[1])

print 1; #Retorno aquest 1 a java perque sapiga que ha acabat
示例#5
0
from SimpleCV import Image

coins = Image("ex22a.jpg")  # Open ex22b.jpg and ex22c.jpg too :)
coins = coins.resize(500, 500)  # A simple resize only for a better display

# Binarize the image to manipulate it more easily
binCoins = coins.binarize()

# Find the blobs on the image
blobs = binCoins.findBlobs()

# 'blobs' it's a object, then we can manipulate it and display it
blobs.show(width=5)
示例#6
0
from SimpleCV import Image
import time
pennies = Image("pennies.jpg") 
binPen = pennies.binarize() 
blobs = binPen.findBlobs() 
blobs.show(width=5)
print "Areas: ", blobs.area()
print "Angles: ", blobs.angle()
print "Centers: ", blobs.coordinates()
time.sleep(5)
示例#7
0
from SimpleCV import Image, Color, Display
from time import sleep
import sys

display = Display()
# Load an image from imgur.
img = Image('http://i.imgur.com/lfAeZ4n.png')
# binarize the image using a threshold of 90 
# and invert the results.
output = img.binarize(90).invert()
# create the side by side image.
result = output
result.save('juniperbinary.png')

# show the resulting image.

result.save(display)

try:
	while not display.isDone():
		sleep(0.1)
	

except KeyboardInterrupt:
	sys.exit()

# save the results to a file. 
示例#8
0
        #img = img.applyLayers()
        img = img - depthbin.invert()
        #img.save(d)
        meanred, meangrn, meanblue = img.meanColor()

        if meanred > meanblue and meanred > meangrn:
            depthbin, junk, junk = depthbin.splitChannels(grayscale=False)
        if meanblue > meanred and meanblue > meangrn:
            junk, junk, depthbin = depthbin.splitChannels(grayscale=False)
        if meangrn > meanred and meangrn > meanblue:
            junk, depthbin, junk = depthbin.splitChannels(grayscale=False)

        laststroke = time.time()
        compositeframe = compositeframe + depthbin
        #we're painting -- keep adding to the composite frame

    else:
        if (time.time() - laststroke > offtime):
            #if we're not painting for a certain amount of time, reset
            compositeframe = Image(cam.getImage().getEmpty())

    frame = ((imgscene - compositeframe.binarize(10).invert()) +
             compositeframe).flipHorizontal()
    #subtract our composite frame from our camera image, then add it back in in red. False = Show red channel as red, [0] = first (red) channel
    frame.save(d)  #show in browser
    if d.mouseLeft:
        d.done = True
        pg.quit()

    time.sleep(0.01)  #yield to the webserver
示例#9
0
from SimpleCV import Image

#Ee crea la instancia de la Imatge agafant la imatege

#la imatge
imatge = Image('/home/palmendr/Documentos/PerePersonal/ServidorCcalc/ServidorCcalc/CCalc/autotrace-0.31.1/render2.bmp')

#S'executa el binarize sense parametres(negre)'

imgBin = imatge.binarize()

#Se salva la imagen como resultado3.jpg

imgBin.save('/home/palmendr/Documentos/PerePersonal/CCalc/ServidorCcalc/ServidorCcalc/autotrace-0.31.1/renderfinal.bmp')
示例#10
0
img = cam.getImage().save("img.jpg")
img = Image("img.jpg")
img.show()
imgGray = img.grayscale().save("imgGray.jpg")
imgGray = Image("imgGray.jpg")
imgGray.show()
hist = imgGray.histogram(255)

(red, green, blue) = img.splitChannels(False)
red_histogram = red.histogram(255)
green_histogram = green.histogram(255)
blue_histogram = blue.histogram(255)
plt.figure(1)
plt.subplot(411)
plt.plot(hist)
plt.subplot(412)
plt.plot(red_histogram)
plt.subplot(413)
plt.plot(green_histogram)
plt.subplot(414)
plt.plot(blue_histogram)
plt.show()

print("Ingresar parametro para binarizar: ")
a = input()

imgBin = imgGray.binarize(a).save("imgBin.jpg")
imgBin = Image("imgBin.jpg")
imgBin.show()
time.sleep(10)
示例#11
0
from SimpleCV import Image
import time
img = Image('ladies.jpg')
# Using Otsu's method
otsu = img.binarize()
# Specify a low value
low = img.binarize(75)
# Specify a high value
high = img.binarize(125)
img = img.resize(int(img.width*.5), int(img.height*.5))
otsu = otsu.resize(int(otsu.width*.5), int(otsu.height*.5))
low = low.resize(int(low.width*.5), int(low.height*.5))
high = high.resize(int(high.width*.5), int(high.height*.5))

top = img.sideBySide(otsu)
bottom = low.sideBySide(high)
combined = top.sideBySide(bottom, side="bottom")

combined.show()
time.sleep(20)
示例#12
0
from SimpleCV import Image
import numpy

img = Image("us-scaled.jpg")
out = img.binarize(30)
out.save('out.png')

img = Image("out.png")
# ones = img.getNumpy()[:,:,:] == (0, 0, 0)
ones = img.getNumpy()[:,:,0] == 0
trues=numpy.where(ones)

points = []
for p in zip(trues[0], trues[1]):
    # points.append(p)
    print(str(p[0]) + " " + str(p[1]))

for one in ones:
    print(one)
from SimpleCV import Image

img = Image("ex18.jpg")

imgBin = img.binarize().invert()
imgBin.show()
示例#14
0
from SimpleCV import Image
img = Image("tape.jpg")
blobs = img.binarize().morphClose().findBlobs()
blobs.image = img
blobs[-1].drawHoles()
img.show()
from SimpleCV import Image
img = Image('ex18.jpg')

imgBin = img.binarize().invert()
imgBin.show()
示例#16
0
from SimpleCV import Image
import time
#using opencv captured image, but purpose is make by video
call(“raspistill -n -t 0 -w %s -h %s -o image.bmp” % 640 480, shell=True)

img = Image(“image.bmp”)

img.show()
time.sleep(5)

#--------
cam = Camera()
img = cam.getImage()

#-----
img = img.edges()
img.show()
time.sleep(5)


img = img.binarize()
img.show()
time.sleep(5) 


img = img.findBlobs()
for blob in blobs:
    blob.draw()  
img.show()
time.sleep(5) 
#연속적인 이미지 촬영으로 영상을 만들면 속도가 너무 느리다 한방으로 가자
from SimpleCV import Image, Color, Display

# Make a function that does a half and half image.
def halfsies(left,right): 
    result = left
    # crop the right image to be just the right side.
    crop   = right.crop(right.width/2.0,0,right.width/2.0,right.height)
    # now paste the crop on the left image.
    result = result.blit(crop,(left.width/2,0))
    # return the results.
    return result
# Load an image from imgur.
img = Image('http://i.imgur.com/lfAeZ4n.png')
# binarize the image using a threshold of 90 
# and invert the results.
output = img.binarize(90).invert()
# create the side by side image.
result = halfsies(img,output)
# show the resulting image.
result.show()
# save the results to a file. 
result.save('juniperbinary.png')
from SimpleCV import Image

img = Image('ex18.jpg')

imgBin = img.binarize()
imgBin.show()
'''

#importa bibliotecas necessárias
from SimpleCV import Image, Color
import math


#função para calcular o X para o ponto Y dado
def calculaX(m, Y, pt1):
    x = (Y - pt1[1]) / m + pt1[0]
    return x


img = Image("d:/estrada.jpg")  #carrega imagem a ser analisada
imgBy = img.binarize(90)  #binariza imagem
lines = imgBy.findLines()  #encontra linhas
size = imgBy.size()  #verifica tamanho da imagem

while True:
    question = "Digite o ponto Y (de 130 a 210): "  #imprime mensagem para entrada do Y

    Y = int(raw_input(question))  #le valor informado
    print Y  #imprime na tela

    if Y < 130 or Y > 210:
        print "Erro: Valor fora do limite especificado. Tente novamente"
    else:
        break

x1 = x1_temp = 0  #variáveis auxiliares para varredura do ponto x na linha 1 à esquerda
示例#20
0
from SimpleCV import Image, Color
img = Image("puzzle.jpg")
blobs = img.binarize().findBlobs()
blobs.image = img
blobs[-1].drawHull(color=Color.RED)
img.show()
示例#21
0
    def run(self):
        # Capture first frame to get size
        frame = cv.QueryFrame(self.capture)
        frame_size = cv.GetSize(frame)
        grey_image = cv.CreateImage(cv.GetSize(frame), cv.IPL_DEPTH_8U, 1)
        moving_average = cv.CreateImage(cv.GetSize(frame), cv.IPL_DEPTH_32F, 3)
        difference = None

        while True:
            # Capture frame from webcam
            color_image = cv.QueryFrame(self.capture)


            preImg = pretreatment.PreTreatment()
            imagePath = preImg.getImage(color_image)
            sobelImagePath = preImg.sobelImage(imagePath)
            thresholdImagePath = preImg.thresholdImage(sobelImagePath)
            print thresholdImagePath
            imThreshold = cv.LoadImage(thresholdImagePath,0)


            src = cv.LoadImage(thresholdImagePath, cv.CV_LOAD_IMAGE_COLOR)
            image = cv.CloneImage(src)
            dest = cv.CloneImage(src)

            #cv.ShowImage("texture", src)

            erDest = preImg.Erosion(src,6)
            opDest = preImg.Opening(erDest,6)
            erDest = preImg.Erosion(opDest,3)

            #save image
            cv.ShowImage("last result",erDest)
            filePath = os.getcwd()+"/img/dest4.jpg"
            cv.SaveImage(filePath,erDest)


            #img = cv.Convert(erDest,)

            img = Image("./img/dest4.jpg")
            blobs = img.binarize().findBlobs()
            pack_blobs = blobs.crop()
            pack_blob_size =  pack_blobs[-1].size()

            blobs.image = img
            print blobs.sortArea()[-1].area()
            blobArea = blobs.sortArea()[-1].area()
            nickels = blobs.filter((blobs.area() > blobArea-10) & (blobs.area() < blobArea+10))
            pack_blob_zoom = (nickels.center()[0][0]/2,nickels.center()[0][1]/2)

            debug = True
            color = (0,0,255)

            rect_start = (nickels.center()[0][0]-pack_blob_size[0]/2,nickels.center()[0][1]-pack_blob_size[1]/2)

            rect_end = (nickels.center()[0][0]+pack_blob_size[0]/2,nickels.center()[0][1]+pack_blob_size[1]/2)
            cv.Rectangle(color_image, rect_start, rect_end, color, 2, 0)

            cutting.cuteImg(pack_blob_zoom,pack_blob_size)

            # palte prccessing
            plateSrcPath = "./img/dest5.jpg"
            plateBinaryImg = plateProcess.binary(plateSrcPath)

            plateBinary = cv.LoadImage("./img/plateBinary.jpg", cv.CV_LOAD_IMAGE_COLOR)
            cv.ShowImage("Binary Plare",plateBinary)


            #start_x, end_x, graph = cutting.getVerticalProjection("./img/plateBinary.jpg")
            #chars = cutting.cut(start_x,end_x,plateBinary)


            # Display frame to user
            cv.ShowImage("Target", color_image)

            # Listen for ESC or ENTER key
            c = cv.WaitKey(7) % 0x100

            if c == 27 or c == 10:
                break
示例#22
0
from SimpleCV import Image
img = Image('hand_pic.JPG')

while True:
    b = img.binarize().invert()
    s = b.skeletonize()
    r = b - s
    r.show()

# Image.track(), mask, findAndRecognizeFaces
#  findBlobsFromHueHistogram(self, model, threshold=1, smooth=True, minsize=10, maxsize=None)
示例#23
0
import random

reward = 0
score = 0

#k = [0,1]
env = gym.make('flashgames.HarvestDay-v0')
env.configure(remotes=1) # create one flashgames Docker container
observation_n = env.reset()
c = 0
x = 0
y = 0

e = 0
img = Image("continue.png")
img = img.binarize()

while True:
  # your agent generates action_n at 60 frames per second
	
			
	 
	x = random.randint(0,600)
	y = random.randint(100,400)
	e += 1
	if e >= 800:
		x = random.randint(0,600)
		y = random.randint(300,400)
	        
	action_n = [universe.spaces.PointerEvent(x, y, 0),
            universe.spaces.PointerEvent(x, y, 1),
示例#24
0
plt.stem(redhist);plt.title('Gray histogram');plt.axis('tight')
plt.subplot(222)
plt.stem(redhist);plt.title('Red histogram');plt.axis('tight')
plt.subplot(223)
plt.stem(greenhist);plt.title('Green histogram');plt.axis('tight')
plt.subplot(224)
plt.stem(bluehist);plt.title('Blue histogram');plt.axis('tight')
plt.savefig('fotos/histogramas.png')

red.save('fotos/lunar_en_rojo.png')
green.save('fotos/lunar_en_verde.png')
blue.save('fotos/lunar_en_azul.png')
 
imagen=Image("fotos/lunar01.png")
#imagen.show()
img_bin=imagen.sideBySide(imagen.binarize() )
img_bin.save('lunar_binario.png')

imgbin=imagen.binarize()

#sobel detector
imsobel= imgGray.sobel()
imsobel.show()

kuns=imgGray.invert().findBlobs()[-1]
mask=kuns.getFullMask()
mask.show()

# cani edges detector
imedge= imgGray.edges()
imedge.show()
from SimpleCV import Image
import time
img = Image('logo')
otsu = img.binarize()
otsu.show()
time.sleep(5)
bin = img.binarize(127)
bin.show()
time.sleep(5)
from SimpleCV import Image

img = Image("ex18.jpg")

imgBin = img.binarize()
imgBin.show()
from SimpleCV import Image

coins = Image("ex22a.jpg") # Open ex22b.jpg and ex22c.jpg too :)
coins = coins.resize(500, 500) # A simple resize only for a better display

# Binarize the image to manipulate it more easily
binCoins = coins.binarize()

# Find the blobs on the image
blobs = binCoins.findBlobs()

# 'blobs' it's a object, then we can manipulate it and display it 
blobs.show(width=5)
示例#28
0
        meanred, meangrn, meanblue = img.meanColor()

        if meanred > meanblue and meanred > meangrn:
            depthbin, junk, junk = depthbin.splitChannels(grayscale = False)
        if meanblue > meanred and meanblue > meangrn:
            junk, junk, depthbin = depthbin.splitChannels(grayscale = False)
        if meangrn > meanred and meangrn > meanblue:
            junk, depthbin, junk = depthbin.splitChannels(grayscale = False)

        laststroke = time.time()
        compositeframe = compositeframe + depthbin
        #we're painting -- keep adding to the composite frame

    else:
        if (time.time() - laststroke > offtime):
        #if we're not painting for a certain amount of time, reset
            compositeframe = Image(cam.getImage().getEmpty())

    imgscene = imgscene.crop(0,25, 605, 455).scale(640,480)

    frame = ((imgscene - compositeframe.binarize(10).invert()) + compositeframe) + imgscene.edges()#.flipHorizontal()
    #subtract our composite frame from our camera image, then add it back in in red. False = Show red channel as red, [0] = first (red) channel
    num = frame.getNumpy()
    Image(num).save(d)
    #frame.save(d) #show in browser
    if d.mouseLeft:
        d.done = True
        pg.quit()

    time.sleep(0.01) #yield to the webserver
        for marca in marcas:
            SCREEN.blit(marca[0], marca[1]) # imagen, rect

    if paso1 == False and paso2 == False:
        dibujar_Textos('GRACIAS,', font40, COLOR_AZUL_CIELO, SCREEN, 10, 100,'center')
        dibujar_Textos('CALIBRACION DE TAPETE FINALIZADA', font40, COLOR_AZUL_CIELO, SCREEN, 10, 150,'center')

    if paso2 == True:
        img = camara.getImage()
        nivel_R = control_RED.valorLevel
        nivel_G = control_GREEN.valorLevel
        nivel_B = control_BLUE.valorLevel
        UMBRAL_BINARIZADO = control_BINARIZE.valorLevel

        img = img.colorDistance((nivel_R, nivel_G, nivel_B))
        img = img.binarize(UMBRAL_BINARIZADO)
        img.save('temp/vistaTapete.png')
        imagen_calibracion =  pygame.image.load('temp/vistaTapete.png')
        SCREEN.blit(imagen_calibracion, (0,0))

        # dibujar los contoles deslizables
        for control_deslizable in listaControles:
            control_deslizable.draw(SCREEN)
            
        # Dibujar Etiquetas(y otros textos)
        dibujar_Textos('(R)   %0d'  %(nivel_R),  font20, COLOR_BLANCO_SUCIO, SCREEN, 10,  15, 0)
        dibujar_Textos('(G)   %0d' %(nivel_G), font20, COLOR_BLANCO_SUCIO, SCREEN, 10,  65, 0)
        dibujar_Textos('(B)   %0d' %(nivel_B),  font20, COLOR_BLANCO_SUCIO, SCREEN, 10, 115, 0)
        dibujar_Textos('BINARIZADO   %0d' %(UMBRAL_BINARIZADO),   font20, COLOR_BLANCO_SUCIO, SCREEN, 10, 160, 0) 

    # Mover Objeto: Si hay objeto Focus seleccionado, moverlo