当前位置: 首页 > 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.yayakq.cn/news/465160/

相关文章:

  • 做网站架构电子产品网页设计
  • 建设高端网站公司哪家好wordpress电子邮件
  • 网站首页的布局方式html5做网站的代码
  • 泉州外贸网站建设都有哪些公司沂水住房与城乡建设局网站
  • 珠海网站建设维护seo推广优化外包价格
  • 创建网站需要注意的问题如何利用seo赚钱
  • 网站发展规划营销型网站建站步骤是什么意思
  • 好三网网站管理软件开发工程师
  • 工艺品网站模板下载-古色古香wordpress固定连接404
  • 苏州网站开发公司兴田德润在哪儿建设银行网银盾官方网站下载
  • 2345影视大全是免费追剧吗网站seo计划书
  • wordpress怎么添加会员中心seo外链收录
  • 荆门网站建设514885镇江网站seo外包
  • 临沂个人做网站做免费导航网站
  • 河源市连平县建设局网站宁国市网站建设
  • 隧道建设期刊网站进不去广州网站建设服务公司
  • 百度商城网站建设网站建设培训总结
  • 建个门户网站电商平台网站运营方案
  • 郑州汉狮做网站报价wordpress付费主题网
  • 哈尔滨建站流程网站收录下降的原因
  • 泰安网站建设优化网站制作怎么做语音搜索框
  • 上海网站开发公司电话聊城做网站的公司教程
  • 云浮+网站建设优惠券的网站制作
  • 做购物网站收费标准京东商城官网登录
  • 做网站的需要考什么证书吗wordpress需要做哪些设置
  • 晋城网站制作滕州个人兼职做网站
  • 做网站有什么意义网站建设表格的属性
  • 建立网站第一步是什么服装定制店的前景
  • 电影网站开发任务书湖北系统建站怎么用
  • 做网站的好公司有哪些网站设计网页设计