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

珠海集团网站建设友の 连接

珠海集团网站建设,友の 连接,郑州富士康疫情最新消息,东莞长安网站制作OpenCV 方法演示项目 项目地址:https://github.com/WangQvQ/opencv-tutorial 项目简介 这个开源项目是一个用于演示 OpenCV 方法的工具,旨在帮助初学者快速理解和掌握 OpenCV 图像处理技术。通过这个项目,你可以轻松地对图像进行各种处理&a…

OpenCV 方法演示项目

项目地址:https://github.com/WangQvQ/opencv-tutorial

请添加图片描述


项目简介

这个开源项目是一个用于演示 OpenCV 方法的工具,旨在帮助初学者快速理解和掌握 OpenCV 图像处理技术。通过这个项目,你可以轻松地对图像进行各种处理,从灰度化到边缘检测,以及更多其他方法。项目使用 Gradio 创建用户友好的界面,让用户能够轻松选择不同的图像处理方法和参数。


为什么选择这个项目

  • 教育性:这个项目的主要目的是教育。它提供了对 OpenCV 方法的实际演示,以帮助初学者更好地理解和掌握这些技术。

  • 互动性:通过 Gradio 创建的用户界面,用户可以立即看到不同处理方法的效果,并可以自己调整参数,以更深入地理解每种方法的工作原理。

  • 适用广泛:这个项目可以帮助广大初学者,无论是学习计算机视觉、图像处理,还是对 OpenCV 有兴趣的人都会受益。


特性

  • 提供了多种 OpenCV 图像处理方法的演示,包括灰度化、反转颜色、平移、直方图均衡化、腐蚀、膨胀、均值滤波、中值滤波、高斯滤波等。

  • 支持自定义卷积核,允许用户尝试不同的卷积核来处理图像。

  • 提供图像旋转、仿射变换和透射变换的演示,以及选择角度和参数的选项。

  • 使用 Gradio 创建用户友好的界面,让用户能够轻松选择不同的图像处理方法和参数。


使用方法

  1. 获取项目:首先,你需要将这个项目克隆到你的本地计算机上。你可以使用以下命令来获取项目:

    git clone https://github.com/WangQvQ/opencv-tutorial.git
    
  2. 安装依赖项:确保你已经安装了以下依赖项:

    • OpenCV
    • Gradio
    • NumPy

    如果你没有安装它们,你可以使用以下命令安装:

    pip install opencv-python-headless=4.7.0.72 gradio=3.1.5 numpy=1.22.4
    
  3. 运行项目:使用以下命令来运行项目:

    python opencv_demo.py
    

    运行后,你将看到一个网址,通常是 http://localhost:7860,你可以在浏览器中访问它。

  4. 使用界面:在浏览器中,你可以上传图像并选择不同的处理方法和参数,然后查看处理后的图像效果。


示例代码

请添加图片描述

以下是部分方法的代码示例:

# 灰度化处理函数
def grayscale(input_image):gray_image = cv2.cvtColor(input_image, cv2.COLOR_BGR2GRAY)return gray_image# 平移图像处理函数
def translate_image(input_image, translation_x, translation_y):rows, cols, _ = input_image.shapetranslation_matrix = np.float32([[1, 0, translation_x], [0, 1, translation_y]])translated_image = cv2.warpAffine(input_image, translation_matrix, (cols, rows))return translated_image# Canny 边缘检测处理函数
def edge_detection(input_image):edges = cv2.Canny(input_image, 100, 200)return edges

贡献

如果你对项目有任何改进或建议,欢迎贡献代码或提出问题。我们欢迎开发者共同改进这个项目,以使其更加有用和友好。


源代码

如果你不想克隆项目,也可以直接运行我的源代码:

