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.