# FPGA Implementation of Gaussian Mixture Model Algorithm for 47 fps Segmentation of 1080p Video

Authors: Mariangela Genovese; Ettore Napoli; Davide De Caro; Nicola Petra; Antonio G. M. Strollo
Journal: Journal of Electrical and Computer Engineering
 (2013)

---

## Abstract

Circuits and systems able to process high quality video in real time are fundamental in nowadays imaging systems. The circuit proposed in the paper, aimed at the robust identification of the background in video streams, implements the improved formulation of the Gaussian Mixture Model (GMM) algorithm that is included in the OpenCV library. An innovative, hardware oriented, formulation of the GMM equations, the use of truncated binary multipliers, and ROM compression techniques allow reduced hardware complexity and increased processing capability. The proposed circuit has been designed having commercial FPGA devices as target and provides speed and logic resources occupation that overcome previously proposed implementations. The circuit, when implemented on Virtex6 or StratixIV, processes more than 45 frame per second in 1080p format and uses few percent of FPGA logic resources.


---

## Body

## 1. Introduction

Real time background identification in high definition video streams is an important task in smart video systems [1–4]. Various algorithms that address the problem have been proposed in the scientific literature throughout the years [5–16].Foreground detection algorithms based on temporal difference techniques [5–7] allow the detection of relevant objects (Foreground, Fg) by comparing two or more consecutive frames but are unreliable in presence of illumination changes.More robust algorithms, named background subtraction algorithms [8–15] are based on the creation of a model that includes the static parts of the scene (Background, Bg). The Fg is detected by analyzing the difference between a frame and the model of the Bg. The Bg subtraction algorithms regularly update the Bg model and are resilient to slow changes of the scene. They differ for the considered model of the Bg and for the algorithm that takes care of model updating.References [13–15] propose Bg subtraction algorithms based on statistical models.In [14] the Bg is represented with a statistical model based on a single Gaussian distribution per pixel. This allows a pixel by pixel model of the Bg with larger variance for pixels that experience wide changes of lighting.The Gaussian Mixture Model (GMM) algorithm has been proposed in [15]. It uses a statistical model in which the probability distribution of the luminosity of each pixel is modeled with a mixture of Gaussian distributions. The GMM algorithm provides good performances in both presence of illumination changes and multimodal Bg. A multimodal Bg is characterized by objects showing repetitive motions, for example, waves, moving leaves, or flickering light. When a pixel lies in a region where a repetitive motion occurs, its brightness oscillates between two or more values. This results in false Fg detection in most algorithms. On the contrary, when the GMM algorithm is used, the intensity distribution of the pixel is modeled using two or more Gaussian distributions and the problem of false Fg detection is mitigated.The OpenCV (Open source Computer Vision software library developed by Intel [16]) provides a common base of computer vision instruments that is becoming the de facto standard for video/image processing. The Bg detection algorithm included in the OpenCV is an optimized version of the GMM algorithm of [15]. It changes the initial learning phase for the Bg model, that is improved with respect to [15], and calculates the learning rate in a simplified yet efficient way. As a consequence, the OpenCV version of the GMM algorithm is both widely used and provides good performances.


### 1.1. Previous Hardware Implementations

In order to generate the updated Bg model, the GMM algorithm processes the video stream by computing a great number of parameters for each pixel of each frame, with a computational burden unfeasible for computers in real time applications. As an example, in [15], only a frame rates of 11–13 frame per second (fps) is obtained for frame size 160×120 on an SGI O2 workstation.Real time video applications with larger frame size require a dedicated hardware architecture. Hardware processors have been proposed in [17–22]. Reference [17] proposes a circuit able to process video sequences with frame size 1024×1024 at 38 fps when implemented on a VirtexII FPGA platform. Processing capabilities of [17] are 39.8 Mega pixel per second (Mps). In [18] the design of an automated digital surveillance system running in real time on an embedded platform is presented. The segmentation unit of the circuit proposed in [18] is able to run at 83 MHz on VirtexII xc2pro30. In [19], the research group of [18] improves the memory throughput with respect to [18] by employing a memory reduction scheme. The improvement in memory throughput is paid with a reduction of the processing capability that is limited to 7.68 Mps.Reference [20] proposes an OpenCV GMM algorithm implementation able to process 22 HD (1920×1080 pixels) frames per second when implemented on Virtex5 xc5vlx50 FPGA. The circuit of [20] is used in [21] in conjunction with a denoising block that implements erosion, dilation, opening, and closing.A circuit that implements the OpenCV GMM algorithm and provides increased performances has been presented in [22]. The improvement in circuit performance derives from the optimization of the bit width of the signals and from a better formulation of the GMM equations.


### 1.2. Proposed Circuit

In this paper a hardware implementation of the GMM algorithm that allows real time processing of HD videos and comply with the OpenCV algorithm is proposed. To the best of author's knowledge, the proposed circuit is the one with highest performance proposed to date. The circuit processes gray scale videos. When color videos need to be processed, the circuit, as reported in [19], can be fed with the luminance channel of the YCrCb color space.The proposed circuit is optimized for an FPGA implementation and, with respect to the best performing previous work, [22], increases the maximum working frequency (+77.4%) and reduces the area utilization (−3.8% of Slices and 0 versus 10 DSP).The improved performances are obtained by(i)
replacing full-width binary multipliers with truncated binary multipliers [23–26];(ii)
approximating nonlinear functions with piecewise linear approximations [27–31];(iii)
exploiting an innovative formulation of the updating equations of the GMM algorithm.It is worth noting that the implemented design techniques (mainly the use of truncated multipliers and the approximation of nonlinear functions with piecewise linear functions) while allowing improved performances in terms of circuit speed and logic resources occupation are a modification of the reference OpenCV GMM algorithm and introduce a computation error that could result in a worsening of the quality of the processed video. The tests presented in Section5, however, demonstrate that the proposed circuit is able to obtain very high performances while providing a good quality of the processed video sequences.


