Skip to content

Beginners Opencv · Tutorials

Basic geometric transformations – OpenCV 3.4 with python 3 Tutorial 12

Access community, courses and source codes
Logo

AI Vision Academy

Access the code of this tutorial, computer vision courses and an exclusive community on AI Vision Academy

  • Access to over 50+ source codes from Pysource.com/blog
  • Dedicated video courses about computer vision
  • Access to an exclusive community of professionals
  • Real-World AI Projects – Get hands-on experience building practical AI Computer Vision solutions with a structured path.
  • Monthly Coaching Calls – get support and any of your questions answered

Subscribe to our newsletter to learn more

4 comments

  1. 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.

    1. 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]

  2. 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.

Join the discussion