im writing a python script that takes in a video input and should find the centres of a tick tack toe board. As of right now i was able to find the countours of the board, but i dont know how to move forward in regard to finding the centre of each little box. Here’s the code:
import numpy as np
import cv2
video = cv2.VideoCapture(0)
while 1:
ret, frame = video.read()
gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
blur = cv2.medianBlur(gray, 3)
thresh = cv2.adaptiveThreshold(blur, 255, 1, 1, 11, 2)
contours, _ = cv2.findContours(thresh, cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE)
c = 0
for i in contours:
area = cv2.contourArea(i)
if area > 200:
cv2.drawContours(frame, contours, c, (0, 255, 0), 3)
c+=1
cv2.imshow("frame", frame)
if cv2.waitKey(1) & 0xFF == ord('q'):
break
and heres the frames that im getting:

>Solution :
I don’t think this is the right approach, since the tick-tack-toe board lines are connected, we will most likely always end up with a single large contour. To make things simple for your purpose, what you could try is detecting lines in the image.
You can try cv2.HoughLinesP or cv2.createLineSegmentDetector to identify lines. I am sure you can go ahead after detecting lines.
Also, you can go look into How to detect lines in OpenCV?, different use case which can be extended for your purpose as well.
Happy coding…