def objectClassification(color, label=False): global image, workingImage, app width, height = workingImage["size"][0], workingImage["size"][1] pixels = workingImage["pixels"] pixels, objects = filters.objectClassification(pixels, width, height, color=color) saveImageChanges(pixels) app.updateCanvas() if(label): for mObject in objects: x, y = mObject["center"][0], mObject["center"][1] app.edit_canvas.create_oval(mObject["center"][0]-3, mObject["center"][1]-3, mObject["center"][0]+3, mObject["center"][1]+3, fill="black", outline="black") l = Label(app.edit_canvas, text="Ob%d"%(mObject["id"])).place(x=x,y=y) print "Object ID: %d, Size (pixels): %s, Size (percentage): %s%%"%(mObject["id"], len(mObject["pixels"]), mObject["percentage"]) print "Done!" return objects
def objectClassification(color, label=False): global image, lastImage, app i = "tmp.png" a, width, height, pixels = imageToPixels(lastImage) pixels, objects = filters.objectClassification(pixels, width, height, color=color) saveImage((width, height), pixels, i) lastImage = i a.putdata(pixels) app.editImage = ImageTk.PhotoImage(a) app.edit_canvas.configure(width=width, height=height) app.edit_canvas.create_image(width/2, height/2, image=app.editImage) if(label): for mObject in objects: #x,y = mObject["center"][0], mObject["center"][1] #app.edit_canvas.create_oval(mObject["center"][0]-3, mObject["center"][1]-3, mObject["center"][0]+3, mObject["center"][1]+3, fill="black", outline="black") #l = Label(app.edit_canvas, text="Ob%d"%(mObject["id"])).place(x=x,y=y) print "Object ID: %d, Size (pixels): %s, Size (percentage): %s%%"%(mObject["id"], len(mObject["pixels"]), mObject["percentage"]) print "Done!" return objects
def objectClassification(color, label=False): global image, workingImage, app width, height = workingImage["size"][0], workingImage["size"][1] pixels = workingImage["pixels"] pixels, objects = filters.objectClassification(pixels, width, height, color=color) if(label): mask = Image.new("RGBA", workingImage["size"]) draw = ImageDraw.Draw(mask) saveImageChanges(pixels) for mObject in objects: x, y = mObject["center"][0], mObject["center"][1] draw.ellipse((mObject["center"][0]-3, mObject["center"][1]-3, mObject["center"][0]+3, mObject["center"][1]+3), fill="black") draw.text((x+2,y+2), "Ob%d"%(mObject["id"]), fill="white") print "Object ID: %d, Size (pixels): %s, Size (percentage): %s%%, Detection Point: %s"%(mObject["id"], len(mObject["pixels"]), mObject["percentage"], mObject["dp"]) saveImageDraw(mask) app.updateCanvas() print "Done!" return objects