python opencv 边缘检测_python人工智能opencv工具作业:使用tkinter展示边缘检测

opencv工具作业:使用tkinter展示边缘检测

AAffA0nNPuCLAAAAAElFTkSuQmCC

图片.png

AAffA0nNPuCLAAAAAElFTkSuQmCC

图片.png

AAffA0nNPuCLAAAAAElFTkSuQmCC

图片.png

AAffA0nNPuCLAAAAAElFTkSuQmCC

图片.png

参考资料

代码#!/usr/bin/python3# -*- coding: utf-8 -*-# 技术支持:https://www.jianshu.com/u/69f40328d4f0 # 技术支持 https://china-testing.github.io/# https://github.com/china-testing/python-api-tesing/blob/master/practices/cv/cv1.py# 项目实战讨论QQ群630011153 144081101# CreateDate: 2018-12-04# import the necessary packagesfrom tkinter import *from PIL import Imagefrom PIL import ImageTkfrom tkinter import filedialogimport cv2def select_image():

# grab a reference to the image panels

global panelA, panelB    # open a file chooser dialog and allow the user to select an input

# image

path = filedialog.askopenfilename()    # ensure a file path was selected

if len(path) > 0:        # load the image from disk, convert it to grayscale, and detect

# edges in it

image = cv2.imread(path)

gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)

edged = cv2.Canny(gray, 50, 100)        # OpenCV represents images in BGR order; however PIL represents

# images in RGB order, so we need to swap the channels

image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)        # convert the images to PIL format...

image = Image.fromarray(image)

edged = Image.fromarray(edged)        # ...and then to ImageTk format

image = ImageTk.PhotoImage(image)

edged = ImageTk.PhotoImage(edged)        # if the panels are None, initialize them

if panelA is None or panelB is None:            # the first panel will store our original image

panelA = Label(image=image)

panelA.image = image

panelA.pack(side="left", padx=10, pady=10)            # while the second panel will store the edge map

panelB = Label(image=edged)

panelB.image = edged

panelB.pack(side="right", padx=10, pady=10)        # otherwise, update the image panels

else:            # update the pannels

panelA.configure(image=image)

panelB.configure(image=edged)

panelA.image = image

panelB.image = edged# initialize the window toolkit along with the two image panelsroot = Tk()

panelA = NonepanelB = Noneroot.title("opencv 边缘检测演示")

# create a button, then when pressed, will trigger a file chooser# dialog and allow the user to select an input image; then add the# button the GUIbtn = Button(root, text="选择图片", command=select_image)

btn.pack(side="bottom", fill="both", expand="yes", padx="100", pady="100")# kick off the GUIroot.mainloop()

作者:python作业AI毕业设计

链接:https://www.jianshu.com/p/3e80a0b49218

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值