Ask Your Question
0

How to call integral() in python directly ?

asked 2018-05-02 20:48:48 -0600

PengGuanjun gravatar image

updated 2018-05-02 22:13:06 -0600

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

edit retag flag offensive close merge delete

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 ( 2018-05-02 22:09:35 -0600 )edit

1 answer

Sort by ยป oldest newest most voted
1

answered 2018-05-02 23:37:39 -0600

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]]
edit flag offensive delete link more

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 ( 2018-05-03 01:15:27 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2018-05-02 20:48:48 -0600

Seen: 3,790 times

Last updated: May 02 '18