python - 如何将图像放大到特定点 + 缩放后跟踪特定点

标签 python image matlab zooming

<分区>

我想将图像放大到图像中的特定定义点。

此外,图像中有一个边界框,我知道它的 4 个角的坐标。我想在放大图像时跟踪这些点,在缩放图像后,如果边界框仍在缩放图像中,我将在缩放图像中获得边界框 4 个角的坐标。

最佳答案

我建议使用 matplotlib 作为示例

import matplotlib.pyplot as plt
import matplotlib.patches as patches

import numpy as np

f = plt.figure()
ax = f.add_subplot(111)

#create 2d array
t = np.linspace(0, 1, 101)
x, y = np.meshgrid(t, t)
img = np.sin(x-0.5)*np.sin(y-0.5)

ax.imshow(img, origin='lower', extent=[0, 1, 0, 1])
#create a rectangle at positions 0.1, 0.1 with width/height 0.5
#so this would be your bounding box from points (0.1, 0.1), (0.6,0.6) etc
rectangle = patches.Rectangle((0.1, 0.1), 0.5, 0.5, fill=False)
ax.add_patch(rectangle)

plt.show()

print ax.get_xlim()
print ax.get_ylim()

这会在绘图显示后创建以下输出

enter image description here

因此,在 matplotlib 中打开该图后,您可以使用鼠标右键放大该图。如果关闭绘图,程序流程将继续 print ax.get_xlim() 等。 这将为您提供绘图的新限制,您应该能够从中计算新的点位置

我不知道你对 python/matplotlib 有多熟悉,但这应该很简单,否则如果你需要更多解释,请告诉我

关于python - 如何将图像放大到特定点 + 缩放后跟踪特定点,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33758580/

相关文章:

c - 在 SDL 中使用 gimp 导出的 .c/.h 图像

javascript - html5 Canvas 图像不显示或图像未加载

function - Matlab GUI 重用功能 block

Matlab 替换轴范围

python - Filenotfounderror 文件 b'.csv' 不存在

python - 排序后的数据未绘制在正确的数据点中

wpf - MVVM、线程和图像源 DataBinidng

matlab - 如何调整 MATLAB 中的霍夫变换以检测更多线以进行棋盘检测?

Python 类/对象 __str__ 和其他问题

python - python 中的循环外中断错误