2

here is my code

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.

here is the link of document:https://docs.opencv.org/3.0-beta/doc/py_tutorials/py_imgproc/py_gradients/py_gradients.html#gradients

enter image description here

Lê Huy Hùng
  • 265
  • 1
  • 3
  • 7
  • I have an article about `sudoku` recognition. If you can read Chinese, then it may help. https://zhuanlan.zhihu.com/p/30956782 – Kinght 金 Jan 05 '18 at 07:17

1 Answers1

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

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.

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(thresh)
cv2.imshow('sud',laplacian8)

This gave me the result:

Result

check this link to learn more about the problem.

Elia Weiss
  • 8,324
  • 13
  • 70
  • 110
janu777
  • 1,940
  • 11
  • 26