1

I'm using OpenCV 2.4.0 python bindings and I found that when calculating a laplacian of an image I get different results with the cv2 API from the cv2.cv API.

if I use cv2 API:

im_laplacian = cv2.Laplacian(im_gray, cv2.IPL_DEPTH_32F, ksize = 3)

im_laplacian is always uint8 (missing sign), and ddepth has to be IPL_DEPTH_32F or IPL_DEPTH_64F, if I try IPL_DEPTH_16S or IPL_DEPTH_32S I get an error:

"OverflowError: Python int too large to convert to C long"

if I use cv2.cv API:

cvgray = cv.fromarray(im_gray)
im_laplacian2 = cv.CreateImage(cv.GetSize(cvgray), cv.IPL_DEPTH_16S, 1)        
cv.Laplace(cvgray, im_laplacian2, 3)

as expected I get a signed laplacian, this is the same result as in the C++ API. If I do:

im_laplacian2_scaled = cv.CreateImage(cv.GetSize(cvgray), 8, 1) 
cv.ConvertScaleAbs(dst, im_laplacian2_scaled, 1, 0)

im_laplacian2_scaled is still different from im_laplacian calculated with cv2 API

In my particular case I think I can get away with the cv2 output, but I'm puzzeled, shouldn't all APIs produce the same output? do they use different algorithms? or maybe the cv2 python bindings don't correspond to individual C++ functions but some combination of them?

martinako
  • 2,690
  • 1
  • 25
  • 44

1 Answers1

3

New cv2 API uses different depth constants:

  • cv2.CV_64F instead of cv2.IPL_DEPTH_64F
  • cv2.CV_32F instead of cv2.IPL_DEPTH_32F
  • cv2.CV_32S instead of cv2.IPL_DEPTH_32S
  • cv2.CV_16S instead of cv2.IPL_DEPTH_16S
  • cv2.CV_16U instead of cv2.IPL_DEPTH_16U
  • cv2.CV_8S instead of cv2.IPL_DEPTH_8S
  • cv2.CV_8U instead of cv2.IPL_DEPTH_8U
Andrey Kamaev
  • 29,582
  • 6
  • 94
  • 88
  • Alright! I see what happened. using a ddepth cv2.IPL_DEPTH_32F in the cv2 API produces the same effect as using cv2.CV_8U and that's the result I was getting. Much simpler answer that I thought :-P I still wonder why the IPL_DEPTH_xxx constants are around in the cv2 API, they come out in the autocompletion, maybe for compatibility reasons? Thanks for your answer Andrey. – martinako Jul 04 '12 at 16:54