A difference can be negative or positive.

For some number types, such as uint8 (unsigned 8-bit int), which can't be negative (have no sign), a negative value wraps around and the value would make no sense anymore. Other types can be signed (e.g. floats, signed ints), so a negative value can be represented correctly.

That's why cv.absdiff exists. It always gives you absolute differences, and those are okay to represent in an unsigned type.

Example with numbers: a = 4, b = 6. a-b should be -2, right?

That value, as an uint8, will wrap around to become 0xFE, or 254 in decimal. The 254 value has some relation to the true -2 difference, but it also incorporates the range of values of the data type (8 bits: 256 values), so it's really just "code".

cv.absdiff would give you the absolute of the difference (-2), which is 2.

Answer from Christoph Rackwitz on Stack Overflow
🌐
Shimat
shimat.github.io › opencvsharp_docs › html › 6c7cefd1-59bc-a595-fe2a-0c8a709f8d16.htm
Cv2.Absdiff Method
Namespace: OpenCvSharp Assembly: OpenCvSharp (in OpenCvSharp.dll) Version: 1.0.0 · Syntax · C# VB · C++ F# Copy · public static void Absdiff( InputArray src1, InputArray src2, OutputArray dst ) Public Shared Sub Absdiff ( src1 As InputArray, src2 As InputArray, dst As OutputArray ) public: static void Absdiff( InputArray^ src1, InputArray^ src2, OutputArray^ dst ) static member Absdiff : src1 : InputArray * src2 : InputArray * dst : OutputArray -> unit ·
🌐
OpenCV
docs.opencv.org › 4.13.0 › d2 › de8 › group__core__array.html
OpenCV: Operations on arrays
The function cv::absdiff calculates: Absolute difference between two arrays when they have the same size and type:
🌐
Rust
docs.rs › opencv › latest › opencv › cudaarithm › fn.absdiff.html
absdiff in opencv::cudaarithm - Rust
opencv:: cudaarithm · Source · pub fn absdiff( src1: &impl ToInputArray, src2: &impl ToInputArray, dst: &mut impl ToOutputArray, stream: &mut impl StreamTrait, ) -> Result<()> Expand description · Computes per-element absolute difference of two matrices (or of a matrix and scalar).
🌐
YouTube
youtube.com › watch
OPENCV & C++ TUTORIALS - 75 | absdiff() | Difference Between Two Images - YouTube
absdiff function siply gives us the absolute difference of each coordinate's pixel values of two images. The math behind the function is very simple however ...
Published: January 19, 2023
🌐
Openlvvision
openlvvision.org › home › opencv › core functionality › arithmetic operations › absdiff
AbsDiff | OpenLvVision
Calculates the per-element absolute difference between two arrays or between an array and a scalar.
🌐
OpenCV
forum.opencv.org › uncategorized
AbsDiff vs BitwiseXor? - Uncategorized - OpenCV
May 8, 2021 - I have been using the bitwiseXor so far to calculate the differences between layers. Now i noticed that opencv have a AbsDiff which perform the absolute difference. I run a simple test and noticed that the output is the same as using the bitwiseXor ...
🌐
OpenCV
docs.opencv.org › 4.x › d0 › d86 › group__gapi__matrixop.html
OpenCV: Graph API: Operations on matrices
The function absDiff calculates absolute difference between two matrices of the same size and depth:
Find elsewhere
🌐
OpenCV
docs.opencv.org › 4.x › d8 › d34 › group__cudaarithm__elem.html
OpenCV: Per-element Operations
In python both src1 and src2 have to be matrices, see absdiffWithScalar for scalar overload.
🌐
GitHub
gist.github.com › gonzalo123 › df3e43477f8627ecd1494d138eae03ae
compare images with opencv · GitHub
Also, add your output folder path here: cv2.imwrite("images/absdiff.png", absdiff) cv2.imwrite("images/diff.png", diff)
🌐
Huihoo
docs.huihoo.com › opencv › 2.4-documentation › modules › core › doc › operations_on_arrays.html
Operations on Arrays — OpenCV 2.4.13.2 documentation
OpenCV API Reference » · core. The Core Functionality » · Calculates an absolute value of each matrix element. C++: MatExpr abs(const Mat& m)¶ · C++: MatExpr abs(const MatExpr& e)¶ · abs is a meta-function that is expanded to one of absdiff() or convertScaleAbs() forms: C = abs(A-B) ...
🌐
YouTube
youtube.com › watch
Night Motion Detection Using Python & OpenCV || cv2.absdiff - YouTube
#okaydexter #nightdetection #motion #opencv #demo #tutorials #pythonNight Motion Detection Using Python & OpenCV || cv2.absdiffIn this video tutorial we'll b...
Published: January 19, 2020
🌐
Blogger
opencv-tutorials-hub.blogspot.com
OpenCV C++ Tutorial And Examples
Here is the OpenCv C++ Example on Operation on Arrays by using absdiff() It calculates the per-element absolute difference between two arrays or between an array and a scalar.
🌐
Medium
medium.com › @saairaamprasad › opencv-in-python-image-processing-part-10-10-6882b85507d0
OpenCV in Python: Image Processing Part 10/10 | by Saairaamprasad | Medium
October 11, 2024 - Didn't see that coming.") # Read the first two frames ret, frame1 = cap.read() ret, frame2 = cap.read() while cap.isOpened(): # Calculate the absolute difference between the two frames diff = cv2.absdiff(frame1, frame2) # Convert the difference to grayscale (because color is too mainstream) gray = cv2.cvtColor(diff, cv2.COLOR_BGR2GRAY) # Blur the image to reduce noise (and details, who needs those?) blur = cv2.GaussianBlur(gray, (5, 5), 0) # Apply thresholding to binarize the image _, thresh = cv2.threshold(blur, 20, 255, cv2.THRESH_BINARY) # Dilate the thresholded image to fill in holes (the