import cv2  
import gradio as gr  
import numpy as np  # 原始图像处理函数
def original_image(input_image):return input_image# 灰度化处理函数
def grayscale(input_image):gray_image = cv2.cvtColor(input_image, cv2.COLOR_BGR2GRAY)return gray_image# 平移图像处理函数
def translate_image(input_image, translation_x, translation_y):rows, cols, _ = input_image.shapetranslation_matrix = np.float32([[1, 0, translation_x], [0, 1, translation_y]])translated_image = cv2.warpAffine(input_image, translation_matrix, (cols, rows))return translated_image# Canny 边缘检测处理函数
def edge_detection(input_image):edges = cv2.Canny(input_image, 100, 200)return edges# Sobel 边缘检测处理函数
def sobel_edge_detection(input_image):gray_image = cv2.cvtColor(input_image, cv2.COLOR_BGR2GRAY)sobel_x = cv2.Sobel(gray_image, cv2.CV_64F, 1, 0, ksize=5)sobel_y = cv2.Sobel(gray_image, cv2.CV_64F, 0, 1, ksize=5)sobel_magnitude = cv2.magnitude(sobel_x, sobel_y)sobel_magnitude = np.uint8(255 * sobel_magnitude / np.max(sobel_magnitude))return sobel_magnitude# 反转颜色处理函数
def invert_colors(input_image):inverted_image = cv2.bitwise_not(input_image)return inverted_image# 腐蚀处理函数
def erosion(input_image, iterations):kernel = np.ones((5, 5), np.uint8)eroded_image = cv2.erode(input_image, kernel, iterations=iterations)return eroded_image# 膨胀处理函数
def dilation(input_image, dilation_iterations):kernel = np.ones((5, 5), np.uint8)dilated_image = cv2.dilate(input_image, kernel, iterations=dilation_iterations)return dilated_image# 均值滤波处理函数
def mean_blur(input_image):mean_blurred_image = cv2.blur(input_image, (5, 5))return mean_blurred_image# 中值滤波处理函数
def median_blur(input_image):median_blurred_image = cv2.medianBlur(input_image, 5)return median_blurred_image# 高斯滤波处理函数
def gaussian_blur(input_image):gaussian_blurred_image = cv2.GaussianBlur(input_image, (5, 5), 0)return gaussian_blurred_image# 双边滤波处理函数
def bilateral_filter(input_image):bilateral_filtered_image = cv2.bilateralFilter(input_image, 9, 75, 75)return bilateral_filtered_image# 方块滤波处理函数
def box_filter(input_image):box_filtered_image = cv2.boxFilter(input_image, -1, (5, 5))return box_filtered_image# 直方图均衡化处理函数
def histogram_equalization(input_image):gray_image = cv2.cvtColor(input_image, cv2.COLOR_BGR2GRAY)equalized_image = cv2.equalizeHist(gray_image)return cv2.cvtColor(equalized_image, cv2.COLOR_GRAY2BGR)# 仿射变换处理函数
def affine_transform(input_image):# 创建仿射变换矩阵rows, cols, _ = input_image.shapematrix = cv2.getRotationMatrix2D((cols / 4, rows / 2), 70, 0.5)  # 90度旋转和1.5倍缩放result_image = cv2.warpAffine(input_image, matrix, (cols, rows))return result_image# 透射变换处理函数
def perspective_transform(input_image):# 定义四个输入图像的角点坐标rows, cols, _ = input_image.shape# 修改pts1和pts2的值以减小透射变换的弯曲程度pts1 = np.float32([[0, 0], [cols, 0], [0, rows], [cols, rows]])pts2 = np.float32([[30, 30], [cols - 50, 50], [50, rows - 50], [cols - 50, rows - 50]])# 计算投射矩阵matrix = cv2.getPerspectiveTransform(pts1, pts2)# 进行投射变换result_image = cv2.warpPerspective(input_image, matrix, (cols, rows))return result_image# 自定义卷积核
def custom_filter(input_image):kernel = np.array([[-1, -1, -1], [-1, 9, -1], [-1, -1, -1]])return cv2.filter2D(input_image, -1, kernel)# 图像旋转处理函数
def rotate_image(input_image, rotation_angle):rows, cols, _ = input_image.shapematrix = cv2.getRotationMatrix2D((cols / 2, rows / 2), rotation_angle, 1)result_image = cv2.warpAffine(input_image, matrix, (cols, rows))return result_image# 创建 Gradio 接口
input_image = gr.inputs.Image()
method = gr.inputs.Radio(choices=["原图", "灰度化", "反转颜色", "平移", "直方图均衡化", "腐蚀", "膨胀", "均值滤波", "中值滤波", "高斯滤波","双边滤波", "方块滤波", "仿射变换", "透射变换", "图像旋转", "Sobel边缘检测", "Canny边缘检测", "自定义卷积核"], default="原图")rotation_angle = gr.inputs.Slider(minimum=-180, maximum=180, default=45, label="图像旋转: 旋转角度")
iterations = gr.inputs.Slider(minimum=0, maximum=10, step=1, default=1, label="腐蚀: 腐蚀参数")
dilation_iterations = gr.inputs.Slider(minimum=0, maximum=10, step=1, default=1, label="膨胀: 膨胀参数")
translation_x = gr.inputs.Slider(minimum=-200, maximum=200, default=200, label="平移: X轴平移")
translation_y = gr.inputs.Slider(minimum=-200, maximum=200, default=200, label="平移: Y轴平移")output_image = gr.outputs.Image(type="pil")# 创建函数根据下拉菜单的选择来执行不同的方法
def apply_opencv_methods(input_image, method, rotation_angle, iterations, dilation_iterations,translation_x, translation_y):if method == "原图":return original_image(input_image)elif method == "图像旋转":return rotate_image(input_image, rotation_angle)elif method == "腐蚀":return erosion(input_image, iterations)elif method == "膨胀":return dilation(input_image, dilation_iterations)elif method == "Sobel边缘检测":return sobel_edge_detection(input_image)elif method == "平移":return translate_image(input_image, translation_x, translation_y)elif method == "自定义卷积核":return custom_filter(input_image)else:methods = {"灰度化": grayscale,"Canny边缘检测": edge_detection,"反转颜色": invert_colors,"均值滤波": mean_blur,"中值滤波": median_blur,"高斯滤波": gaussian_blur,"双边滤波": bilateral_filter,"方块滤波": box_filter,"仿射变换": affine_transform,"透射变换": perspective_transform,"直方图均衡化": histogram_equalization,}return methods[method](input_image)# 创建 Gradio 接口
gr.Interface(fn=apply_opencv_methods,inputs=[input_image, method, rotation_angle, iterations, dilation_iterations, translation_x,translation_y],outputs=output_image,live=True,title="图像处理初学者导引",description="选择一张图像, 并选择对应方法"
).launch(share=False)
http://www.yidumall.com/news/97564.html

