opencv 2.4.0 laplacian 根据使用的 API 产生不同的结果? [英] opencv 2.4.0 laplacian different results depending on API used?

查看:78
本文介绍了opencv 2.4.0 laplacian 根据使用的 API 产生不同的结果?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 OpenCV 2.4.0 python 绑定,我发现在计算图像的拉普拉斯算子时,我从 cv2.cv API 得到了不同的结果.

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.

如果我使用 cv2 API:

if I use cv2 API:

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

im_laplacian 总是 uint8(缺少符号),并且 ddepth 必须是 IPL_DEPTH_32F 或 IPL_DEPTH_64F,如果我尝试 IPL_DEPTH_16S 或 IPL_DEPTH_32S 我得到一个错误:

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:

溢出错误:Python int 太大而无法转换为 C long"

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

如果我使用 cv2.cv API:

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)

正如预期的那样,我得到了一个带符号的拉普拉斯算子,这与 C++ API 中的结果相同.如果我这样做:

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 与使用 cv2 API 计算的 im_laplacian 还是有区别的

im_laplacian2_scaled is still different from im_laplacian calculated with cv2 API

在我的特殊情况下,我认为我可以摆脱 cv2 输出,但我很困惑,难道不是所有的 API 都应该产生相同的输出吗?他们使用不同的算法吗?或者也许 cv2 python 绑定不对应于单独的 C++ 函数,而是它们的某种组合?

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?

推荐答案

New cv2 API 使用不同的深度常量:

New cv2 API uses different depth constants:

  • cv2.CV_64F 而不是 cv2.IPL_DEPTH_64F
  • cv2.CV_32F 而不是 cv2.IPL_DEPTH_32F
  • cv2.CV_32S 而不是 cv2.IPL_DEPTH_32S
  • cv2.CV_16S 而不是 cv2.IPL_DEPTH_16S
  • cv2.CV_16U 而不是 cv2.IPL_DEPTH_16U
  • cv2.CV_8S 而不是 cv2.IPL_DEPTH_8S
  • cv2.CV_8U 而不是 cv2.IPL_DEPTH_8U
  • 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

这篇关于opencv 2.4.0 laplacian 根据使用的 API 产生不同的结果?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