开发者

Finding a grid in an image

开发者 https://www.devze.com 2023-04-06 20:18 出处:网络
Having a match-3 game screenshot (for example http://www.gameplay3.com/images/games/jewel-quest-ii-01S.jpg), what would be the correct way to find the bound box for the grid (table with tiles)? The bo

Having a match-3 game screenshot (for example http://www.gameplay3.com/images/games/jewel-quest-ii-01S.jpg), what would be the correct way to find the bound box for the grid (table with tiles)? The board doesn't have to be a perfect rectangle (as can be seen in the screenshot), but each cell is completely square.

I've tried several games, and found that there are some per-game image transformations that can be done to enhance the tiles inside the grid (for example in this game it's enough to take the V channel out of HSV color space). Then I can enlarge the tiles so that they overlap, find the largest contour of the image and get the bound box from it.

The problem with above approach is that every game (or even level inside the same game) may need a different transformation to get hold of the tiles. So the question is - is there a standard way to enhance either tiles inside the grid or grid's lines (I've tried finding lines with Hough transform, but, although the grid seems pretty visible to the eye, Hough doesn't find it)?

Also, what if the screenshot is obtained using the phone camera i开发者_JAVA百科nstead of taking a screenshot of a desktop? From my experience, captured images have less defined colors (which depends on lighting), and also can be distorted a little, as there is no way to hold the phone exactly in front of the screen.


I would go with the following approach for a screenshot:

  1. Find corners in the image using for example a canny like edge detector.
  2. Perform a hough line transform. This should work quite nicely on the edge image.
  3. If you have some information about size of the tiles you could eliminate false positive lines using some sort of spatial model of the grid (eg. lines only having a small angle to x/y axis of the image and/or distance/angle of tile borders.
  4. Identifiy tile borders under the found hough lines by looking for edges found by canny under/next to the lines.

Which implementation of the hough transform did you use? How did you preprocess the image?

Another approach would be to use some sort of machine learning approach. As you are working in OpenCV you could use either a Haar like feature detector. An example for face detection using Haar like features can be found here:

OpenCV Haar Face Detector example

Another machine learning approach would be to follow a Histogram of Oriented Gradients (Hog) approach in combination with a Support Vector Machine (SVM). An example is located here:

HOG example

You can find general information about HoG detection at:

Hog detection

0

精彩评论

暂无评论...
验证码 换一张
取 消