相关文章:

  • 为什么动态网站要建设虚拟目录百度关键词排名点击
  • 城乡建设局和住监局官网关键词优化到首页怎么做到的
  • wordpress转成中文版免费seo诊断
  • 网站建设南京人民日报评网络暴力
  • 专业刷单网站建设竞价推广遇到恶意点击怎么办
  • seo网站快速国内seo排名分析主要针对百度
  • 电子商务网站模板页面如何推广一个项目
  • 怎么免费做一个网站做淘宝客精准大数据获客系统
  • 手机类网站设计上海培训机构白名单
  • 济南网站怎么做国际最新消息
  • 做代理的项目在哪个网站线上购买链接
  • 16岁的做兼职在什么网站好网站优化检测
  • 东营教育信息网官网谷歌seo一个月费用需要2万吗
  • 网页设计代码html个人简介百度seo优化按年收费
  • 杭州做公司网站的公司网络营销策略是什么
  • 网站企业建设产品推广计划方案
  • 网站设计与开发期末考试题竞价推广代运营
  • 小程序云开发文档seo公司发展前景
  • 泰兴公司做网站网站开发从入门到实战
  • 简约商务ppt模板免费下载宁波seo优化公司排名
  • 平面设计免费素材网站网站建设制作专业
  • 河南网站建设的详细策划营销网站建设培训学校
  • HTMT超链接网站怎么做制作网站需要的技术与软件
  • 注册公司网上申请入口网站武汉大学人民医院精神卫生中心
  • 做pc端网站价位企业seo整站优化方案
  • png免费素材网站武汉seo优化顾问
  • 国家批准的现货交易所seo网站优化培训公司
  • iis7 静态网站哪个平台推广效果最好
  • 网站换主机换域名seo关键词排名优化的方法
  • 怎么用织梦做自适应网站北京seo排名厂家