Ask Your Question
0

How to call integral() in python directly ?

asked May 3 '18

PengGuanjun gravatar image

updated May 3 '18

I use integral() in the link, but I don't get the correct integral image.

My code is the following:

import cv2
snap = cv2.imread("image.png")
global sum
imageIntegral =   cv2.integral( snap, sum ,-1 )
imshow("Integral Image",imageIntegral);  
waitKey();

Error message:

Blockquote Traceback (most recent call last): File "C:/Users/MaiBenBen/Desktop/FASeg.py", line 6, in <module> imageIntegral = cv2.integral( snap, sum ,-1 ) TypeError: sum is not a numpy array, neither a scalar

Preview: (hide)

Comments

I've been looking for a long time and still haven't found an example of python calling integral(). This link is more detailed but it has no effect.

PengGuanjun gravatar imagePengGuanjun (May 3 '18)edit

1 answer

Sort by » oldest newest most voted
1

answered May 3 '18

phillity gravatar image
import cv2
import numpy as np

snap = np.ones((3,3),dtype='uint8')
print(snap)

intergral_image = cv2.integral( snap )
print(intergral_image)

# if you dont want the top row/left column pad
intergral_image = intergral_image[1:,1:]
print(intergral_image)

#OUTPUT:
[[1 1 1]
 [1 1 1]
 [1 1 1]]
[[0 0 0 0]
 [0 1 2 3]
 [0 2 4 6]
 [0 3 6 9]]
[[1 2 3]
 [2 4 6]
 [3 6 9]]
Preview: (hide)

Comments

1

thanks a lot. If it is a picture, the following code is also valid

import cv2  
import numpy as np  

image = cv2.imread("image.png")  
rows,cols,dims=image.shape  

sum = np.zeros((rows,cols),np.int32)  
imageIntegral = cv2.integral(image, sum,-1)  
cv2.imshow("Integral Image",imageIntegral);    
waitKey();
PengGuanjun gravatar imagePengGuanjun (May 3 '18)edit

Question Tools

1 follower

Stats

Asked: May 3 '18

Seen: 4,149 times

Last updated: May 02 '18