## 1.1. Previous Hardware Implementations

In order to generate the updated Bg model, the GMM algorithm processes the video stream by computing a great number of parameters for each pixel of each frame, with a computational burden unfeasible for computers in real time applications. As an example, in [15], only a frame rates of 11–13 frame per second (fps) is obtained for frame size 160×120 on an SGI O2 workstation.Real time video applications with larger frame size require a dedicated hardware architecture. Hardware processors have been proposed in [17–22]. Reference [17] proposes a circuit able to process video sequences with frame size 1024×1024 at 38 fps when implemented on a VirtexII FPGA platform. Processing capabilities of [17] are 39.8 Mega pixel per second (Mps). In [18] the design of an automated digital surveillance system running in real time on an embedded platform is presented. The segmentation unit of the circuit proposed in [18] is able to run at 83 MHz on VirtexII xc2pro30. In [19], the research group of [18] improves the memory throughput with respect to [18] by employing a memory reduction scheme. The improvement in memory throughput is paid with a reduction of the processing capability that is limited to 7.68 Mps.Reference [20] proposes an OpenCV GMM algorithm implementation able to process 22 HD (1920×1080 pixels) frames per second when implemented on Virtex5 xc5vlx50 FPGA. The circuit of [20] is used in [21] in conjunction with a denoising block that implements erosion, dilation, opening, and closing.A circuit that implements the OpenCV GMM algorithm and provides increased performances has been presented in [22]. The improvement in circuit performance derives from the optimization of the bit width of the signals and from a better formulation of the GMM equations.


## 1.2. Proposed Circuit

In this paper a hardware implementation of the GMM algorithm that allows real time processing of HD videos and comply with the OpenCV algorithm is proposed. To the best of author's knowledge, the proposed circuit is the one with highest performance proposed to date. The circuit processes gray scale videos. When color videos need to be processed, the circuit, as reported in [19], can be fed with the luminance channel of the YCrCb color space.The proposed circuit is optimized for an FPGA implementation and, with respect to the best performing previous work, [22], increases the maximum working frequency (+77.4%) and reduces the area utilization (−3.8% of Slices and 0 versus 10 DSP).The improved performances are obtained by(i)
replacing full-width binary multipliers with truncated binary multipliers [23–26];(ii)
approximating nonlinear functions with piecewise linear approximations [27–31];(iii)
exploiting an innovative formulation of the updating equations of the GMM algorithm.It is worth noting that the implemented design techniques (mainly the use of truncated multipliers and the approximation of nonlinear functions with piecewise linear functions) while allowing improved performances in terms of circuit speed and logic resources occupation are a modification of the reference OpenCV GMM algorithm and introduce a computation error that could result in a worsening of the quality of the processed video. The tests presented in Section5, however, demonstrate that the proposed circuit is able to obtain very high performances while providing a good quality of the processed video sequences.


## 2. GMM Algorithm

The GMM algorithm has been proposed by Stauffer and Grimson, [15], with the target of efficiently dealing with multimodal Bg by using a statistical model composed by a mixture of Gaussian distributions. The GMM algorithm has been modified and included in the OpenCV libraries. A short description of the OpenCV GMM algorithm is given in the following. The differences with respect to the algorithm of [15] are indicated in the text.


### 2.1. Statistical Model

The statistical model for each pixel of the video sequence is composed by a mixture ofK Gaussian distributions, each one represented by four parameters: weight (w), mean (μ), variance (σ2), and matchsum, a counter introduced in the OpenCV algorithm.Gaussian parameters differ for each Gaussian of each pixel and change for every frame of the video sequence. They are therefore defined by three indexes(p,k,t), where “p” is the index for the pixel, “k” is the index for the Gaussian distribution, and “t” is for the frame. In the following the pixel index is omitted since the same operations are repeated for every pixel.


### 2.2. Parameters Update

When a frame is acquired, for each pixel, theK Gaussian distributions are sorted in decreasing order of a parameter named Fitness (Fk,t):
(1)Fk,t=wk,tσk,t.
A match condition is checked with the K Gaussian distributions that model the pixel. The match condition is
(2)Mk=1if|(pixel-μk,t)|<2.5σk,t.
Equation (2) establishes if the pixel can be considered part of the Bg. A pixel can verify (2) for more than one Gaussian. The Gaussian that matches with the pixel (Mk=1) and has the highest Fk,t value is considered as the “matched distribution” and its parameters are updated as follows:
(3)μk,t+1=μk,t+αk,t·(pixel-μk,t),σk,t+12=σk,t2+αk,t·[(pixel-μk,t)2-σk,t2],wk,t+1=wk,t-αw·wk,t+αw,matchsumk,t+1=matchsumk,t+1.
The parameter αw is the learning rate for the weight while αk,t is the learning rate for mean and variance. It is derived from αw as follows:
(4)αk,t=αwwk,t.
Equation (4) is characteristic of the OpenCV algorithm and differs from what is proposed in [15] where αk,t is calculated, being η the Gaussian probability density function as follows:
(5)αk,t=αw·η(pixel,μk,t,σk,t).
The approach of [15] results, as shown in [32], in a slow convergence if compared with (4).For the unmatched Gaussian distributions mean and variance are unchanged while the weights are updated as follows:(6)wk,t+1=wk,t-αw⋯wk,t.When the pixel does not match any Gaussians, a specific “no_match” procedure is executed and the Gaussian distribution with smallestFk,t is updated as follows:
(7)μk,t+1=pixelmatchsumk,t+1=1,σk,t+12=vinitwk,t+1=1msumtot,
where vinit is a fixed initialization value and msumtot is the sum of the values of the matchsum of the K-1 Gaussians with highest Fk,t. The weights of the K-1 Gaussians with highest Fk,t are decremented as in (6) while their means and variances are unchanged.


