0

I am a newbie working on image processing with OpenCV. I'm trying to find perfect coordinates for a 9x9 sudoku board shape.

I've worked on the code to the best of my knowledge, but I'm getting an error and I don't know how to go about it.

Below is what I get so far:

import cv2
import numpy as np

im = cv2.imread("sudoku0.png")
gray = cv2.cvtColor(im,cv2.COLOR_BGR2GRAY);
gray = cv2.GaussianBlur(gray, (5, 5), 0)
_, bin = cv2.threshold(gray,120,255,1) # inverted threshold (light obj on dark bg)
bin = cv2.dilate(bin, None)  # fill some holes
bin = cv2.dilate(bin, None)
bin = cv2.erode(bin, None)   # dilate made our shape larger, revert that
bin = cv2.erode(bin, None)
bin, contours, hierarchy = cv2.findContours(bin, cv2.RETR_LIST, cv2.CHAIN_APPROX_SIMPLE)

rc = cv2.minAreaRect(contours[0])
box = cv2.boxPoints(rc)
for p in box:
    pt = (p[0],p[1])
    print (pt)
    cv2.circle(im,pt,5,(200,0,0),2)
cv2.imshow("plank", im)
cv2.waitKey()

The error from the above code came from this:

bin, contours, hierarchy = cv2.findContours(bin, cv2.RETR_LIST, cv2.CHAIN_APPROX_SIMPLE)

After running the code, this is what I got:

not enough values to unpack (expected 3, got 2)

Can someone please help me and explain what I'm missing?

Thanks

Eniola
  • 133
  • 10
  • You are probably using OpenCV 4, use `contours, hierarchy = cv2.findContours(bin, cv2.RETR_LIST, cv2.CHAIN_APPROX_SIMPLE)`. For backward compatibility you may use: `contours, hierarchy = cv2.findContours(bin, cv2.RETR_LIST, cv2.CHAIN_APPROX_SIMPLE)[-2:]`. See the following [post](https://stackoverflow.com/questions/48291581/how-to-use-cv2-findcontours-in-different-opencv-versions). – Rotem Mar 31 '20 at 19:20
  • Check also this: https://stackoverflow.com/questions/10196198/how-to-remove-convexity-defects-in-a-sudoku-square – Andrey Smorodov Apr 01 '20 at 08:09

0 Answers0