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

Bitwise operations

There are some operations that can be performed at bit level using bitwise operators, which can be used to manipulate the values for comparison and calculations. These bitwise operations are simple, and are quick to calculate. This means that they are a useful tool when working on images.

Bitwise operations include AND, OR, NOT, and XOR.

  • Bitwise AND: bitwise_and = cv2.bitwise_and(img_1, img_2)
  • Bitwise OR: bitwise_xor = cv2.bitwise_xor(img_1, img_2)
  • Bitwise XOR: bitwise_xor = cv2.bitwise_xor(img_1, img_2)
  • Bitwise NOT: bitwise_not_1 = cv2.bitwise_not(img_1)

In order to explain how these operations work, look at the output of the bitwise_operations.py script in the following screenshot:

In order to play with bitwise ...

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