### 2.3. Background Identification

The Bg identification uses the following algorithm:(8)B=argminb(∑k=1bwk,t>T).
Equation (8) adds in succession the weights of the first b Gaussian distributions, sorted beginning from the one with highest Fk,t value, until their sum is greater than T, a fixed threshold belonging to the [0,1] interval. The set of Gaussian distributions that verify (8) represents the Bg and a pixel that matches one of these Gaussians is classified as a Bg pixel. The algorithm entails that if the “no_match” condition occurs, the pixel is classified as Fg.


## 2.1. Statistical Model

The statistical model for each pixel of the video sequence is composed by a mixture ofK Gaussian distributions, each one represented by four parameters: weight (w), mean (μ), variance (σ2), and matchsum, a counter introduced in the OpenCV algorithm.Gaussian parameters differ for each Gaussian of each pixel and change for every frame of the video sequence. They are therefore defined by three indexes(p,k,t), where “p” is the index for the pixel, “k” is the index for the Gaussian distribution, and “t” is for the frame. In the following the pixel index is omitted since the same operations are repeated for every pixel.


## 2.2. Parameters Update

When a frame is acquired, for each pixel, theK Gaussian distributions are sorted in decreasing order of a parameter named Fitness (Fk,t):
(1)Fk,t=wk,tσk,t.
A match condition is checked with the K Gaussian distributions that model the pixel. The match condition is
(2)Mk=1if|(pixel-μk,t)|<2.5σk,t.
Equation (2) establishes if the pixel can be considered part of the Bg. A pixel can verify (2) for more than one Gaussian. The Gaussian that matches with the pixel (Mk=1) and has the highest Fk,t value is considered as the “matched distribution” and its parameters are updated as follows:
(3)μk,t+1=μk,t+αk,t·(pixel-μk,t),σk,t+12=σk,t2+αk,t·[(pixel-μk,t)2-σk,t2],wk,t+1=wk,t-αw·wk,t+αw,matchsumk,t+1=matchsumk,t+1.
The parameter αw is the learning rate for the weight while αk,t is the learning rate for mean and variance. It is derived from αw as follows:
(4)αk,t=αwwk,t.
Equation (4) is characteristic of the OpenCV algorithm and differs from what is proposed in [15] where αk,t is calculated, being η the Gaussian probability density function as follows:
(5)αk,t=αw·η(pixel,μk,t,σk,t).
The approach of [15] results, as shown in [32], in a slow convergence if compared with (4).For the unmatched Gaussian distributions mean and variance are unchanged while the weights are updated as follows:(6)wk,t+1=wk,t-αw⋯wk,t.When the pixel does not match any Gaussians, a specific “no_match” procedure is executed and the Gaussian distribution with smallestFk,t is updated as follows:
(7)μk,t+1=pixelmatchsumk,t+1=1,σk,t+12=vinitwk,t+1=1msumtot,
where vinit is a fixed initialization value and msumtot is the sum of the values of the matchsum of the K-1 Gaussians with highest Fk,t. The weights of the K-1 Gaussians with highest Fk,t are decremented as in (6) while their means and variances are unchanged.


## 2.3. Background Identification

The Bg identification uses the following algorithm:(8)B=argminb(∑k=1bwk,t>T).
Equation (8) adds in succession the weights of the first b Gaussian distributions, sorted beginning from the one with highest Fk,t value, until their sum is greater than T, a fixed threshold belonging to the [0,1] interval. The set of Gaussian distributions that verify (8) represents the Bg and a pixel that matches one of these Gaussians is classified as a Bg pixel. The algorithm entails that if the “no_match” condition occurs, the pixel is classified as Fg.


## 3. Background Identification Circuit

