

Using colors to segment (or identify) the red apple in the specific video frame is the most simple. For this exercise it is recommended to use the simplest way for apple segmentation using colors and use 2D cross correlation to find the movement of the apples from one frame to the next. Otherwise it is also possible to use another form of blob analysis or edgde tracking algorithms. The easiest way is to threshold the intensity of the color red if we want to find red apples in the frames. Several methods for finding the position of the apples are available. Step 2: Finding the position of the apples The next logical step is to compute the position of the apples within the frames. Now we are able to load the frames into double precision that matlab can process. Subplot(3,1,3) imagesc(imB) colorbar title( 'Blue') axis image Subplot(3,1,2) imagesc(imG) colorbar title( 'Green') axis image Subplot(3,1,1) imagesc(imR) colorbar title( 'Red') axis image In other words it is the intensity of that color. The colors in the figure is just how much of the specific color is present in the picture at the given location of the frame. Don't be confussed that for an example the red color isn't red. The values of each color can be seen in the following figure. In the following are each of the three colors, from frame 24, saved in their own variable: imR = im2double(mov(24).cdata(:,:,1)) The function im2double does exactly that. The data contained in the mov(:).cdata are in unsigned 8 bit integers (uint8) but to make things less complicated we make a convertion from uint8 to doubles. These colors can be used to easily identify an object of a certain color in the picture (for instance a red apple).
#MATLAB TOOLS FOR VIDEO TRACKING CODE#
The variable mov(x).cdata contains three color codes Red, Green, and Blue (therefore the color code are "RGB").
#MATLAB TOOLS FOR VIDEO TRACKING MOVIE#
You can also view the loaded movie using the movie player in Matlab implay(mov,5) The frames can be seen with either the image or imshow function as seen below (frame 24): figure imshow(mov(24).cdata) This is done by reading one frame at a time and save it into the array: (access data as with the object Video) for k = 1 : nFrames In the following "for" loop each of the frames from the "apple" video are parked in the car park or more technically correct saved within the prior preallocated variable. mov(1:nFrames) = struct( 'cdata', zeros(vidHeight, vidWidth, 3, 'uint8'), 'colormap', ) Said in another way build an empty variable or you could say a empty car park for the frames of the video. Preallocate or build an empty video structure. This information can be accessed and saved as shown below: nFrames = Video.NumberOfFrames The function returns information about number of frames, the resolution of the video, and video format amoung other things. Path: 'D:\Dokumenter\Undervisning\Measurement Technology and D.' The underlaying variables can be seen using the function get: get(Video) The output variable is in this case called an object: Video = VideoReader( '120905-135843.wmv') Īn object means that it contains underlaying varibles. Use of the VideoReader function is easy just type in the path and the returning variable saves the output. In this case the VideoReader function can be used (the homepage of is very useable) or type doc VideoReader in the command window. Matlab, as you probably already know, has a variaty of inbuilt functions.

The first thing you need to do is to load the frames from the "apple" video into usable matlab data (preferably doubles). Step 1: Load the video frames into matlab

Step 2: Finding the position of the applesĪlways start matlab coding with the following line which is necessary to clear the memory (both command window and workspace) and close all previosly opened figures.Step 1: Load the video frames into matlab.
