opencv Laplacian函数无法像文档中那样有效地工作 [英] opencv Laplacian function not work effectively like in document

查看:91
本文介绍了opencv Laplacian函数无法像文档中那样有效地工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的代码

img_original=cv2.imread("sudoku-original.jpg",0)
cv2.imshow("original",img_original)
laplacian = cv2.Laplacian(img_original,cv2.CV_64F)
cv2.imshow("laplace",laplacian)

我想要类似文档中的结果,但不需要.

I want result like in the document but It don't.

这是文档的链接: https://docs.opencv.org/3.0-beta/doc/py_tutorials/py_imgproc/py_gradients/py_gradients.html#gradients

推荐答案

laplacian = cv2.Laplacian(img_original,cv2.CV_64F)

以上行表示图像的格式为CV_64F,它是浮点值的数组.因此,当您使用cv2.imshow()函数时,它的工作方式类似于:大于1.0的值为白色像素,小于0.0的值为黑色.

The above line implies that the format of the image is CV_64F which is an array of float values. So when you use cv2.imshow() function, it works in a way like: values greater than 1.0 will be white pixels and values lesser than 0.0 will be black.

因此,您需要将其转换为CV_8U.有很多方法可以做到 我通常使用这个:

So you will need to convert it to CV_8U. There are many ways to do it, I generally use this:

laplacian = cv2.Laplacian(img,cv2.CV_64F)
ret,thresh = cv2.threshold(laplacian,0,255.0,cv2.THRESH_TOZERO)
laplacian8 = np.uint8(laplacian)
cv2.imshow('sud',laplacian8)

这给了我结果:

选中链接以了解有关此问题的更多信息.

check this link to learn more about the problem.

这篇关于opencv Laplacian函数无法像文档中那样有效地工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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