Figure1 shows a conceptual overview of a Bg identification system. A CMOS sensor captures each frame of the video sequence and a CMOS interface gives the pixel values to the Bg identification circuit. The Bg identification circuit processes the luminance value of the input “Pixel,” and the “Statistical Model” of the pixel for the given frame. The output data are the “Updated Statistical Model” and the “Fg/Bg” tag. For each pixel, the Gaussian parameters are read from an external memory and the updated parameters are stored in the memory. For each frame of the input video sequence, the Fg/Bg tags produce a binary image that can be displayed on a monitor.Figure 1
Conceptual overview of a background identification system.In this paper, the “background identification circuit” of Figure1 has been implemented on FPGA devices. Figure 2 shows the block diagram of the proposed circuit. The circuit is described in VHDL code and implements the GMM algorithm using, as suggested in [15], three Gaussian distributions for each pixel (k=[1,2,3]). As a consequence, the proposed circuit processes 13 parameters per pixel (the luminance value and 12 Gaussians parameters for the statistical model of the pixel).Figure 2
Block diagram of the proposed FPGA implementation. The functionality of the circuit is described in Section5. The star indicates the circuital block that has been improved by using the truncated binary multipliers. The diamond indicates the circuital blocks that have been improved by using piecewise linear approximation of nonlinear functions.The software algorithm of the OpenCV library represents the Gaussians parameters as double precision (64 bit) floating point numbers. A double precision hardware implementation would be impractically large and slow and would require a very high bandwidth towards the memory. The proposed circuit represents the signals as fixed point numbers on a limited number of bits. The word length and the representation of the Gaussians parameters are determined by using the word length optimization algorithm proposed in [22] that minimizes the word length while constraining the Peak Signal-to-Noise Ratio (PSNR) of a set of test video streams. The input bits of the resulting circuit are the 99 bits for the parameters of the statistical model and the 8 bits of the luminance of the input pixel. The output bits are the updated statistical model, that requires 99 bits, and the Fg/Bg tag.The optimized fixed point representation, an innovative formulation of the GMM algorithm equations (described in Section4), the use of truncated multipliers, and the application of ROM optimization techniques (details in Section 5), allow the design of a Bg identification circuit with high working frequency and low logic resources utilization.


## 4. Hardware Oriented Formulation of the GMM Equations

The equations of the GMM algorithm, detailed in Section2, if straightforwardly implemented, would be too complex for the realization of a fast and compact circuit. The proposed circuit is therefore based on the manipulation and simplification of the above-cited equations. A first step towards the simplification is the use of an optimized fixed point representation for circuit signals [22]. A second step is the smart implementation of the nonlinear operations as will be shown in Section 5.In addition to the above-cited techniques, in this paper, in order to reduce the logic occupation, a new order parameter for Gaussian distributions is introduced. The parameter is namedIFitness (indicated in the following as IFk,t) and is defined as the inverse of the Fk,t factor:
(9)IFk,t=1Fk,t.
With simple manipulations, taking into account (1) and (4), IFk,t can be written as
(10)IFk,t=σk,twk,t=σk,twk,t·αk,tαk,t=σk,t·αk,tαw.Equation (10) shows that the IFk,t factor can be computed as a function of the learning rate αk,t.Moreover, in the proposed implementation, the learning ratesαw and αk,t are quantized as power of two values:
(11)αw=2nwαk,t=2nk,t.
As a consequence, the IFk,t factor can be computed as follows:
(12)IFk,t=σk,t·2(nk,t-nw)
and the multiplication between 2(nk,t-nw) and σk,t can be performed using a shifter instead of a binary multiplier.It is worth noting that ordering the Gaussian distributions as a function ofFk,t, a process needed in the GMM algorithm in order to determine the Bg model according to (8), is equivalent to ordering versus the IFk,t value.Equations (4) and (12) can be implemented using only a shifter and a square root circuit that calculates the standard deviation σk,t. The implementation does not require the multiplier that would be needed to implement (1). The removal of the multiplier is not only beneficial for the implied reduction of hardware usage but, being the multiplier on the critical path of the Bg identification circuit, is also effective in increasing overall circuit speed. More details regarding the HW implementation of the above-described equations are given in the Section 5.


## 5. FPGA Implementation of the Background Identification Circuit

The schematic of the FPGA implementation of the GMM algorithm is shown in Figure2. A detailed explanation of the functionalities and of the hardware implementation of the circuital blocks of Figure 2 is given in the following.


### 5.1. Learning Rate

Computesαk,t following (4).The “learning rate” unit is implemented with three ROM, each of them stores the power of two values that better approximatesαk,t as a function of wk,t ((4), (11)). The equation implemented by the ROM is
(13)nk,t=round[log2(αk,t)]
in which the function “round(·)” is the approximation to the nearest integer value. The nk,t values are then used by the “IFitness” unit to shift the σk,t in order to calculate the IFk,t factor according to (12).


### 5.2. Standard Deviation

The formulation of the GMM equations described in Section4 requires the standard deviation values, σk,t, for the three Gaussians while the input data for the circuit include the variance values, σk,t2.The “Standard Deviation” block determines the variance values by implementing a square root circuit.In the proposed implementation theσk,t2 signals are represented on 11 bits and range in [8 : 16376]. Due to the reduced number of bits of the variance signal, a ROM implementation for the square root circuit could be feasible but not optimal. In this paper the square root function has instead been implemented by using a piecewise linear approximation of the nonlinear function, a technique that has been previously proposed as an effective method to reduce hardware complexity [27–31].The interval [8 : 16376] is divided, as shown in Figure3, into four nonuniform intervals, I1,…,I4. In each interval, a linear function yi approximates σk,t as follows:
(14)yi=qi-mi·σk,t2σk,t2∈Ii
with i=1,…,4 and qi,mi>0. In order to simplify the hardware, the mi coefficients are quantized as powers of two and the multiplication between mi and σk,t2 is performed by using a shifter resulting in lower area utilization and higher working frequency.Figure 3
Piecewise linear polynomial approximation of theσk,t function implemented in the “Standard Deviation” block of Figure 2.


### 5.3. IFitness

