

rotatedImage = cv2.warpAffine(img, rotationMatrix, (width, height)) To rotate the image, we have a cv2 method named wrapAffine which takes the original image, the rotation matrix of the image and the width and height of the image as arguments. The next step is to rotate our image with the help of the rotation matrix.
#Simpleimage has no attribute read code#
To get the rotation matrix of our image, the code will be: rotationMatrix = cv2.getRotationMatrix2D((width/2, height/2), 90. Here the center is the center point of rotation, the angle is the angle in degrees and scale is the scale property which makes the image fit on the screen. The syntax of getRotationMatrix2D() is: cv2.getRotationMatrix2D(center, angle, scale) To get the rotation matrix, we use the getRotationMatrix2D() method of cv2. Okay, now we have our image matrix and we want to get the rotation matrix. The shape attribute returns the height and width of the image matrix. To rotate this image, you need the width and the height of the image because you will use them in the rotation process as you will see later. Here we set the time to zero to show the window forever until we close it manually. The waitkey functions take time as an argument in milliseconds as a delay for the window to close. To display the image, you can use the imshow() method of cv2. All the time you are working with a NumPy array. It’s a NumPy array! That why image processing using OpenCV is so easy. The image is now treated as a matrix with rows and columns values stored in img.Īctually, if you check the type of the img, it will give you the following result: >print(type(img)) Now to read the image, use the imread() method of the cv2 module, specify the path to the image in the arguments and store the image in a variable as below: img = cv2.imread("pyimg.jpg") Let’s have some fun with some images!įirst of all, import the cv2 module.

Now OpenCV is installed successfully and we are ready.
#Simpleimage has no attribute read install#
To install OpenCV on your system, run the following pip command: pip install opencv-python
