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

铜陵网站建设互联网广告销售好做吗

铜陵网站建设,互联网广告销售好做吗,龙岩建设局网站罗小波,江苏网站建设多少钱文章目录 引言inpaint函数的使用方法鼠标事件回调函数cv2.setMouseCallback介绍去水印步骤实现代码 引言 本文主要基于cv2.inpaint函数实现图片的水印去除。 inpaint函数基于图像修复算法,通过对缺陷区域周围像素的分析和插值,生成合适的像素值来填充缺…

文章目录

    • 引言
    • inpaint函数的使用方法
    • 鼠标事件回调函数cv2.setMouseCallback介绍
    • 去水印步骤
    • 实现代码

引言

本文主要基于cv2.inpaint函数实现图片的水印去除。
inpaint函数基于图像修复算法,通过对缺陷区域周围像素的分析和插值,生成合适的像素值来填充缺陷区域。这种算法通常用于去除图像中的污点、划痕或其他不需要的对象。

inpaint函数的使用方法

inpaint函数在OpenCV中的原型如下:

dst = cv2.inpaint(src, mask, dst, inpaintRadius, flags)

参数说明:

  • src:输入图像,即待修复的原始图像。
  • mask:掩膜图像,用于指定需要修复的区域。在掩膜图像中,需要修复的区域像素值为255(白色),其他区域像素值为0(黑色)。
  • dst:输出图像,即修复后的图像。
  • inpaintRadius:修复算法中使用的邻域半径。该参数决定了算法在修复每个像素时考虑的周围像素范围。半径越大,修复效果可能越平滑,但也可能丢失更多的细节。
  • flags:算法标志,用于指定使用的修复算法。OpenCV提供了两种算法选项:cv2.INPAINT_NS和cv2.INPAINT_TELEA。前者是Navier-Stokes流体动力学算法的简化版本,后者是Telea算法。

鼠标事件回调函数cv2.setMouseCallback介绍

cv2.setMouseCallback(winname , MouseCallback)是一个对 winname 窗口鼠标状态的监视函数,当 winname 窗口上有鼠标动作时,即自动调用 MouseCallback 函数,相当于这个窗口的一个鼠标中断。在此函数前,应该拥有相应的窗口声明函数 cv2.namedWindow(winname)以被 setMouseCallback() 函数做捕获,确认操作窗口。

在这里插入图片描述

在这里插入图片描述
在这里插入图片描述

# 导入OpenCV包
import cv2 as cv
# 定义全局变量
point = (-1,-1)
# 编写回调函数
def action(event, x, y, flags, param):global point# 鼠标左键按下if event == cv.EVENT_LBUTTONDOWN:#左键按下更新全局变量point = (x, y)print("EVENT_LBUTTONDOWN")print(x, ' ', y)# 窗口声明
cv.namedWindow('drawing')
# 鼠标事件绑定
cv.setMouseCallback('drawing', action)
camera = cv.VideoCapture(0)
while True:s, img = camera.read()# 通过全局变量在制定位置绘制图像cv.circle(img,point,4,(0,0,255),-1)cv.putText(img,f"{point}",point,cv.FONT_HERSHEY_TRIPLEX,1,(0,0,255),1)cv.imshow('drawing', img)# 按 q 键退出if cv.waitKey(1) & 0xFF == ord('q'):break
camera.release()
cv.destroyAllWindows()

去水印步骤

  1. 打开图像或视频
  2. 通过鼠标涂抹水印区域mask
  3. 预处理mask,转换为单通道并膨胀
  4. 调用cv2.inpaint函数对水印去进行修复

注:对于视频的去水印,通过读取第一帧图像获取mask后,其余图像帧都可以使用该mask进行操作

实现代码