It computesIFk,t according to (12).The circuit is actually a combinatorial shifter that shiftsσk,t2 as a function of the nk,t value and obtains the IFk,t factor.The proposed formulation of the GMM equations, that use (4) and (12) computed by the “learning rate” and “IFitness” block, implemented on Virtex5 vlx50 FPGA requires 64 Slices. This result can be compared with the implementation of (4) and (1) (the technique used in [22]) that, on the same FPGA, requires 123 Slices and 3 DSP. This demonstrates that the new formulation of the GMM algorithm equations is effective in reducing circuit complexity.


### 5.4. Match

It verifies the match condition for the three Gaussian distributions and is composed by three identical units (one for each Gaussian). Each unit implements (15) and employs a subtractor and one comparator as follows:
(15)Mk=1if|pixel-μk,t|<2.5·σk,t.


### 5.5. Control Logic

It sorts the Gaussians in increasingIFk,t order and establishes which Gaussian has to be updated as in (3), (6), and (7).


### 5.6. Parameter Update

This circuital block is composed by five subunits (“Weight”, “Mean”, “Variance” “No Match”, and “Matchsum”) that implement the parameters update equations (3), (6), and (7) detailed in Section 2.


#### 5.6.1. “Weight” and “Mean”

If the match condition is verified, these blocks update the parameters according to (3) and (6). The quantization of the learning rates as power of two allows to implement (3) by using shifters instead of multipliers.


#### 5.6.2. “Variance”

The left hand of the variance update equation of  (3) requires the computation of a square. In the proposed circuit the square has been implemented by using a truncated multiplier [26].Truncated binary multipliers, for which the optimality in terms of mean square error is analytically demonstrated, have been proposed in [23–26]. Truncated multipliers have been used with good results in a variety of applications [33–35]. A full-width digital n×n bits multiplier computes the 2n bits output as a weighted sum of partial products. A truncated multiplier is an n×n multiplier with an m<2n bits output.In the proposed circuit the inputs of the multipliers are represented on 12 bits. The output of a12×12 full-width multiplier is hence on 24 bits. In order to reduce HW complexity and improve circuit speed, the proposed circuit implements a truncated binary multiplier, based on the architecture proposed in [24], in which the output is directly produced on 15 bits (9 less-significant bits are discarded with an almost 40% reduction of the required HW for the multiplier).


#### 5.6.3. “No Match”

When no Gaussians match the pixel, the “No Match” block updates the parameters of the Gaussian with highestIFitness value according to (7). Equation (7) requires the calculation of the inverse of the msumtot signal. In [22] a ROM-based approach is used to implement the required function. Since the msumtot signal is represented on 6 bits and its inverse is on 8 bits, the ROM size is equal to 26×8.In the proposed paper the ROM is eliminated by using a piecewise linear approximation technique similar to those used for the calculation of theσk,t signals. The msumtot signal range [1 : 63] is divided into four nonuniform intervals Ji and in each interval, a function zi approximates 1/msumtot as follows:
(16)zi=λi-ηi·msumtot,msumtot∈Ji,
with i=1,…,4,λi,  ηi>0, and ηi quantized as power of two so that the multiplication between ηi and msumtot is performed using a shifter.


#### 5.6.4. “Matchsum”

This is the circuit that updates thematchsum signal according to (3) and (7). The matchsum signal is a counter, associated to every Gaussian, introduced in the OpenCV with the aim to improve the initial learning phase of the GMM algorithm (as demonstrated in [22]). The matchsum signal counts the number of times that a given Gaussian is matched according to (2). The introduction of the matchsum entails the synthesis of three counters that are not on the critical path. The only drawback is an increase of circuit area.


### 5.7. Output Selection

It establishes the values of the updated parameters depending on whether the match condition is verified or not.


### 5.8. Bg Identification

It verifies the background identification condition shown in (8) determining, also as a function of the “No Match” condition, if the input pixel belongs to the background or not.


## 5.1. Learning Rate

Computesαk,t following (4).The “learning rate” unit is implemented with three ROM, each of them stores the power of two values that better approximatesαk,t as a function of wk,t ((4), (11)). The equation implemented by the ROM is
(13)nk,t=round[log2(αk,t)]
in which the function “round(·)” is the approximation to the nearest integer value. The nk,t values are then used by the “IFitness” unit to shift the σk,t in order to calculate the IFk,t factor according to (12).


## 5.2. Standard Deviation

The formulation of the GMM equations described in Section4 requires the standard deviation values, σk,t, for the three Gaussians while the input data for the circuit include the variance values, σk,t2.The “Standard Deviation” block determines the variance values by implementing a square root circuit.In the proposed implementation theσk,t2 signals are represented on 11 bits and range in [8 : 16376]. Due to the reduced number of bits of the variance signal, a ROM implementation for the square root circuit could be feasible but not optimal. In this paper the square root function has instead been implemented by using a piecewise linear approximation of the nonlinear function, a technique that has been previously proposed as an effective method to reduce hardware complexity [27–31].The interval [8 : 16376] is divided, as shown in Figure3, into four nonuniform intervals, I1,…,I4. In each interval, a linear function yi approximates σk,t as follows:
(14)yi=qi-mi·σk,t2σk,t2∈Ii
with i=1,…,4 and qi,mi>0. In order to simplify the hardware, the mi coefficients are quantized as powers of two and the multiplication between mi and σk,t2 is performed by using a shifter resulting in lower area utilization and higher working frequency.Figure 3
Piecewise linear polynomial approximation of theσk,t function implemented in the “Standard Deviation” block of Figure 2.


## 5.3. IFitness

It computesIFk,t according to (12).The circuit is actually a combinatorial shifter that shiftsσk,t2 as a function of the nk,t value and obtains the IFk,t factor.The proposed formulation of the GMM equations, that use (4) and (12) computed by the “learning rate” and “IFitness” block, implemented on Virtex5 vlx50 FPGA requires 64 Slices. This result can be compared with the implementation of (4) and (1) (the technique used in [22]) that, on the same FPGA, requires 123 Slices and 3 DSP. This demonstrates that the new formulation of the GMM algorithm equations is effective in reducing circuit complexity.


## 5.4. Match

It verifies the match condition for the three Gaussian distributions and is composed by three identical units (one for each Gaussian). Each unit implements (15) and employs a subtractor and one comparator as follows:
(15)Mk=1if|pixel-μk,t|<2.5·σk,t.


## 5.5. Control Logic

It sorts the Gaussians in increasingIFk,t order and establishes which Gaussian has to be updated as in (3), (6), and (7).


## 5.6. Parameter Update

This circuital block is composed by five subunits (“Weight”, “Mean”, “Variance” “No Match”, and “Matchsum”) that implement the parameters update equations (3), (6), and (7) detailed in Section 2.


### 5.6.1. “Weight” and “Mean”

If the match condition is verified, these blocks update the parameters according to (3) and (6). The quantization of the learning rates as power of two allows to implement (3) by using shifters instead of multipliers.


### 5.6.2. “Variance”

The left hand of the variance update equation of  (3) requires the computation of a square. In the proposed circuit the square has been implemented by using a truncated multiplier [26].Truncated binary multipliers, for which the optimality in terms of mean square error is analytically demonstrated, have been proposed in [23–26]. Truncated multipliers have been used with good results in a variety of applications [33–35]. A full-width digital n×n bits multiplier computes the 2n bits output as a weighted sum of partial products. A truncated multiplier is an n×n multiplier with an m<2n bits output.In the proposed circuit the inputs of the multipliers are represented on 12 bits. The output of a12×12 full-width multiplier is hence on 24 bits. In order to reduce HW complexity and improve circuit speed, the proposed circuit implements a truncated binary multiplier, based on the architecture proposed in [24], in which the output is directly produced on 15 bits (9 less-significant bits are discarded with an almost 40% reduction of the required HW for the multiplier).


### 5.6.3. “No Match”

When no Gaussians match the pixel, the “No Match” block updates the parameters of the Gaussian with highestIFitness value according to (7). Equation (7) requires the calculation of the inverse of the msumtot signal. In [22] a ROM-based approach is used to implement the required function. Since the msumtot signal is represented on 6 bits and its inverse is on 8 bits, the ROM size is equal to 26×8.In the proposed paper the ROM is eliminated by using a piecewise linear approximation technique similar to those used for the calculation of theσk,t signals. The msumtot signal range [1 : 63] is divided into four nonuniform intervals Ji and in each interval, a function zi approximates 1/msumtot as follows:
(16)zi=λi-ηi·msumtot,msumtot∈Ji,
with i=1,…,4,λi,  ηi>0, and ηi quantized as power of two so that the multiplication between ηi and msumtot is performed using a shifter.


### 5.6.4. “Matchsum”

This is the circuit that updates thematchsum signal according to (3) and (7). The matchsum signal is a counter, associated to every Gaussian, introduced in the OpenCV with the aim to improve the initial learning phase of the GMM algorithm (as demonstrated in [22]). The matchsum signal counts the number of times that a given Gaussian is matched according to (2). The introduction of the matchsum entails the synthesis of three counters that are not on the critical path. The only drawback is an increase of circuit area.


## 5.6.1. “Weight” and “Mean”

If the match condition is verified, these blocks update the parameters according to (3) and (6). The quantization of the learning rates as power of two allows to implement (3) by using shifters instead of multipliers.


## 5.6.2. “Variance”

The left hand of the variance update equation of  (3) requires the computation of a square. In the proposed circuit the square has been implemented by using a truncated multiplier [26].Truncated binary multipliers, for which the optimality in terms of mean square error is analytically demonstrated, have been proposed in [23–26]. Truncated multipliers have been used with good results in a variety of applications [33–35]. A full-width digital n×n bits multiplier computes the 2n bits output as a weighted sum of partial products. A truncated multiplier is an n×n multiplier with an m<2n bits output.In the proposed circuit the inputs of the multipliers are represented on 12 bits. The output of a12×12 full-width multiplier is hence on 24 bits. In order to reduce HW complexity and improve circuit speed, the proposed circuit implements a truncated binary multiplier, based on the architecture proposed in [24], in which the output is directly produced on 15 bits (9 less-significant bits are discarded with an almost 40% reduction of the required HW for the multiplier).


## 5.6.3. “No Match”

