def array(): x = request.form.getlist('values[]') images = x[0].split(",") results = [] for file in images: try: file = file.split("SPLIT") files = file[1] identifier = file[0] img = Image(files) area = img.area() # minimum and maximum areas for a cup relative to the image # proportions estimated and slightly expanded from real samples minsize = 0.0015 * area maxsize = 0.03 * area # super saturate pixels that most closely approximate red and invert image for blob detection im2 = img.hueDistance(color=(212,36,42), minsaturation=200, minvalue=70).invert() # extract blobs within the specified size range blobs = im2.findBlobs(minsize=minsize, maxsize=maxsize) # if blob (i.e. cup) detected, draw blue rectangle according to its bounding box. if blobs: # for blob in blobs: # box = blob.mBoundingBox # img.drawRectangle(box[0],box[1],box[2],box[3], color=Color.BLUE, width=5) results.append({"id" : identifier, "src" : files}) # else: # # determine a reasonable location for text # # y = img.height / 2 # # x = img.width / 2.5 # # img.drawText('Nothing detected!', x=x, y=y, color=Color.WHITE, fontsize=45) # results.append({"result" : "not found", "src" : file}) except Exception as e: print "File : %s, Error : %s" % (files, e) return render_template("results.html" , results = results)
def detectChargingStation(image_file): debug = False myColor1 = (8,33,64) myColor2 = (70,80,100) original = Image(image_file) only_station = onlyBlueColor(original, myColor1) #Different findBlobs maskMean = original.hueDistance(color=(200,160,150)) mask = only_station.hueDistance(color=myColor1).binarize() meanColor = (round(((maskMean.meanColor()[0]+maskMean.meanColor()[1]+maskMean.meanColor()[2])/3) * 10000)/10000) blobs = original.findBlobsFromMask(mask, minsize=400) if(meanColor > 190): return 6 #print "Number of blobs found" , len(blobs) try: blobs.image = original except Exception: only_station = onlyBlueColor(original, myColor2) mask = only_station.hueDistance(color=myColor2).binarize() blobs = original.findBlobsFromMask(mask, minsize=400) blobs.image = original station_blob = chooseBestBlobCosine(blobs) station_blob.drawMinRect(color=Color.RED) centroidX = station_blob.minRectX() centroidY = station_blob.minRectY() #Have to find out which part of the screen centroid is in maxX = original.getNumpy().shape[0] maxY = original.getNumpy().shape[1]+100 if(debug): centroidLayer = DrawingLayer((maxX,maxY)) centroidLayer.line((0,(1/3.0)*maxY),(maxX, (1/3.0)*maxY), color=Color.GREEN, width=2) centroidLayer.line((0,(2/3.0)*maxY),(maxX, (2/3.0)*maxY), color=Color.GREEN, width=2) centroidLayer.circle((int(centroidX), int(centroidY)), color=Color.GREEN, radius=5, filled=True) original.addDrawingLayer(centroidLayer) original.applyLayers() mask.save("binarizeMask.png") original.save("blobs.png") only_station.save("blueFilter.png") #print "Coordinates of centroid are "+str(centroidX)+", "+str(centroidY) #print "Coordinates of max are "+str(maxX)+", "+str(maxY) #if(station_blob.width() * station_blob.height() < 4000): # return 2 blobArea = station_blob.width() * station_blob.height() if(blobArea < 10000): return 2 return chargingStationLocation_New(maxX,maxY,centroidX,centroidY,200, station_blob.width() / float(station_blob.height()), blobArea)
pz.forward(speed) #statusWin.clear() statusWin.addstr(1,1, 'Reverse '+ str(speed)+" ") elif keyp == 'r': prefix=str(time.time()) copyfile("/dev/shm/lastsnap.jpg","/home/pi/"+prefix+"_lastsnap.jpg") copyfile("/dev/shm/p3.png","/home/pi/"+prefix+"_p3.png") copyfile("/dev/shm/p4.png","/home/pi/"+prefix+"_p4.png") statusWin.addstr(1,1, 'Saved webcam and opencv images to prefix '+prefix) elif keyp == 'e': img = Image("/dev/shm/lastsnap.jpg") object = img.hueDistance(Color.BLUE) object.save("/dev/shm/p3.png") #blobs = blue_distance.findBlobs() #object.draw(color=Color.PUCE, width=2) #blue_distance.show() #blue_distance.save("/dev/shm/p3.png") corners=img.findCorners() statusWin.clear() statusWin.addstr( 1, 1, str(object.meanColor())) num_corners = len(corners) statusWin.addstr(2,1, "Corners Found:" + str(num_corners))
inverted_image = stretched_image.invert() blobs = inverted_image.findBlobs(minsize=3500) if blobs: return True #means there is an obstruction return False # image = Image('images/0.jpg') x = 18 # while (x < 20): # print x # image = Image('images/'+ str(x) + '.jpg') image = Image('images/stop5.jpg') # segmented_black_white = image.stretch(180,181) # black_white_blobs = segmented_black_white.findBlobs(minsize=100) reds = image.hueDistance(color=scv.Color.RED) red_stretched_image = reds.stretch(20, 21) red_inverted_image = red_stretched_image.invert() red_blobs = red_inverted_image.findBlobs(minsize=3500) # print red_blobs # if red_blobs: # for blob in red_blobs: # blob.draw(color=(128,0,0)) # if red_blobs: red_inverted_image.show() red_inverted_image.show() time.sleep(10) x += 1 exit()
#!/usr/bin/python import subprocess from SimpleCV import Color, Image import time img = Image("/dev/shm/lastsnap.jpg") img.save("/dev/shm/p1.png") #img = img.binarize() #macchie = img.findBlobs() #img.save("p2.png") #print "Areas: ", macchie.area() #print "Angles: ", macchie.angle() #print "Centers: ", macchie.coordinates() #colore = (0,255,0) blue_distance = img.hueDistance(Color.GREEN) #.invert() #blue_distance = img.colorDistance(Color.GREEN); #.invert() blobs = blue_distance.findBlobs() blobs.draw(color=Color.PUCE, width=2) #blue_distance.show() blue_distance.save("/dev/shm/p3.png") img.addDrawingLayer(blue_distance.dl()) img.save("/dev/shm/p4.png")
#!/usr/bin/env python # -*- coding: utf-8 -*- import time from SimpleCV import Color, Image img = Image("lol.png") try: blue_distance = img.hueDistance(Color.BLUE).invert() blobs = blue_distance.findBlobs() blobs.draw(color=Color.PUCE, width=3) img.addDrawingLayer(blue_distance.dl()) img.show() time.sleep(10) except: print('kill')