Computer vision — playing with images
2 min readJun 9, 2021
1. Create image by yourself Using Python Code
You can create your own image in computer vision and NumPy
2. Crop some part of image and swapping it and also make a collage of images
Here are some code snippets to give you better idea
import cv2 ,numpy
#original cat image
photo1 = cv2.imread("cat.jpg")
#resized it for ease of use
photo1 = cv2.resize(photo1 , ( 400 ,400 ))
cv2.imshow("Img1",photo1)
if cv2.waitKey() == 13:
pass
cv2.destroyAllWindows()
#original tigers image
photo2 = cv2.imread("tiger.jpg")
photo2 = cv2.resize(photo2 , ( 400 ,400 ))
cv2.imshow("Img1",photo2)
if cv2.waitKey() == 13:
pass
cv2.destroyAllWindows()
#horizontaly added image
himg1 = numpy.hstack((photo1 , photo2))
cv2.imshow("Img1",himg1)
if cv2.waitKey() == 13:
pass
cv2.destroyAllWindows()
#croped cats's face
cimg1 = photo1[45:270, 35:265 , : ]
print(cimg1.shape)
cimg1 = cv2.resize(cimg1 , (255 , 270 ))
cv2.imshow("Img1",cimg1)
if cv2.waitKey() == 13:
pass
cv2.destroyAllWindows()
print(cimg1.shape
#put tigers face on cat's face
finalimg1 = photo1
finalimg1[45:270, 35:265 , : ]= cimg2[:,:,:]
cv2.imshow("Img1",finalimg1)
if cv2.waitKey() == 13:
pass
cv2.destroyAllWindows()
cv2.destroyAllWindows()#put tigers face on cat's face
finalimg2 = photo2
finalimg2[40:310, 90:345 , : ]= cimg1[:,:,:]
cv2.imshow("Img1",finalimg2)
if cv2.waitKey() == 13:
pass
cv2.destroyAllWindows()himg2 = numpy.hstack(( finalimg1 , finalimg2 ))
cv2.imshow("Img1",himg2)
if cv2.waitKey() == 13:
pass
cv2.destroyAllWindows()
Thankyou .