Wednesday, December 7, 2016

Activity 11: Basic Video Processing


This activity is the last of my Applied Physics 186 activities. Here, we try to apply all of the image processing techniques we've learned during the sem to a sequence of images that are played continuously more commonly known as a video to extract information like the position of a ball in time. 

Consider a simple mechanics problem shown below: A ball is released from one end of an inclined plane. Find a) Its position through time b) The acceleration due to gravity, $g$.

We need to isolate the ball using color segmentation. Vid.1 is a 5-second video we want to process. We take each frame as an image and try to isolate the ball by taking a patch on the surface of the tennis ball as our ROI and then apply Parametric Segmentation. To know about this said technique, you can revisit my Activity 7 here. 





After the parametric segmentation, there are still some other blobs we want to disregard completely. To do this, I did morphological operations to remove these blobs. First, label each blob using the SearchBlobs() function and then, try to filter each using FilterBySize(). The following video shows the isolated ball.


Below is the code I used to isolate the ball and compute for the centroid.




Now that we have one single blob to track, we find its position by calculating for its centroid. The centroid is the coordinates of the blob's center of mass in the image so that it is in x and y. The problem can be solved using polar coordinates for ease in computation but since the centroid for every frame is an ordered pair of (x,y) we first use cartesian coordinates and then convert into polar. The following images contain the schematic diagram of the problem and also the derivation of the important equations.
Figure 1. Schematic diagram with the origin at the top of the ramp. Polar and cartesian relations are also derived.

We consider the origin to be at the top of the ramp inclined at an angle $\alpha$ and has a length $s_{max}$. The relationship of the cartesian to polar quantities are also shown.

Figure 2. Energu relations for a hollow ball from which we derived the velocity $\dot s$ at the bottom of the incline

We consider the tennis ball to be a hollow sphere with a moment of inertia $I = \frac{2}{3}mr^2$ and that its motion includes rolling without slipping along the incline. From the energy relation which shows the conservation of energy where the potential energy is equal to the kinetic, we can derive its final speed $\dot s$.

Figure 3. We take the derivative  of the expression for the velocity $\dot s$ in Figure 2 to get the acceleration of the ball along the ramp and then use trigonometry to get the acceleration along the horizontal.

Figure 4. The position of the ball per frame is tracked and then plotted against time

Images were extracted from the video with rate of 25 frames/second. For each frame the position of the ball is extracted. But the pixel location plotted against time is meaningless so we need to convert it into real physical units. To do this, we compute for the calibration factor $C$ which determines the length covered by a pixel unit. Shown below is the computation.

$L_{actual} = 7 ft$

$end_1 = (828,35)$
$end_2 = (5,104)$

Since the length is oriented along the diagonal, we cannot simply subtract the coordinates like we did in Activity 2. To find the length of the incline, we employ the distance formula.

$L_{image} = end-to-end distance = \sqrt{(825-5)^2 + (5-104)^2} = 825.887 px$

7 ft. = 825.887 px

$(7ft.)\left(\frac{12 in.}{1 ft}\right)\left(\frac{2.54 cm.}{1 in.}\right)\left(\frac{1 m}{100 cm}\right) = 2.1336 \, m$

$C = \frac{2.1336 m}{825.887 px} = 2.58 \times 10^-3 \,  \frac{m}{px}$

And the incline is tilted at an angle of $\alpha = \arctan\left({\frac{|35- 104|}{|828-5|}}\right)= 4.79224 ^{\circ}$

Now we know that a pixel represents a distance of $2.58 \times 10^-3 \,  \frac{m}{px}$. The next thing we need to do is to multiply all the x-pixel coordinates with this factor to get the position and space and then plot this against time mutiplied to $\frac{1}{25}$ which represents the time per frame.
Figure 5 shows the plot of the balls position in time as extracted from the video frames. Now we can compare the coefficients of the fit with the theoretical as shown in Figure 4.



Figure 5. Position of ball in time with quadratic fit


We know that the concavity of the curve represents the acceleration $\ddot x$ of the ball so that, $\ddot x = 2a = \frac{3}{10}\,g\,\sin\alpha$. Isolating $g$, we get


$g = \frac{20\,a}{\sin 2\alpha}$ where a  is the coefficient of the quadratic fit in the experimental plot of the position vs. time shown in Figure 5. The calculated value for the acceleration due to gravity is $g = 9.961863 \frac{m}{s^2}$ which deviates from the theoretical value by $1.5 \%$.

This has been quite a culmination of the image processing skills I acquired for the entire sem and a refresher of my mechanics. For this activity, I will rate myself 11/10 since I was able to effectively apply image processing techniques and  accomplish my objectives completely. And also, I believe the images (Figure 1-4) used to illustrate the problem involved much effort in creating and also they're neat! :D

References:

[1] M. Soriano, "Basic Video Processing", AP186 class manual. (2016)







No comments:

Post a Comment