如何将图像垂直切割成两个相等大小的图像

Hal*_*alp 6 python opencv numpy image-resizing opencv3.1

所以我有一个800 x 600的图像,我想用OpenCV 3.1.0垂直切割成两张大小相同的图片.这意味着在剪切结束时,我应该有两个图像,每个图像为400 x 600,并存储在自己的PIL变量中.

这是一个例子:

纸被切成两半

谢谢.

编辑:我想要最有效的解决方案,所以如果该解决方案使用numpy拼接或类似的东西,那么去吧.

fsi*_*vic 6

您可以尝试以下代码,该代码将创建两个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)
Run Code Online (Sandbox Code Playgroud)

face.png文件是一个示例,需要替换为您自己的图像文件.