Opencv cv2.absdiff (img1, img2) .sum () without a temporary img

Is it possible to compute cv2.absdiff (img1, img2) .sum () without a temporary img?

I have a video stream and I need some kind of image stabilization at the beginning of my processing. Abspiy gives a fast and error-dependent result of checking different placement vectors with the following two images, but I need to create, write and read a temporary image that is used only for calculating img.sum (). Therefore, it would be great to eliminate these operations of memory allocation, writing and reading.

def calcMatch(img1, img2): diff = cv2.absdiff(img1, img2) return diff.sum() 

Python solution

 import cv2 import time img = cv2.imread('test.jpg') img = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY) img1 = img[10:330, 10:870] img2 = img[20:340, 20:880] start = time.clock() d = cv2.absdiff(img1, img2) s = d.sum() t = time.clock() - start print 'with absdiff ', t print s start = time.clock() s = cv2.norm(img1, img2, cv2.NORM_L1) t = time.clock() - start print 'with norm L1 ', t print s 

This greatly speeds up work on my laptop with a very stable ratio:
with absdiff 0.00207574457822
4315120
with norm L1 0.000226647018223
4,315,120.0

+4
source share
1 answer

Try norm with norm NORM_L1 . C ++ Code:

 double res = cv::norm(img1, img2, cv::NORM_L1); 
+5
source

Source: https://habr.com/ru/post/1493142/


All Articles