When no Gaussians match the pixel, the “No Match” block updates the parameters of the Gaussian with highestIFitness value according to (7). Equation (7) requires the calculation of the inverse of the msumtot signal. In [22] a ROM-based approach is used to implement the required function. Since the msumtot signal is represented on 6 bits and its inverse is on 8 bits, the ROM size is equal to 26×8.In the proposed paper the ROM is eliminated by using a piecewise linear approximation technique similar to those used for the calculation of theσk,t signals. The msumtot signal range [1 : 63] is divided into four nonuniform intervals Ji and in each interval, a function zi approximates 1/msumtot as follows:
(16)zi=λi-ηi·msumtot,msumtot∈Ji,
with i=1,…,4,λi,  ηi>0, and ηi quantized as power of two so that the multiplication between ηi and msumtot is performed using a shifter.


## 5.6.4. “Matchsum”

This is the circuit that updates thematchsum signal according to (3) and (7). The matchsum signal is a counter, associated to every Gaussian, introduced in the OpenCV with the aim to improve the initial learning phase of the GMM algorithm (as demonstrated in [22]). The matchsum signal counts the number of times that a given Gaussian is matched according to (2). The introduction of the matchsum entails the synthesis of three counters that are not on the critical path. The only drawback is an increase of circuit area.


## 5.7. Output Selection

It establishes the values of the updated parameters depending on whether the match condition is verified or not.


## 5.8. Bg Identification

It verifies the background identification condition shown in (8) determining, also as a function of the “No Match” condition, if the input pixel belongs to the background or not.


## 6. Results

### 6.1. CAD Tools for Design and Test

The proposed FPGA implementation of the OpenCV GMM algorithm is synthesized and implemented on Virtex6 (xc6vlx75t), Virtex5 (xc5vlx50), and Spartan3 (xc3s1000) Xilinx FPGA and on Stratix IV (SGX230HF35C2) Altera FPGA. The performances of the proposed circuit on FPGA devices and the comparison with previous art are shown in Table1.Table 1
Performances of the circuit of Figure2 implemented on different FPGA and comparison with previous art.
Target FPGA
Circuit
LUT/ALUT
Flip Flop
Slice/LAB
DSP/MULT
Frequency (MHz)
HD fps
Virtex6 (xc6vlx75t)
proposed circuit
922/46560
0/93120
265/11640
0/288
97.19
46
Virtex5 (xc5vlx50)
proposed circuit
844/28800
0/28800
301/7200
0/48
91.03
43
Reference [22]
705/28800
0/28800
313/7200
10/48
51.30
24
StratixIV (SGX230HF35C2)
proposed circuit
1150/182400
0/182400
81/9120
0/1288
98.12
47
Spartan3 (xc3s1000)
proposed circuit
1797/15360
0/15360
1010/7680
0/24
35.30
17For Virtex6, Virtex5, and Spartan3 the synthesis has been carried out using XST and fitting and Place&Route have been carried out using ISE. The implementation on StratixIV has been conducted with Quartus II. ModelSim PE has been used to perform the circuit simulations.


### 6.2. Quality of the Processed Video Streams

The implementation of (12), the utilization of truncated multipliers, and the implementation of ROM approximation techniques could worsen the accuracy of the processed video streams. Figure 4 shows a selection of frames with resolution 320×240 extracted from two video sequences. The original frames of Figures 4(a) and 4(d) have been processed by using the proposed implementation (Figures 4(b) and 4(e)) or by using the circuit of [22] that uses full-width multipliers and no ROM compression techniques (Figures 4(c) and 4(f)). The Bg masks of Figures 4(b), 4(e), and 4(c), 4(f) differ in few pixels (in both the video sequences less than the 1% of the total number of the pixels is differently classified by the two circuits). This demonstrates that the proposed implementation provides negligible effect on the quality of the processed video streams.Figure 4
Comparison between the Bg masks obtained with the circuit of [22] and with the proposed implementation. (a),(d) unprocessed video frames; (b),(e) output of the proposed circuit; (c),(f) output of the circuit proposed in [22].


### 6.3. Circuit Performances

Table1 shows that the circuit of Figure 2, implemented on high-performances FPGA devices, is able to process more than 43 HD fps by using less than the 5% of the FPGA resources. Implemented on Virtex6 processes 46 HD fps by using the 2% of the total number of Slice of the FPGA. On Virtex5 the frame rate is 43 HD fps while the logic utilization is equal to 301 of 7200 Slices, when implemented on StratixIV processes 47 HD fps by using less than the 1% of Logic Adaptive Blocks (LAB).The performances analysis has been conducted by including input and output registers that synchronize the circuits and provide timing performances that are not dependent on the I/O pads. The reported frame rate values are obtained by considering the maximum work frequency of the circuits (Frequency in Table1), obtained by imposing a constraint on the minimum period of the clock signal. For each implementation of Table 1, the synthesis of the circuit has been carried out by repeatedly reducing the constraint. The process has been stopped when a 0.1 ns reduction made the implementation impossible. The last synthesized clock period has determined the maximum work frequency of the circuit. The timing analysis of the obtained implementations has allowed to identify the critical path of the circuit that includes “Match,” “Control Logic,” “Variance,” and “Output Selection” units of Figure 2. However, the very closed constraint on the minimum clock period entails that all the paths between inputs and outputs of the circuit have delay values almost equal to the maximum delay.The previous art of the background identification circuits is represented by [22] that provides improved performances if compared against [17–21].The proposed FPGA implementation, as shown in Table1 outperforms the circuit proposed in [22]. Since that the proposed circuit improves many blocks that in [22] was on the critical path, when the proposed circuit is implemented on Virtex5 xc5vlx50, the maximum working frequency almost doubles (+77.4%), while the area utilization is strongly reduced (−3.8% in number of used Slices and zero DSP used versus 10 DSP).Table1 also shows the performances of the circuit on low-cost Spartan3 FPGA. Implemented on Spartan3, the proposed circuit is able to run at 35.30 MHz by using the 13% of the total number of Slice of the FPGA.


