python opencv resize怎么指定以中点为基准进行缩放
时间: 2024-02-19 19:03:11 浏览: 235
要指定以图像中心为基准进行缩放,可以在resize函数中指定缩放中心点的坐标。具体步骤如下:
1. 计算图像中心点的坐标:
```python
import cv2
img = cv2.imread('image.jpg')
h, w = img.shape[:2]
center = (w // 2, h // 2)
```
2. 在resize函数中指定缩放中心点:
```python
new_size = (200, 200) # 指定新的图像大小
resized_img = cv2.resize(img, new_size, fx=0, fy=0, interpolation=cv2.INTER_LINEAR)
```
在resize函数中,fx和fy参数用于指定水平和垂直方向上的缩放比例,如果这两个参数都为0,则表示以给定的目标大小为准进行缩放。因此,我们可以忽略fx和fy参数,然后指定resize函数的第三个参数为缩放中心点的坐标,即:
```python
resized_img = cv2.resize(img, new_size, center=center, interpolation=cv2.INTER_LINEAR)
```
这样,就可以指定以图像中心为基准进行缩放了。
阅读全文
相关推荐
















