resized = cv2.resize(src , dsize , fx, fy , interpolation)- src -> is the original image.
- dsize -> new dimensions in pixels (width , height) format
- fx , fy -> scale factors
- interpolation -> to control quality
(Slicing)
cropped = image[startY:endY, startX:endx]- Y -> rows : top to down
- X -> cols : left to right
(Rotation , Flipping)
-
M = cv2.getRotationMatrix2D(center , angle, scale) -
rotated_img = cv2.warpAffine(image , M , (width , height))-
.getRotationMatrix2D -> creates a matrix with parameters according to which rotation will take place for an image
-
center -> coordinates from where we need to rotate ( usually we find center with the help of width // 2 and height // 2)
-
angle -> in degrees how much to rotate (90 : counter clockwise ; -90 : clockwise)
-
scale -> how much to zoom in or zoom out during rotation (1 : full , 0.5 : half , 2 : double)
-
.warpAffine -> will be used to apply the parameters we set through M
-
-
flipped = cv2.flip(image , flipcode)- .flip -> direct function to flip the image
- flipcode -> (0 : vertically {top - bottom} , 1 : horizontally {left - right} , -1 : both horizontal and vertical )
(Lines Circles Rectangles)
Line cv2.line(img , pt1 , pt2 ,color , thickness)
- pt1 , pt2 -> coordinates in the format of (width , height) for both pt1 and pt2
Rectangle cv2.rectangle(img , pt1 , pt2 , color , thickness)
- pt1 -> top left corner
- pt2 -> bottom right corner
Circle cv2.circle(img , center , radius , color , thickness)
- center -> will be the coordinates to draw circle around of.
- radius -> size of circle
Note : "thickness = -1 will fill the shape chosen"
(Text Placement, Font Selection)
-> Used for custom labelling like to add text on the image.
cv2.putText(img , text , org , font , fontScale , color , thickness)
- text -> what we want to write on the image.
- org -> bottom left corner of the text
- font -> font type (font family) { cv2.FONTFAMILY }
- fontScale -> text size (1 : Normal , 2 : Big)