所以我有一个800 x 600的图像,我想用OpenCV 3.1.0垂直切割成两张大小相同的图片。这意味着在剪切结束时,我应该有两个图像,每个图像为400 x 600,并存储在自己的PIL变量中。
这是一个例子:
谢谢。
编辑:我想要最有效的解决方案,所以如果该解决方案使用numpy拼接或类似的东西,那么去吧。
您可以尝试以下代码,它将创建两个numpy.ndarray
实例,您可以轻松地显示或写入新文件。
from scipy import misc
# Read the image
img = misc.imread("face.png")
height, width = img.shape
# Cut the image in half
width_cutoff = width // 2
s1 = img[:, :width_cutoff]
s2 = img[:, width_cutoff:]
# Save each half
misc.imsave("face1.png", s1)
misc.imsave("face2.png", s2)
face.png
文件是一个示例,需要替换为您自己的图像文件。