Skip to Content
Mastering OpenCV 4 with Python
book

Mastering OpenCV 4 with Python

by Alberto Fernández Villán
March 2019
Intermediate to advanced
532 pages
13h 2m
English
Packt Publishing
Content preview from Mastering OpenCV 4 with Python

Translating an image

In order to translate an object, you need to create the 2 x 3 transformation matrix by using the NumPy array with float values providing the translation in both the x and y directions in pixels, as shown in the following code:

M = np.float32([[1, 0, x], [0, 1, y]])

This gives the following M transformation matrix:

Once this matrix has been created, the cv2.warpAffine() function is called, as shown in the following code:

dst_image = cv2.warpAffine(image, M, (width, height))

The cv2.warpAffine() function transforms the source image using the M matrix provided. The third (width, height) argument establishes the size of the ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

OpenCV 4 with Python Blueprints - Second Edition

OpenCV 4 with Python Blueprints - Second Edition

Dr. Menua Gevorgyan, Michael Beyeler (USD), Arsen Mamikonyan, Michael Beyeler
Learning OpenCV 3

Learning OpenCV 3

Adrian Kaehler, Gary Bradski
Machine Learning for OpenCV 4 - Second Edition

Machine Learning for OpenCV 4 - Second Edition

Aditya Sharma, Michael Beyeler (USD), Vishwesh Ravi Shrimali, Michael Beyeler

Publisher Resources

ISBN: 9781789344912Supplemental Content