<< Chapter < Page Chapter >> Page >

The construction of the difference density matrix as in Algorithm 3 is parallelized by considering the value of thethresholded difference matrix D' at each index (r; c), mapping that index to the appropriate index in the difference densitymatrix (i, j) where (i less than m) and (j less than n), then adding to the value of the array at (i, j) at each encounter of a difference pixel in D'.Our CUDA implementation therefore relies on the fact that the density array is initialized to 0 before the kernel is launched;this is accomplished in practice with a calloc operation on the host, followed by copying that array to GPU memory.

Listing 7. gpu computation of the difference density matrix

__global__ void spatial_difference_density_map( double *density_map,int *difference, int width,int height, int horizontal_divisions,int vertical_divisions ) {int r = blockIdx.y * blockDim.y + threadIdx.y; int c = blockIdx.x * blockDim.x + threadIdx.x;int i = r * width + c;int horizontal_block_size = width/horizontal_divisions; int vertical_block_size = height/vertical_divisions;int block_size = horizontal_block_size * vertical_block_size;const int scaling_factor = 1000; if (difference[i]!= 0) { int i = (int)(vertical_divisions * r/(double)height);int j = (int)(horizontal_divisions * c/(double)width); density_map[i * horizontal_divisions + j]+= scaling_factor/(double)block_size; }}

The generation of the motion area estimation image is relatively straightforward: we map the index (i, j) of D' back toan index (r, c) where (r less than M) and (c less than N), and set the value at that index high or low accordingly.

Listing 8. gpu generation of the motion area estimation image

__global__ void motion_area_estimate( int *motion_area,double *density_map, int width,int height, int horizontal_divisions,int vertical_divisions, double threshold) { int r = blockIdx.y * blockDim.y + threadIdx.y;int c = blockIdx.x * blockDim.x + threadIdx.x; int i = r * width + c;int density_map_index = (int)(vertical_divisions*r/(double)height) * horizontal_divisions + (int)(horizontal_divisions*c/(double)width);if (density_map[density_map_index]>= threshold) { motion_area[i]= 255; } else {motion_area[i] = 0;} }

High-level python implementation

The Python implementation of Algorithm 3 is very straightforward and looks almost exactly like the pseudo-code, makingit easy to implement even for those with minimal programming experience.

Listing 9. python implementation of the motion area estimation image

import numpy as npdef detect_motion(e1, e2): height, width, depth = np.shape(e1)d = difference(e1, e2) d_prime = np.zeros((M, N), np.uint8)for i in range(M): for j in range(N):x = 0 for i_prime in range(height/M):for j_prime in range(width/N): if d[i*height/M+i_prime, j*width/N+j_prime]!= 0: x += 1if M*N*x/(height*width*1.0)>T: d_prime[i, j]= 255 return d_prime

Facial recognition algorithm

Our facial recognition implementation is based off of the HAAR features-based cascade classifiers method proposed byViola-Jones in 2001. It’s split into two phases: training and detection. The algorithm is as follows:

Get Jobilize Job Search Mobile App in your pocket Now!

Get it on Google Play Download on the App Store Now




Source:  OpenStax, Elec 301 projects fall 2015. OpenStax CNX. Jan 04, 2016 Download for free at https://legacy.cnx.org/content/col11950/1.1
Google Play and the Google Play logo are trademarks of Google Inc.

Notification Switch

Would you like to follow the 'Elec 301 projects fall 2015' conversation and receive update notifications?

Ask