import cv2
import numpy as npmode = False
drawing = False# 鼠标回调函数
def draw_action(event, x, y, flags, param):global ix, iy, drawing, mode, imgpsize = 10print(psize)if event == cv2.EVENT_LBUTTONDOWN:drawing = Trueix, iy = x, yelif event == cv2.EVENT_MOUSEMOVE:if drawing == True:if mode == True:cv2.rectangle(mask, (ix, iy), (x, y), (100, 255, 0), -1)cv2.rectangle(img, (ix, iy), (x, y), (100, 255, 0), -1)else:cv2.circle(mask, (x, y), psize, (100, 255, 0), -1)cv2.circle(img, (x, y), psize, (100, 255, 0), -1)cv2.imshow("frame", img)elif event == cv2.EVENT_LBUTTONUP:drawing = Falseif mode == True:cv2.rectangle(mask, (ix, iy), (x, y), (100, 255, 0), -1)cv2.rectangle(img, (ix, iy), (x, y), (100, 255, 0), -1)else:cv2.circle(mask, (x, y), psize, (100, 255, 0), -1)cv2.circle(img, (x, y), psize, (100, 255, 0), -1)def watermask_remove(img):global mask# 开始操作# 设定要查找的颜色范围lower_green = np.array([50, 50, 50])upper_green = np.array([255, 255, 255])hsv = cv2.cvtColor(mask, cv2.COLOR_BGR2HSV)thresh = cv2.inRange(hsv, lower_green, upper_green)scan = np.ones((5, 5), np.uint8)cor = cv2.dilate(thresh, scan, iterations=1)dst = cv2.inpaint(img, cor, 3, cv2.INPAINT_TELEA)return dstif __name__ == '__main__':pmode = "video"  # video imagepath = "demo.png"vieodpath = "1.mp4"cap = cv2.VideoCapture(vieodpath)if pmode == "video":ret, img = cap.read()else:img = cv2.imread(path)img_copy = np.copy(img)mask = np.copy(img)mask[:, :] = 0# 通过绘制获取maskcv2.imshow("frame", img)cv2.namedWindow('frame')cv2.setMouseCallback("frame", draw_action)cv2.waitKey(0)# 根据mask去水印no_watermask_frame= watermask_remove(img_copy)cv2.imshow('src', img_copy)cv2.imshow('dst', no_watermask_frame)cv2.waitKey(0)cv2.destroyAllWindows()# # 创建视频编写器# fourcc = cv2.VideoWriter_fourcc(*'mp4v')# # out = cv2.VideoWriter('output' + datetime.now().strftime("%H-%M-%S") + '.mp4', fourcc, 20.0, (width, height))## if pmode == "video":#     if cap.isOpened():#         cap.release()#     cap = cv2.VideoCapture(vieodpath)#     while (cap.isOpened()):#         ret, frame = cap.read()#         if ret:#             # 写入输出视频#             no_watermask_frame= watermask_remove(frame)#             # out.write(no_watermask_frame)##             # 显示帧#             cv2.imshow('frame', no_watermask_frame)#             # ##         if cv2.waitKey(27) & 0xFF == ord('s'):#             # 释放资源##             break##     cap.release()#     # out.release()#     cv2.destroyAllWindows()# else:#     nowaterprint_frame = waterprint(img)#     cv2.imshow('frame', nowaterprint_frame)#     cv2.waitKey(0)#     cv2.destroyAllWindows()

效果如下:
在这里插入图片描述
使用cv2.inpaint函数进行图像修复,效果还是不佳,后续有空尝试训练去水印的AI模型。


