示例#1
0
def up2():
	##data=request.form['img']
	get_json =request.json
	trg=json.loads(get_json)
	data=trg['img']
	
	#data = '''R0lGODlhDwAPAKECAAAAzMzM/////wAAACwAAAAADwAPAAACIISPeQHsrZ5ModrLlN48CXF8m2iQ3YmmKqVlRtW4MLwWACH+H09wdGltaXplZCBieSBVbGVhZCBTbWFydFNhdmVyIQAAOw==''' 

	#imgをオープンする
	im = Image.open(BytesIO(base64.b64decode(data)))
	#pngをJPGに
	if im.mode != "RGB":
		im = im.convert("RGB")

	#リサイズする
	size=(256,256)
	im = im.resize(size, Image.ANTIALIAS)


	#保存。存在すれば上書きされる
	#リネーム
	path="tmp/"+uuid.uuid4().hex
	im.save(path+".jpg")



	#分類する
	#result=inspection.inspect(path+".jpg")
	result=inspection.inspect(im)

	#DBに保存
	saveImageDB(data,result[0][2],result[0][1],version)
	#DBから文章を取り出す
	description=loadDescription(result[0][2],version)
	description={
		0:description[0],
		1:description[1],
	}

	#画像をスケッチ風にする
	sketchized=sket.sketchize(path)
	
	#結果listをjsonにして端末に返す
	result={0:{'name':result[0][0],'p':result[0][1], 'class':result[0][2]},
			1:{'name':result[1][0],'p':result[1][1]},
			2:{'name':result[2][0],'p':result[2][1]},
			3:description,
			4:sketchized,
			}

	return jsonify(result)
示例#2
0
def tool_run():
    print("Inspection running...")
    settings = read_settings()
    settings_names = []
    settings_values = []
    for i in range(len(settings)):
        settings_names.append(settings[i][0])
        for j in range(1, len(settings[i])):
            settings_values.append(settings[i][j])
    for i in range(len(settings_values)):
        settings_values[i] = int(settings_values[i])
    global x, y, w, h, images
    acceptance, x,y,w,h, filepath_inspected, images = \
        myModule.inspect(filepath, settings_values, 3, 12)
    if images == 0:
        status.config(text="Try loading file again")
    else:
        status.config(text=" Main defect size: " + str(w) + " x " + str(h) +
                      " / Coordinates: (" + str(x) + ";" + str(y) + ")" +
                      " / Acceptance: " + str(acceptance))
        load_image(filepath_inspected)
        button_display_process.config(state=NORMAL)
示例#3
0
def img_newest(img_dir):
    # Return the path to the most recent image in the img_dir directory

    img_lst = [os.path.join(img_dir, f) for f in os.listdir(img_dir)]
    img_lst = list(filter(os.path.isfile, img_lst))
    img_lst.sort(key=os.path.getctime, reverse=True)
    cleanup(img_lst)
    img_newest = img_lst[0]
    return img_newest


def cleanup(img_lst, ct_max=100, ct_min=50):
    # Delete older images to free up memory.
    # Parameters:
    #   img_lst: Paths to all images in the directory
    #   ct_max, ct_min: min and max number of images allowed in directory

    if len(img_lst) > ct_max:
        for image in img_lst[ct_min:]:
            os.remove(image)


inspected = ''

# Inspect newly uploaded images in img_dir directory.
while True:
    img = img_newest(img_dir)
    if img != inspected:
        inspection.inspect(img)
        inspected = img
示例#4
0
def classify():
    #画像分類結果を返す
    return inspection.inspect(g_path)