OpenCV,Python代码示例
时间: 2023-02-20 11:57:45 浏览: 16
OpenCV是一个开源的计算机视觉库,支持多种语言,包括Python。下面是一个使用OpenCV在Python中读取并显示图像的示例代码:
```python
import cv2
# 读取图像
img = cv2.imread("image.jpg")
# 显示图像
cv2.imshow("Image", img)
# 等待键盘输入
cv2.waitKey(0)
# 释放窗口
cv2.destroyAllWindows()
```
在这段代码中,首先导入了OpenCV库,然后使用`cv2.imread`函数读取了名为"image.jpg"的图像。接着使用`cv2.imshow`函数显示了图像,并使用`cv2.waitKey(0)`等待键盘输入。最后使用`cv2.destroyAllWindows()`释放窗口。
相关问题
opencv Python代码
以下是一个简单的 OpenCV Python 代码示例,用于读取图像文件并显示它:
```python
import cv2
# 读取图像文件
img = cv2.imread('image.jpg')
# 显示图像
cv2.imshow('Image', img)
# 等待用户按下任意按键
cv2.waitKey(0)
# 关闭窗口
cv2.destroyAllWindows()
```
这个代码读取名为 `image.jpg` 的图像文件,并将其显示在名为 `Image` 的窗口中。用户需要按下任意键才能关闭窗口。
opencv python 示例、
以下是一个简单的 OpenCV Python 示例,演示如何读取图像并显示它:
```python
import cv2
# 读取图像
img = cv2.imread('image.jpg')
# 显示图像
cv2.imshow('Image', img)
# 等待按键
cv2.waitKey(0)
# 释放窗口
cv2.destroyAllWindows()
```
这个示例首先使用 `cv2.imread()` 函数读取名为 `image.jpg` 的图像文件。然后,它使用 `cv2.imshow()` 函数显示图像,并在窗口中命名为 “Image”。代码中的 `cv2.waitKey()` 函数会等待用户按下任意按键,然后继续执行程序。最后,`cv2.destroyAllWindows()` 函数释放窗口并关闭程序。
注意,这个示例假设你已经安装了 OpenCV Python 库和 NumPy 库。如果你没有安装这些库,你需要先安装它们才能运行此示例。
阅读全文
相关推荐












