<分区>
我想将图像放大到图像中的特定定义点。
此外,图像中有一个边界框,我知道它的 4 个角的坐标。我想在放大图像时跟踪这些点,在缩放图像后,如果边界框仍在缩放图像中,我将在缩放图像中获得边界框 4 个角的坐标。
<分区>
我想将图像放大到图像中的特定定义点。
此外,图像中有一个边界框,我知道它的 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()
这会在绘图显示后创建以下输出
因此,在 matplotlib 中打开该图后,您可以使用鼠标右键放大该图。如果关闭绘图,程序流程将继续 print ax.get_xlim()
等。
这将为您提供绘图的新限制,您应该能够从中计算新的点位置
我不知道你对 python/matplotlib 有多熟悉,但这应该很简单,否则如果你需要更多解释,请告诉我
关于python - 如何将图像放大到特定点 + 缩放后跟踪特定点,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33758580/