Basic geometric transformations – OpenCV 3.4 with python 3 Tutorial 12
[python]
import cv2
import numpy as np
img = cv2.imread("red_panda.jpg")
rows, cols, ch = img.shape
print("Height: ", rows)
print("Width: ", cols)
scaled_img = cv2.resize(img, None, fx=1/2, fy=1/2)
matrix_t = np.float32([[1, 0, -100], [0, 1, -30]])
translated_img = cv2.warpAffine(img, matrix_t, (cols, rows))
matrix_r = cv2.getRotationMatrix2D((cols/2, rows/2), 90, 0.5)
rotated_img = cv2.warpAffine(img, matrix_r, (cols, rows))
cv2.imshow("Original image", img)
cv2.imshow("Scaled image", scaled_img)
cv2.imshow("Translated image", translated_img)
cv2.imshow("Rotated image", rotated_img)
cv2.waitKey(0)
cv2.destroyAllWindows()
[/python]
Files:
4 Comments
Leave a Reply Cancel reply
This site uses Akismet to reduce spam. Learn how your comment data is processed.
Opencv Beginner Tutorial
- 1) Loading images
- 2) Loading Video and Webcam
- 3) Drawing and writing on images
- 4) Basic operations on images
- 5) Add images and Threshold
- 6) Blending images
- 7) Bitwise Operators
- 8) Trackbars
- 9) Object detection using HSV Color space
- 10) Basic Thresholding
- 11) Histograms
- 12) Basic geometric transformations
- 13) Perspective transformation
- 14) Affine transformation
- 15) Adaptive thresholding5
- 16) Smoothing images
- 17) Morphological transformation
- 18) Edge detection
- 19) Find and Draw Contours
- 20) Template matching
- 21) Lines detection with Hough Transform
- 22) Corners detection
- 23) Image Pyramids
- 24) Image Pyramids (Blending and reconstruction)
- 25) Feature detection (SIFT, SURF, ORB)
- 26) Feature Matching (Brute-Force)
- 27) Mouse Events
- 28) Histogram and Back Projection
- 29) Object tracking with Mean-shift
- 30) Object tracking with Camshift
- 31) Optical Flow with Lucas-Kanade method
- 32) Background Subtraction
- 33) k-Nearest Neighbour classification
- 34) Object tracking using Homography
- 35) Fourier Transform
- 36) Knn handwritten digits recognition
- 37) Face detection using Haar Cascades
Most Read:
-
Train YOLO to detect a custom object (online with free GPU)
-
YOLO object detection using Opencv with Python
-
Detecting colors (Hsv Color Space) – Opencv with Python
-
How to install Python 3 and Opencv 4 on Windows
-
Check if two images are equal with Opencv and Python
-
How to install Dlib for Python 3 on Windows
-
Feature detection (SIFT, SURF, ORB) – OpenCV 3.4 with python 3 Tutorial 25
-
Eye motion tracking – Opencv with Python
hi sergio
my name ist mustafa im a student in germany and i have projekt with opencv. I saw your Tutorial 12 and would like to ask you how i can do the same with cv2.videocapture(0) .
i would appreciate it if you could help me with this.
Hi Mustafa,
it’s easy. It works in the same way but inside a loop, as for a video you need to process frame by frame.
Here is the code for a video:
[python]
import cv2
import numpy as np
cap = cv2.VideoCapture(0)
# Git first frame to take the size of frame
_, frame = cap.read()
rows, cols, ch = frame.shape
print("Height: ", rows)
print("Width: ", cols)
while True:
_, frame = cap.read()
scaled_img = cv2.resize(frame, None, fx=1 / 2, fy=1 / 2)
matrix_t = np.float32([[1, 0, -100], [0, 1, -30]])
translated_img = cv2.warpAffine(frame, matrix_t, (cols, rows))
matrix_r = cv2.getRotationMatrix2D((cols / 2, rows / 2), 90, 0.5)
rotated_img = cv2.warpAffine(frame, matrix_r, (cols, rows))
cv2.imshow("Original image", frame)
cv2.imshow("Scaled image", scaled_img)
cv2.imshow("Translated image", translated_img)
cv2.imshow("Rotated image", rotated_img)
key = cv2.waitKey(1)
if key == 27:
break
cap.release()
cv2.destroyAllWindows()
[/python]
Hi,
part of my final project to software engineer study we need to calculate Plant area.
we need to take photo of the plant each day, and calculate the area to check the Growth of the Plant.
do you have ant solution for me please..?
Thanks.
Hi Hanan, it seems a simple task to achieve.
You could create a mask by the color of the plant (you can see here how https://www.youtube.com/watch?v=SJCu1d4xakQ) and then calculate the area of the white part in the mask.