opencv 2.4.0 laplacian different results depending on API used?

好久不见. 提交于 2021-02-07 10:28:17

问题


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?


回答1:


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


来源:https://stackoverflow.com/questions/11331830/opencv-2-4-0-laplacian-different-results-depending-on-api-used

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!