Created
March 15, 2019 05:58
-
-
Save ChongyeWang/cfd473cdb9757271e5f14c7bde347f3b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import cv2 | |
import numpy as np | |
image = cv2.imread('images/input.jpg') | |
height, width = image.shape[:2] | |
# Let's get the starting pixel coordiantes (top left of cropping rectangle) | |
start_row, start_col = int(height * .25), int(width * .25) | |
# Let's get the ending pixel coordinates (bottom right) | |
end_row, end_col = int(height * .75), int(width * .75) | |
# Simply use indexing to crop out the rectangle we desire | |
cropped = image[start_row:end_row , start_col:end_col] | |
cv2.imshow("Original Image", image) | |
cv2.waitKey(0) | |
cv2.imshow("Cropped Image", cropped) | |
cv2.waitKey(0) | |
cv2.destroyAllWindows() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment