After honoring the article by Alexander Shuravina (megabax) with the title: “A Simple Motion Recognition Algorithm” on the site, there was a need to advance in solving the problem posed in the article. As a result, an algorithm appeared for processing a sequence of frames containing displays of moving objects, for example, vehicles (TS).
At the output of the algorithm, several frames are formed - according to the number of vehicles displayed in the input sequence. Each output frame displays an individual vehicle track in the camera’s field of view and an image of this vehicle. There will also be placed digital information on the current position of the center of the bordering rectangle, the instantaneous and average speed of the vehicle.
For example, Figure 1 shows the results of processing the input sequence consisting of 40 frames taken from one of the overpasses above the M8 highway. At the output, five frames are formed with the display of the track and the image of each vehicle that entered the camera’s field of view.

')
The algorithm consists of three blocks.
In the first block of several consecutive frames, a binary frame is formed, which displays moving objects and / or their fragments as white spots on a black background.
In the second block, each spot is painted in its own shade of gray and the mass of pixels in the spot, the size of the rectangle bordering the spot, the coordinates of its vertices and center are calculated.
In the third block, the offset of each spot relative to each spot in the previous frame is calculated, and a spot is determined from the minimum offset, which is most likely related to the same object. Due to the individual coloration, these spots can be identified and transferred to individual frames displaying a sequence of nearby spots.
Such frames are individual for each spot and as a result display the track of a moving object, formed by the imposition of synchronously moving spots. Estimation of the vehicle speed can be made by the displacement of the center or vertices of the rectangles bordering the spot. A more accurate method is described in article [1].
The algorithm is quite effective due to the informativeness of the output frames. They can contain digital information about the position and speed of the vehicle in the field of view of the camera, as well as visual data on the size, appearance of each vehicle and its track.
Here is a screenshot of the program for the first and second blocks.



The code of the third block contains a lot of similar searches and was quite heavy and slow. Therefore, it is not given in the article. Those who wish can send the full code of the processing program. (It is necessary, however, to understand that the program is written by a "teapot").
To configure the algorithm, you need to set the thresholds for estimating the value of pairwise comparison of the level of illumination in the same pixels of adjacent frames. The optimal thresholds correspond to the minimum number of spots on a binary frame, indicated in the program by the symbol w1 [k].
Figure 2 shows a group of frames for pairwise comparison of illumination at each pixel.

Figures 3a, 3b, 3c show the influence of the threshold value on the appearance of a binary frame and a frame in shades of gray, obtained from two adjacent frames (the second and third thresholds are so large that they disable the third and fourth frames).

Figures 4a, 4b, 4c show the effect of the threshold value on the appearance of a binary frame and a grayscale frame obtained from three adjacent frames (the third threshold turns off the fourth frame).

Figures 5a, 5b, 5c show the effect of the threshold value on the appearance of a binary frame and a gray scale, obtained from four adjacent frames.

Figures 6 show the effect of the threshold value on the type of output frames.
Literature1. A.A. Yakovlev Determining the speed of the video method of special points Actual issues of modern science / Collection of articles on the materials of the 1X international scientific-practical conference (February 8, 2018, Tomsk). Part 1 .- p. 97 / - Ufa: Ed. Dendra, 2018.