0

I'm experimenting with python and openCV to get back into coding. As a fun project, I would like to build an agent that could play PacMan. I'm able to find all the "pills" and ghosts from this image, but the same approach appears to fail miserably when I'm trying to identify the walls, i.e. it only detects few segments.

I am using:

cv.matchTemplate(pacman_table_img, [pill|wall]_img, cv.TM_CCOEFF_NORMED)

pacman table

pill

wall

Thanks in advance for any help or suggestion.

2e0byo
  • 5,305
  • 1
  • 6
  • 26
final3
  • 1
  • Are you compensating for the fact that horizontal and vertical walls are different? You SHOULD be able to detect the blue color. – Tim Roberts Sep 29 '21 at 04:17
  • How do you use the matchTenplate result? Nany code samples only use the best match, but you will have to find all matches. Did you try different metrics than cv.TM_CCOEFF_NORMED? – Micka Sep 29 '21 at 04:57
  • Yes, I tried different metrics w no significative improvement (must admit some worked worse than TM_CCOEFF_NORMED). – final3 Sep 29 '21 at 14:04
  • re: vertical vs horizontal, The few detected walls are horizontal, but as my code could not detect all of them I did not focus on the missing vertical one, but good point. – final3 Sep 29 '21 at 14:06
  • I could go for a solution like this one https://stackoverflow.com/questions/58288014/how-to-know-if-a-color-is-detected-on-opencv The PacMan map can be divided in subcells of a constant size and the code could check if they contain any wall-blue pixel. – final3 Sep 29 '21 at 14:10

0 Answers0