当前位置: 首页 > wzjs >正文

厦门网站建设方案策划做网站开发需要什么技能

厦门网站建设方案策划,做网站开发需要什么技能,南京网络推广优化哪家好,wordpress底部悬浮python实现简单的图片去水印工具 使用说明: 点击"打开图片"选择需要处理的图片 在图片上拖拽鼠标选择水印区域(红色矩形框) 点击"去除水印"执行处理 点击"保存结果"保存处理后的图片 运行效果 先简要说明…

python实现简单的图片去水印工具

使用说明:

点击"打开图片"选择需要处理的图片

在图片上拖拽鼠标选择水印区域(红色矩形框)

点击"去除水印"执行处理

点击"保存结果"保存处理后的图片

运行效果

先简要说明本程序用到的python库:

(1)from PIL import Image, ImageTk, ImageDraw 和 import PIL,需要Pillow。

Pillow 是一个图像处理库,用于处理图像的打开、操作和保存。它不是 Python 标准库的一部分,是第三方库需要单独安装。

(2)import cv2,需要OpenCV。

OpenCV 是一个计算机视觉库,用于图像和视频处理、目标检测等任务。它不是 Python 标准库的一部分,是第三方库需要单独安装。

(3)import numpy as np,需要NumPy 。

NumPy 是一个科学计算库,用于高效处理多维数组和矩阵运算。它第三方库,需要单独安装。

(4)import tkinter as tk 和 from tkinter import filedialog, messagebox,需要tkinter。

tkinter 是 Python 的标准 GUI 库,用于创建图形用户界面。它是 Python 标准库的一部分,不需要单独安装。

(5)import os,需要os。

os 是 Python 的标准库,用于操作操作系统相关的功能,如文件和目录操作。它也是 Python 标准库的一部分,不需要单独安装。

Python第三方扩展库Pillow 更多情况可见 https://blog.csdn.net/cnds123/article/details/126141838

Python第三方库OpenCV (cv2) 更多情况可见 https://blog.csdn.net/cnds123/article/details/126547307

Python第三方扩展库NumPy 更多情况可见 https://blog.csdn.net/cnds123/article/details/135844660

源码如下:

import tkinter as tk
from tkinter import filedialog, messagebox
from PIL import Image, ImageTk, ImageDraw
import PIL
import cv2
import numpy as np
import osclass WatermarkRemoverApp:def __init__(self, root):self.root = rootself.root.title("简单的图片去水印工具")# 初始化变量self.original_image = Noneself.processed_image = Noneself.display_ratio = 1.0self.selection_rect = Noneself.mask = None# 创建界面布局self.create_widgets()# 鼠标事件绑定self.canvas.bind("<ButtonPress-1>", self.start_selection)self.canvas.bind("<B1-Motion>", self.update_selection)self.canvas.bind("<ButtonRelease-1>", self.end_selection)self.original_file_path = None  # 新增实例变量def create_widgets(self):# 工具栏toolbar = tk.Frame(self.root)toolbar.pack(fill=tk.X)btn_open = tk.Button(toolbar, text="打开图片", command=self.open_image)btn_open.pack(side=tk.LEFT, padx=2, pady=2)btn_process = tk.Button(toolbar, text="去除水印", command=self.remove_watermark)btn_process.pack(side=tk.LEFT, padx=2, pady=2)btn_save = tk.Button(toolbar, text="保存结果", command=self.save_image)btn_save.pack(side=tk.LEFT, padx=2, pady=2)# 图像显示区域self.canvas = tk.Canvas(self.root, bg='gray', cursor="cross")self.canvas.pack(fill=tk.BOTH, expand=True)def open_image(self):file_path = filedialog.askopenfilename(filetypes=[("Image Files", "*.jpg *.jpeg *.png *.bmp")])if not file_path:returntry:self.original_image = Image.open(file_path)self.original_file_path = file_path  # 保存原始路径self.processed_image = Noneself.show_image(self.original_image)self.mask = Noneexcept Exception as e:messagebox.showerror("错误", f"无法打开图片:\n{str(e)}")def show_image(self, image):# 计算缩放比例canvas_width = self.canvas.winfo_width()canvas_height = self.canvas.winfo_height()img_width, img_height = image.sizeself.display_ratio = min(canvas_width / img_width,canvas_height / img_height,1.0  # 最大保持原始尺寸)display_size = (int(img_width * self.display_ratio),int(img_height * self.display_ratio))# 缩放并显示图像if hasattr(Image, 'Resampling'):resample_method = Image.Resampling.LANCZOSelse:resample_method = Image.LANCZOS  # 旧版本回退display_image = image.resize(display_size, resample_method)self.tk_image = ImageTk.PhotoImage(display_image)self.canvas.delete("all")self.canvas.config(width=display_size[0],height=display_size[1])self.canvas.create_image(0, 0, anchor=tk.NW, image=self.tk_image)def start_selection(self, event):self.selection_rect = (event.x, event.y, event.x, event.y)def update_selection(self, event):if self.selection_rect:x0, y0, _, _ = self.selection_rectx1, y1 = event.x, event.yself.selection_rect = (x0, y0, x1, y1)self.draw_selection_rect()def end_selection(self, event):if self.selection_rect:self.draw_selection_rect()# 转换到原始图像坐标x0 = int(self.selection_rect[0] / self.display_ratio)y0 = int(self.selection_rect[1] / self.display_ratio)x1 = int(self.selection_rect[2] / self.display_ratio)y1 = int(self.selection_rect[3] / self.display_ratio)# 创建掩膜self.mask = Image.new("L", self.original_image.size, 0)draw = ImageDraw.Draw(self.mask)draw.rectangle([x0, y0, x1, y1], fill=255)def draw_selection_rect(self):self.canvas.delete("selection")x0, y0, x1, y1 = self.selection_rectself.canvas.create_rectangle(x0, y0, x1, y1,outline="red",tags="selection")def remove_watermark(self):if not self.original_image:messagebox.showwarning("警告", "请先打开图片")returnif not self.mask:messagebox.showwarning("警告", "请先选择水印区域")returntry:# 转换图像格式img = cv2.cvtColor(np.array(self.original_image), cv2.COLOR_RGB2BGR)mask = np.array(self.mask)# 使用OpenCV的inpaint方法radius = 10result = cv2.inpaint(img, mask, radius, cv2.INPAINT_TELEA)# 转换回PIL格式self.processed_image = Image.fromarray(cv2.cvtColor(result, cv2.COLOR_BGR2RGB))self.show_image(self.processed_image)except Exception as e:messagebox.showerror("错误", f"处理失败:\n{str(e)}")def save_image(self):if not self.processed_image:messagebox.showwarning("警告", "没有可保存的结果")returnif not self.original_file_path:messagebox.showwarning("警告", "未找到原始文件信息")return# 生成默认文件名original_name = os.path.basename(self.original_file_path)default_name = f"RW_{original_name}"file_path = filedialog.asksaveasfilename(defaultextension=".png",filetypes=[("PNG", "*.png"), ("JPEG", "*.jpg"), ("BMP", "*.bmp")],initialfile=default_name  # 设置默认文件名)if file_path:try:self.processed_image.save(file_path)messagebox.showinfo("成功", "图片保存成功")except Exception as e:messagebox.showerror("错误", f"保存失败:\n{str(e)}")if __name__ == "__main__":root = tk.Tk()app = WatermarkRemoverApp(root)root.geometry("800x600")root.mainloop()


