top of page

RESEARCH

Fish 1 .png
WhatsApp Image 2022-03-12 at 9.35.48 PM.jpeg
WhatsApp Image 2022-03-12 at 9.35.48 PM (1).jpeg

Development

WhatsApp Image 2022-03-12 at 9.35.48 PM (3).jpeg
WhatsApp Image 2022-03-12 at 9.35.49 PM.jpeg
WhatsApp Image 2022-03-12 at 8.06.16 PM (2).jpeg
Cat fish.png
Fish bowl 2 .png
WhatsApp Image 2022-03-12 at 9.35.49 PM (3).jpeg
WhatsApp Image 2022-03-12 at 9.35.49 PM (4).jpeg

CODE

In order to simplify the code, as well as to carry out a correct documentation, the code was analyzed thanks to the fact that it was separated with boxes of different colors, which are explained in the lower part of the capture of each one of the segments.

Code1.png
CColores1.png

The camera with which the program will work is selected, either the camera that detects the fish or the camera for the demonstration.

It establishes the definition of the cameras, this to be able to carry out the same program with any of the cameras.

As visual support, 4 green lines are placed on the image to divide it into 9 equal segments which represent different actions in the program. 

The image is resized to fit the preview frame on the front panel of the program.

From this point we start with the analysis of the image, the first step is to simplify the image to a binary image, this from an RGB filter.

Here the parameters and ranges of the RGB filter are established, if the analyzed pixel is within these parameters it is considered a pixel on, if not, it is considered off.

Code2.png
CColores2.png

After the simplification of the image there may be points which we do not need, this function helps us to remove these particles.

The next step of image analysis is the close function, which helps close nearby images or objects into polygons.

The next function is to dilate the image so that the image is simplified and has a shape similar to a circle.

In this function, the center of mass of the binary image is searched to recognize the fish, obtaining its position and if it exists.

In this section of the program a boolean result is obtained which is the result of the comparison if the fish is in the image or not, which serves to avoid errors in the program logic.

In this part, the position of the fish is compared with respect to the quadrants of the image, with this a two-dimensional matrix is created with three spaces towards each of the directions. This is exported to a global variable.

This section of the code is the main part where the parameters for the movement are obtained, which are transmitted from the computer to the MyRio controller with PWM signals to the L298N.

Code3.png
CColores3.png

In this section of code, the global variables are imported with the values of the position of the fish in the 3x3 matrix, as well as the value of its position in pixels.

In this section, a switch case was placed in which it compares the three cases of the positions in X.

Inside each of the previous cases, another switch case was placed with the positions of the matrix, in this case it is with respect to the Y dimension

Thanks to these cases, the PWM values are obtained, that is, speed, for each of the motors, as well as their direction. Which are sent in the corresponding ports of the MyRio FPGA.

CIRCUIT

CircuitoPez.png
bottom of page