Skip to main content

Take 2 images, crop some part of both the images and swap them

 



Libraries Required for this 

1.numpy

2.Matplotlib

3.opencv

Taking input from the user using

img1 = cv2.imread("imageone.jpg")
img2 = cv2.imread("imagetwo.png")

Converting both the images into RGB format from BGR

img1 = cv2.cvtColor(img1,cv2.COLOR_BGR2RGB)

Showing image using Matplotlib

plt.imshow(imagename)

Make sure that both the images are of same sizes to add them together one can check the shape of the image and confirm whether both image has same size

using
imgname.shape

return (x,y,[RGB])


Cropping the image


cropimg1 = img1[1000:1700 , 400:1300]
plt.imshow(cropimg1)


Resizing the image


cropimg1= cv2.resize(cropimg1,(900,400))
cropimg2= cv2.resize(cropimg2,(900,700))


Swapping the Two part


img1[1000:1700 , 400:1300] = cropimg2
plt.imshow(img1)


Concatenating the hstack

newimg = np.hstack((img1,img2))

Comments

Popular posts from this blog

Detailed Analysis on Arduino UNO R3

Arduino UNO R3 Arduino Uno is a microcontroller board based on ATmega328P . It has 14 digital input/output pins 6 Analog pins a 16 MHz quartz crystal oscillator with USB connection ,a power jack , an ICSP(In-Circuit Serial programming) header and a reset button actually it has two reset buttons . Also Arduino uno has RX-0,TX-1 that is receiving and transmitting pins on board. Arduino uno contains  AREF pin which means Analogue-Reference IOREF pin this pin is provides a voltage  reference at which the microcontrller works 3-ground pins 3-Vcc pins Basically the purpose of creating an Arduino Uno is to Control the sensors and the actuators so that it can work accordingly the data which we provide with the help of software . Nowadays people using Arduino Uno in many fields it has very huge scope in  the field of  IOT(Internet Of Things). Also in my current project which is 2D-printer we have used Arduino Uno which sense the Data and accordingly move the X-Y pla

7 some Intersesting commands in espeak-ng linux

  In This Blog we learn how to perform espeak commands inside the red hat enterprise linux What is espeak-ng? eSpeakNG is a compact, open-source, software speech synthesizer for Linux, Windows, and other platforms. It uses a formant synthesis method, providing many languages in a small size. Much of the programming for eSpeakNG's language support is done using rule files with feedback from native speakers.

What are the differences between StaticJsonBuffer and DynamicJsonBuffer?

   StaticJsonBuffer ArduinoJson  uses preallocated memory to store the data and this is possible due to StaticJsonBuffer. If one has to use this library then firstly they should create t he StaticJsonBuffer just like: StaticJsonBuffer<200> jsonBuffer; then it creates an  memory of 200 byte size which creates allocated memory in the system for storing the data static as the name tells it has fixed in size type of memory.Also we cannot reuse the memory once it gets allocated.it has high speed performance. DynamicJsonBuffer This library supports DynamicJsonBuffer since it has parameters for dynamic memory allocation but it will be more useful if we use this buffer in the machine having memory more than 10KB of RAM. to use this syntax is just similar. DynamicJsonBuffer jsonBuffer; This will create one dynamic memory for the system so that it can allocate it more precisely.its size is variable it stores the data in heap.while storing it take time and its somehow process slow