'''
@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
# global start 全局变量定义初始化开始
#全局变量参数
carmela_hight = 200
carmela_width = 200
#Tkinter元素句柄参数
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__))
#global end 全局变量定义初始化结束
#创建窗口对象以及窗口使用变量
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_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))
# 填充至min_side * min_side
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
#窗口使用变量初始化结束
#图片获取通过图片路径显示标签,返回值为cv2.imread 缩放后
def ImageGet():
#读取图片参数,通过opencv
Source_Img = cv2.imread(Img_Path_String.get())
if (Source_Img is None):
return None
else
python学习随笔03 Opencv提取轮廓,对轮廓识别后,判断轮廓形状
最新推荐文章于 2024-09-26 16:04:41 发布