简体   繁体   English

如何使用opencv python从底部裁剪图像

[英]How to crop the image from bottom using opencv python

I am trying to divide the image into two 1) till bottom text one image 2) from text till end another image.我试图将图像分成两个 1) 直到底部文本一个图像 2) 从文本直到另一个图像结束。

I have no clue where to start off with, gone through few answers but still confused.我不知道从哪里开始,经历了几个答案,但仍然感到困惑。

请找到原图

After cropping i want it in a way like裁剪后我想要它的方式像

最佳

The below image is separated下图是分开的

底部一

You could simply create 2 subimages based on pixel values.您可以简单地根据像素值创建 2 个子图像。

You can do this with subimage = image[Y_start : Y_end, X_start : X_end] .你可以用subimage = image[Y_start : Y_end, X_start : X_end]做到这一点。

The code below gives this result:下面的代码给出了这个结果:

在此处输入图片说明

# load image
img = cv2.imread("map.png")

# create sub images
img_map = img[0:600, 0:600]
img_legend = img[600:705, 0:600]

#show images - to save the images, uncomment the lines below.
cv2.imshow("map", img_map)
cv2.imshow("legend", img_legend)
# cv2.imwrite('map_only.png',img_map)
# cv2.imwrite('legend_only.png',img_legend)
cv2.waitKey(0)
cv2.destroyAllWindows()  

you can define a crop margin based on pixels and assign it to a new variable:您可以根据像素定义裁剪边距并将其分配给新变量:

src_img = cv2.imread(image_file)


crop_img = src_img[h_start : h_end, w_start : w_end]

cv2.imshow("original", src_img )
cv2.imshow("cropped", crop_img)

cv2.waitKey(0)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM