Video Analytics Using CIM Accelerators
|
Vehicle and foot traffic recognition and tracking. Picture credit KAIST IPSL
|
|
Car detected in non-traffic area. Picture credit RaidNet
|
|
Surveillance video anomaly detection. Picture credit Butler University, Information Sciences and Systems
|
Overview
Video analytics, also sometimes referred to as Video Content Analysis, is the capability to automatically analyze video to detect and
determine temporal events not based on a single image. That description is from Wikipedia, but it might be modified to include
"patterns and objects from one or more images, and temporal events from multiple images or stream of images". Without fundamental
pattern recognition and object detection, video content analysis cannot occur.
Applications
Video analytics, and its underlying foundation of object and pattern recognition, has many applications, including:
- Security
- Motion detection in a museum, store, bank, or other place secured for a period of time
- Recognizing a person of interest in a surveillance video (known as face recognition, or facial recognition)
- Robotics
- Object tracking, object recognition
- Location and mapping (sometimes referred to as SLAM, or Simultaneous Location and Mapping)
- Military
- Detecting recently disturbed earth or curbside debris along a road in order to identify a possible IED location
- Recognizing unusual activity, such as vehicle or foot traffic out of the ordinary
- Entertainment
- Automatically recognizing a video's content, regardless of its labeling, to detect copyright infringement
- Automatically recognizing and counting TV advertisements to ensure a radio or TV station has run ads they were paid to run by advertisers
Source Code Examples
Below are some video analytics source code examples, marked with CIM pragmas to accelerate compute-intensive sections of code. Note
that
CIM pragmas and API calls follow the OpenMP convention (highlighted in yellow below).
/* IIR Filter implementation from ffmpeg library, marked with CIM pragmas */
void ff_iir_filter(const struct FFIIRFilterCoeffs *c, struct FFIIRFilterState *s,
int size, const int16_t *src, int sstep, int16_t *dst, int dstep) {
int i;
if (c->order == 4) {
for (i=0; i<size; i+=4) {
float in, res;
FILTER(0, 1, 2, 3);
FILTER(1, 2, 3, 0);
FILTER(2, 3, 0, 1);
FILTER(3, 0, 1, 2);
}
else {
#pragma cim parallel for num_threads 4
for (i=0; i<size; i++) {
int j;
float in, res;
in = *src * c->gain;
for (j=0; j<c->order; j++)
in += c->cy[j] * s->x[j];
res = s->x[0] + in + s->x[c->order >> 1] * c->cx[c->order >> 1];
for (j=1; j<c->order>>1; j++)
res += (s->x[j] + s->x[c->order - j]) * c->cx[j];
for (j=0; j<c->order-1; j++)
s->x[j] = s->x[j + 1];
*dst = av_clip_int16(lrintf(res));
s->x[c->order - 1] = in;
src += sstep;
dst += sstep;
}
}
}
/* Discrete Cosine Transform (DCT) implementation from ffmpeg library, marked with CIM pragmas */
static void ff_dct_calc_III_c(DCTContext *ctx, FFTSample *data) {
int n = 1 << ctx->nbits;
int i;
float next = data[n - 1];
float inv_n = 1.0f / n;
#pragma cim parallel for num_threads 6
for (i=n-2; i>=2; i-=2) {
float val1 = data[i];
float val2 = data[i - 1] - data[i + 1];
float c = COS(ctx, n, i);
float s = SIN(ctx, n, i);
data[i] = c * val1 + s * val2;
data[i + 1] = s * val1 - c * val2;
}
}