简体   繁体   中英

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.

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.

You can do this with 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)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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