文章转载自:

http://d5wyQ27y.ypmqy.cn
http://yWQADlRK.ypmqy.cn
http://ibQFVvEt.ypmqy.cn
http://4EPth1o1.ypmqy.cn
http://8HDqJ39D.ypmqy.cn
http://29UazkMr.ypmqy.cn
http://AoPdeiPA.ypmqy.cn
http://CdPcY29X.ypmqy.cn
http://P9seyGYU.ypmqy.cn
http://p0r4pytI.ypmqy.cn
http://gEvtMPv5.ypmqy.cn
http://XCElhuqb.ypmqy.cn
http://vfHFaPoa.ypmqy.cn
http://nzvma6Sv.ypmqy.cn
http://QdTBNHSI.ypmqy.cn
http://9fTsfCyy.ypmqy.cn
http://XBdmViGg.ypmqy.cn
http://82m5fpTO.ypmqy.cn
http://oQY3csPa.ypmqy.cn
http://gRI3YFur.ypmqy.cn
http://Q3IKH67P.ypmqy.cn
http://GGUHDd7i.ypmqy.cn
http://q1m34Okj.ypmqy.cn
http://yTtn49Qw.ypmqy.cn
http://fWClzhs2.ypmqy.cn
http://c4ZbqCPr.ypmqy.cn
http://YDrM9mbQ.ypmqy.cn
http://jL80VBhc.ypmqy.cn
http://7OwKCwdz.ypmqy.cn
http://PuvXK6NW.ypmqy.cn
http://www.dtcms.com/wzjs/766419.html

相关文章:

  • 企业网站建设 调研制作触屏版网站开发
  • wordpress子站共享用户名中国局势最新消息今天
  • 网站开发专业成功人士广东做网站公司
  • 网站建设协议需要注意的问题wordpress 中文在线字体
  • 免费查公司信息的网站宁波网站seo
  • 网站建设 中企动力 常州洛阳设计公司官网
  • 沈阳cms建站模板房地产网站 模板
  • 江西网站开发科技公司wordpress预订插件
  • 抖音开放平台搜索引擎优化的步骤和具体方法
  • 怎么让公司建设网站邓州市建设局网站
  • 设计网站的元素汕头 网站设计
  • 做家装的网站好有关网站开发的论文
  • 晋江模板建站google安卓手机下载
  • 网站打开不对淘宝接单做网站
  • 宁波哪里有网站建设杭州画册设计公司
  • 用mvc做网站的缺点seo诊断工具有哪些
  • 深圳营销型网站建设费用丰台网站制作公司
  • 企业品牌网站建设类型鲜花网站开发背景
  • 如何备份网站 整站建设电子商务系统网站
  • 网站底部设计源码网站实现留言功能吗
  • 轻松网站建设网站维护运营主要是做什么的
  • 自己可以做网站推广吗网站基本架构设计的主要步骤
  • 网站集约化建设 技术做js题目的网站知乎
  • 移动端网站的优势百度找不到我的网站了
  • 做网站的公司主要工作网站运营团队建设
  • 惠州建设厅网站怎样用flash做网站
  • 手机网站的建设价格wordpress主页显示分类
  • 华文细黑做网站有版权吗做个网站要多少钱建站费用明细表
  • 中国最新消息军事方面的婚纱摄影 网站关键词 优化
  • 崇明建设镇乡镇府网站义乌市企推网络科技有限公司