Advertisement
Guest User

Untitled

a guest
Aug 17th, 2017
45
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.29 KB | None | 0 0
  1. import cv2
  2. import numpy as np
  3. img = cv2.imread("your_image.jpg")
  4. x,y=img.shape[:2]
  5. ma=max(x,y)
  6. blank = np.zeros((ma,ma,3), np.uint8)
  7. if y>x:
  8. blank[(y-x)/2:(y-x)/2+x,0:y]=img
  9. if x>y:
  10. blank[0:x,(x-y)/2:(x-y)/2+y]=img
  11. cv2.imshow('result', blank)
  12. cv2.imwrite("result.jpg",blank)
  13. cv2.waitKey(0)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement