Find an object template in an array in C #

I am looking for an effective way to find an object template in an array. Here is the problem I have to solve. I am writing a tangible interface application that collects data from a webcam, converts it into a black and white image, from which I create an array. The created array looks something like this:

1111111111111111111111111111 1111110001111111111000111111 1111100000111111110000011111 1111100000111111110000011111 1111110001111111111000111111 1111111111111111111111111111 

Where zeros represent the color black in the image. I have about 32 (4 lines of 8 circles in each), and I need to find an effective way to find their coordinates. I don’t need the whole shape, just a set of coordinates for each circle.

Thanks for the help.

Sincerely, Theodor Stoyanov

+4
source share
3 answers

Three parameters that I can see right away (Tuple is used to represent the coordinates in your matrix):

  • You can use BitArray for each point in the matrix, the bit is set if the coordinate is O, the cost will be O (row length x column length) for storage. Search - O (1), if you know the coordinates that you want to check otherwise, O (n), if you just want to find all O

  • You can use List<Tuple<int,int>> to store only the coordinates for each O in the matrix, the cost will be O (m) for storage, m is the number of O. Extract also O (m)

  • As an alternative to option 2, you can use Dictionary<Tuple<int, int>, bool> , which allows you to retrieve O (1) if you know the coordinates you want to check.

+1
source

Select an arbitrary value of 0 and fill the fill. The average coordinates of all 0s found to get the center of the circle. Remove the flooded 0 and repeat.

+1
source

There is actually no easy way to do this, but the best thing you can do is mess with Artificial Neural Networks . They allow you to transfer data and receive output over many different data inputs. If you build the network correctly, it will self-adjust its weights over many iterations.

Sorry, but I doubt that you will get the exact solution prescribed for you in the code. Although I have not used any of these libraries or resources, a quick look at them makes them look pretty decent:

0
source

All Articles