'''
@Author: your name
@Date: 2020-02-13 13:30:07
@LastEditTime: 2020-02-20 16:17:34
@LastEditors: Please set LastEditors
@Description: 高斯平滑展示,边缘检测展示,
能够通过按键时时控制高斯平滑,高斯选择改变后改变高斯图和边缘检测图
边缘检测通过右侧两个滑条更改检测阈值
加入圆形检测
'''
import tkinter
import os
import cv2
import numpy
from PIL import Image,ImageTk
from tkinter import filedialog
carmela_hight = 200
carmela_width = 200
Source_Img_Label = None
Gray_Img_Label = None
Canny_Img_Label = None
Circles_Img_Label = None
Gaussian_Button = None
Counters_Button = None
Threshold_Min_Scale = None
Threshold_Max_Scale = None
Hough_Parm1_Scale = None
Hough_Parm2_Scale = None
Gaussian_Enable = False
Counters_Enable = False
py_path=os.path.abspath(os.path.dirname(__file__))
root = tkinter.Tk()
Img_Path_String = tkinter.StringVar()
Img_Path_String.set('尚未选择文件')
Dp_Value = tkinter.StringVar()
Dp_Value.set('1')
screen_Width = root.winfo_screenwidth()
screen_height = root.winfo_screenheight()
width = screen_Width//2
height = screen_height//2+50
root_win_par = '%dx%d+%d+%d'% (width, height, (screen_Width-width)/2, (screen_height-height)/2)
def resizeImage(image, width, height, inter=cv2.INTER_AREA):
size = image.shape
h, w = size[0], size[1]
min_side = min(width,height)
scale = max(w, h) / float(min_side)
new_w, new_h = int(w/scale), int(h/scale)
resize_img = cv2.resize(image, (new_w, new_h))
if new_w % 2 != 0 and new_h % 2 == 0:
top, bottom, left, right = (min_side-new_h)/2, (min_side-new_h)/2, (min_side-new_w)/2 + 1, (min_side-new_w)/2
elif new_h % 2 != 0 and new_w % 2 == 0:
top, bottom, left, right = (min_side-new_h)/2 + 1, (min_side-new_h)/2, (min_side-new_w)/2, (min_side-new_w)/2
elif new_h % 2 == 0 and new_w % 2 == 0:
top, bottom, left, right = (min_side-new_h)/2, (min_side-new_h)/2, (min_side-new_w)/2, (min_side-new_w)/2
else:
top, bottom, left, right = (min_side-new_h)/2 + 1, (min_side-new_h)/2, (min_side-new_w)/2 + 1, (min_side-new_w)/2
pad_img = cv2.copyMakeBorder(resize_img, int(top), int(bottom), int(left), int(right), cv2.BORDER_CONSTANT, value=[0,0,0])
return pad_img
def ImageGet():
Source_Img = cv2.imread(Img_Path_String.get())
if (Source_Img is None):
return None
else