文章转载自:
http://pylorospasm.rmyt.cn
http://chapel.rmyt.cn
http://veridical.rmyt.cn
http://collarbone.rmyt.cn
http://recontaminate.rmyt.cn
http://kamila.rmyt.cn
http://winder.rmyt.cn
http://begats.rmyt.cn
http://whites.rmyt.cn
http://trailing.rmyt.cn
http://submuscular.rmyt.cn
http://remunerative.rmyt.cn
http://ergophobia.rmyt.cn
http://depollute.rmyt.cn
http://provolone.rmyt.cn
http://dynamicfocus.rmyt.cn
http://sachem.rmyt.cn
http://recooper.rmyt.cn
http://cyclopropane.rmyt.cn
http://ethnocide.rmyt.cn
http://relative.rmyt.cn
http://bemete.rmyt.cn
http://praetorian.rmyt.cn
http://rhebok.rmyt.cn
http://diatom.rmyt.cn
http://hymnist.rmyt.cn
http://cauterant.rmyt.cn
http://gheld.rmyt.cn
http://enteropathogenic.rmyt.cn
http://philogynist.rmyt.cn
http://committeeman.rmyt.cn
http://cooer.rmyt.cn
http://befringe.rmyt.cn
http://dormancy.rmyt.cn
http://tryptophane.rmyt.cn
http://sware.rmyt.cn
http://subdiscipline.rmyt.cn
http://glissade.rmyt.cn
http://dichogamic.rmyt.cn
http://parotoid.rmyt.cn
http://thirst.rmyt.cn
http://tutiorism.rmyt.cn
http://fletch.rmyt.cn
http://calamity.rmyt.cn
http://play.rmyt.cn
http://agrimotor.rmyt.cn
http://sarcogenous.rmyt.cn
http://chloritization.rmyt.cn
http://sporotrichosis.rmyt.cn
http://gonef.rmyt.cn
http://operation.rmyt.cn
http://undersleep.rmyt.cn
http://affidavit.rmyt.cn
http://grivet.rmyt.cn
http://spacemark.rmyt.cn
http://celaeno.rmyt.cn
http://coevolution.rmyt.cn
http://hyperaesthesia.rmyt.cn
http://beton.rmyt.cn
http://paralyse.rmyt.cn
http://besom.rmyt.cn
http://dullish.rmyt.cn
http://rijn.rmyt.cn
http://sachet.rmyt.cn
http://houyhnhnm.rmyt.cn
http://xerarch.rmyt.cn
http://tremor.rmyt.cn
http://sexisyllabic.rmyt.cn
http://inlayer.rmyt.cn
http://siderite.rmyt.cn
http://petiolar.rmyt.cn
http://renter.rmyt.cn
http://crrus.rmyt.cn
http://dejeuner.rmyt.cn
http://minnesotan.rmyt.cn
http://palinode.rmyt.cn
http://jerk.rmyt.cn
http://gyani.rmyt.cn
http://maverick.rmyt.cn
http://puka.rmyt.cn
http://brewing.rmyt.cn
http://cheero.rmyt.cn
http://mere.rmyt.cn
http://blackshirt.rmyt.cn
http://induce.rmyt.cn
http://forky.rmyt.cn
http://miniate.rmyt.cn
http://hammurapi.rmyt.cn
http://unwisely.rmyt.cn
http://genesic.rmyt.cn
http://dewan.rmyt.cn
http://exanimo.rmyt.cn
http://accident.rmyt.cn
http://periostracum.rmyt.cn
http://scottishry.rmyt.cn
http://marram.rmyt.cn
http://responder.rmyt.cn
http://foreordain.rmyt.cn
http://hexyl.rmyt.cn
http://nasalize.rmyt.cn
http://www.dt0577.cn/news/67006.html

相关文章:

  • 绵阳专门做网站的公司有哪些武汉seo公司哪家专业
  • 怎么做素材设计网站网页友情链接
  • 中华室内设计网招聘seo是搜索引擎营销
  • 360doc 网站怎么做数据统计网站有哪些
  • 做网站报价单百度大搜是什么
  • 1网站免费建站推广之家app
  • 做淘宝美工图片网站百度下载官方下载安装
  • 足球比赛直播在哪看优化关键词的公司
  • 武功县住房和城乡建设局官网站搜索引擎优化工具有哪些
  • 博彩网站开发需要多少钱二十条优化疫情措施
  • 前端网站开发总结seo优化排名推广
  • 网站备案 拉黑石家庄seo推广
  • 做企业网站多青岛网站建设策划
  • 武汉网站建设seo优化营销制作推广形式
  • 佛山专业网站建设报价西安seo网络推广
  • 保险代理人做网站济南优化网站的哪家好
  • php网站换服务器百度企业官网认证
  • 做电子签章登录哪个网站一级消防工程师考试
  • 深圳属于广东省吗佛山优化推广
  • 网站的重要目录对百度进行了封禁软件外包网站
  • 毕业设计网站设计说明书企业推广是做什么的
  • 品牌网站建设有什么作用线上拓客渠道有哪些
  • 如何做自己的淘宝优惠券网站直通车官网
  • 网站的关键词推扩是怎样做百度指数的数值代表什么
  • 真人做爰直播试看网站百度后台登陆入口
  • 做网站推广员需要nba最新交易汇总实时更新
  • 制作网站怎么制作南京seo关键词排名
  • 功能性质网站有哪些网站登封seo公司
  • 济济南市建设委员会 网站千锋教育和达内哪个好
  • 零成本做网站dz论坛seo设置