专栏名称: 小白学视觉
本公众号主要介绍机器视觉基础知识和新闻,以及在学习机器视觉时遇到的各种纠结和坑的心路历程。
目录
相关文章推荐
小米汽车  ·  成都天府赛道 ... ·  15 小时前  
不正常人类研究中心  ·  已经到了不爱吃零食的年纪了 ·  昨天  
不正常人类研究中心  ·  意大利人这是身经百战了 ·  昨天  
51好读  ›  专栏  ›  小白学视觉

一些有用的 OpenCV 函数

小白学视觉  · 公众号  ·  · 2025-02-08 19:18

正文

点击上方 小白学视觉 ”,选择加" 星标 "或“ 置顶

重磅干货,第一时间送达

1.cv2.imread() — 用于读取图像文件并将其存储为 NumPy 数组。

import cv2

# Read an image file and store it as a NumPy array
image = cv2.imread('image.jpg')
  1. cv2.imshow() — 用于在屏幕上显示图像。
import cv2

# Read an image file and store it as a NumPy array
image = cv2.imread('image.jpg')

# Display the image on the screen
cv2.imshow('Image', image)

# Wait for the user to press any key before closing the window
cv2.waitKey(0)

# Destroy the window
cv2.destroyAllWindows()
  1. cv2.cvtColor() — 用于将图像从一种颜色空间转换为另一种颜色空间。
import cv2

# Read an image file and store it as a NumPy array
image = cv2.imread('image.jpg')

# Convert the image from BGR to grayscale
gray_image = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
  1. cv2.resize() — 用于调整图像大小。
import cv2

# Read an image file and store it as a NumPy array
image = cv2.imread('image.jpg')

# Resize the image to half its original size
resized_image = cv2.resize(image, (int(image.shape[1]/2), int(image.shape[0]/2)))
  1. cv2.GaussianBlur() — 用于使用高斯内核模糊图像。
import cv2

# Read an image file and store it as a NumPy array
image = cv2.imread('image.jpg')

# Blur the image using a Gaussian kernel with a kernel size of 5x5
blurred_image = cv2.GaussianBlur(image, (5,5), 0)
  1. cv2.Canny() — 用于使用 Canny 边缘检测算法检测图像中的边缘。
import cv2

# Read an image file and store it as a NumPy array
image = cv2.imread('image.jpg')

# Detect edges in the image using the Canny edge detection algorithm
edges = cv2.Canny(image, 100200)
  1. cv2.threshold() — 用于对图像应用阈值处理,将其转换为二值图像。
import cv2

# Read an image file and store it as a NumPy array
image = cv2.imread('image.jpg')

# Apply thresholding to the image, turning it into a binary image
_, thresholded_image = cv2.threshold(image, 127255, cv2.THRESH_BINARY


下载1:OpenCV-Contrib扩展模块中文版教程
在「小白学视觉」公众号后台回复:扩展模块中文教程即可下载全网第一份OpenCV扩展模块教程中文版,涵盖扩展模块安装、SFM算法、立体视觉、目标跟踪、生物视觉、超分辨率处理等二十多章内容。

下载2:Python视觉实战项目52讲
小白学视觉公众号后台回复:Python视觉实战项目即可下载包括图像分割、口罩检测、车道线检测、车辆计数、添加眼线、车牌识别、字符识别、情绪检测、文本内容提取、面部识别等31个视觉实战项目,助力快速学校计算机视觉。






请到「今天看啥」查看全文