## 6.1. CAD Tools for Design and Test

The proposed FPGA implementation of the OpenCV GMM algorithm is synthesized and implemented on Virtex6 (xc6vlx75t), Virtex5 (xc5vlx50), and Spartan3 (xc3s1000) Xilinx FPGA and on Stratix IV (SGX230HF35C2) Altera FPGA. The performances of the proposed circuit on FPGA devices and the comparison with previous art are shown in Table1.Table 1
Performances of the circuit of Figure2 implemented on different FPGA and comparison with previous art.
Target FPGA
Circuit
LUT/ALUT
Flip Flop
Slice/LAB
DSP/MULT
Frequency (MHz)
HD fps
Virtex6 (xc6vlx75t)
proposed circuit
922/46560
0/93120
265/11640
0/288
97.19
46
Virtex5 (xc5vlx50)
proposed circuit
844/28800
0/28800
301/7200
0/48
91.03
43
Reference [22]
705/28800
0/28800
313/7200
10/48
51.30
24
StratixIV (SGX230HF35C2)
proposed circuit
1150/182400
0/182400
81/9120
0/1288
98.12
47
Spartan3 (xc3s1000)
proposed circuit
1797/15360
0/15360
1010/7680
0/24
35.30
17For Virtex6, Virtex5, and Spartan3 the synthesis has been carried out using XST and fitting and Place&Route have been carried out using ISE. The implementation on StratixIV has been conducted with Quartus II. ModelSim PE has been used to perform the circuit simulations.


## 6.2. Quality of the Processed Video Streams

The implementation of (12), the utilization of truncated multipliers, and the implementation of ROM approximation techniques could worsen the accuracy of the processed video streams. Figure 4 shows a selection of frames with resolution 320×240 extracted from two video sequences. The original frames of Figures 4(a) and 4(d) have been processed by using the proposed implementation (Figures 4(b) and 4(e)) or by using the circuit of [22] that uses full-width multipliers and no ROM compression techniques (Figures 4(c) and 4(f)). The Bg masks of Figures 4(b), 4(e), and 4(c), 4(f) differ in few pixels (in both the video sequences less than the 1% of the total number of the pixels is differently classified by the two circuits). This demonstrates that the proposed implementation provides negligible effect on the quality of the processed video streams.Figure 4
Comparison between the Bg masks obtained with the circuit of [22] and with the proposed implementation. (a),(d) unprocessed video frames; (b),(e) output of the proposed circuit; (c),(f) output of the circuit proposed in [22].


## 6.3. Circuit Performances

Table1 shows that the circuit of Figure 2, implemented on high-performances FPGA devices, is able to process more than 43 HD fps by using less than the 5% of the FPGA resources. Implemented on Virtex6 processes 46 HD fps by using the 2% of the total number of Slice of the FPGA. On Virtex5 the frame rate is 43 HD fps while the logic utilization is equal to 301 of 7200 Slices, when implemented on StratixIV processes 47 HD fps by using less than the 1% of Logic Adaptive Blocks (LAB).The performances analysis has been conducted by including input and output registers that synchronize the circuits and provide timing performances that are not dependent on the I/O pads. The reported frame rate values are obtained by considering the maximum work frequency of the circuits (Frequency in Table1), obtained by imposing a constraint on the minimum period of the clock signal. For each implementation of Table 1, the synthesis of the circuit has been carried out by repeatedly reducing the constraint. The process has been stopped when a 0.1 ns reduction made the implementation impossible. The last synthesized clock period has determined the maximum work frequency of the circuit. The timing analysis of the obtained implementations has allowed to identify the critical path of the circuit that includes “Match,” “Control Logic,” “Variance,” and “Output Selection” units of Figure 2. However, the very closed constraint on the minimum clock period entails that all the paths between inputs and outputs of the circuit have delay values almost equal to the maximum delay.The previous art of the background identification circuits is represented by [22] that provides improved performances if compared against [17–21].The proposed FPGA implementation, as shown in Table1 outperforms the circuit proposed in [22]. Since that the proposed circuit improves many blocks that in [22] was on the critical path, when the proposed circuit is implemented on Virtex5 xc5vlx50, the maximum working frequency almost doubles (+77.4%), while the area utilization is strongly reduced (−3.8% in number of used Slices and zero DSP used versus 10 DSP).Table1 also shows the performances of the circuit on low-cost Spartan3 FPGA. Implemented on Spartan3, the proposed circuit is able to run at 35.30 MHz by using the 13% of the total number of Slice of the FPGA.


## 7. Conclusion

An OpenCV compatible hardware implementation of the GMM algorithm for Bg identification is presented in the paper. The circuit has been designed having commercial FPGA devices as a target and is able to process 1080p video at 47 frames per second when implemented on Statix IV FPGA.The circuit exploits an innovative formulation of the equations of the GMM algorithm, approximates some nonlinear functions with piecewise linear polynomials, and uses truncated binary multipliers. The circuit is implemented on both Altera and Xilinx FPGA and, when compared with previously proposed Bg identification circuits, provides improved speed and reduced logic utilization.



---

*Source: 129589-2013-02-14.xml*