Android-based video surveillance system design and implementation

Source: Internet
Author: User

Currently, the video monitoring system is evolving towards Digitalization, networking, and function integration. Most traditional video surveillance systems use cables orOptical FiberThe video signal is transmitted to the monitoring center. However, due to network cable restrictions, it is not conducive to the rapid establishment of the monitoring system. With the popularization of wireless networks, especially 3G networks, video surveillance systems are facing a wider and free space [1].
The bandwidth supported by 3G networks in mobile environments is limited, while the real-time performance of video monitoring systems requires that video signals be transmitted as clearly and smoothly as possible. Therefore, to ensure that video signals are true, perform the maximum possible compression. H.264 adopts the high-precision and multi-mode prediction technology to increase the compression ratio and reduce the code stream [2]. It can be widely used in remote monitoring, teleconference, videophone, and other fields.
This article introduces a Video Monitoring System Based on Android, and uses PDA combined with H.264 encoding technology and 3G wireless network communication technology to achieve real-time monitoring of remote videos.
1. System Overview
1. The system uses a C/S architecture. The hardware includes a PDA with a camera and H.264EncoderAnd the background monitoring computer. The key technology of the system is the design of the encoder, which converts the captured analog signal into a digital signal through H. 264 encoder for encoding compression, and finally use 3G wireless network to transmit the compressed data to the background monitoring computer for real-time display. The background computer can also send control commands to PDA through 3G networks to implement cloud platform control and other related operations. This article mainly introduces the design and implementation of PDA.

2. Android operating system
Android is an open-source operating system based on Linux and is mainly used for portable devices. Android has a core library that provides Java programming language functions. Each Java-compiled application has an independent Dalvik Virtual Machine instance. Dalvik is designed as a device that can efficiently run multiple virtual systems at the same time. This feature makes the Android system well adaptedMobile phoneSpecial runtime environment. ThroughIPInstall android on SE
SDK plug-in allows you to easily build an android development platform. The Code Compiled on this platform can automatically generate an APK file and install and use it directly [3].
3. Implementation of PDA-side Video Processing
The most important part of the Android-based video surveillance system is the design of PDA and peripherals and video processing. PDA LimitedMemoryThis part of implementation is required to achieve low power consumption and high performance as much as possible to achieve optimization of algorithms and software.
BecauseDSPThe chip is highly programmable to facilitate later encoding comparison and optimization. Therefore, EncoderAdiThe company launched the DSP chip blackfin533. The chip integrates a large number of peripherals and memory interfaces, and optimizes the C/C ++ structure to achieve high code density and meet the requirements of H. 264 real-time Encoding requirements.
3.1 H.264 Algorithm Optimization
Compared with previous video encoding standards (such as H.263 and MPEG)Series) Only one or two macro block encoding modes are used. H.264 uses16Seven Macro Block encoding modes from x 16 to 4x4 save H.263 the bit rate by about 264. But at the same time, it is facing a considerable amount of computing consumption [4]. To achieve real-time encoding, how to implement a fast Pattern Selection Algorithm becomes the key to solving the problem [5-6]. The Macro Block encoding mode of H.264/AVC applies a large number of traversal operations to increase the coding speed by appropriately reducing the traversal mode or terminating the traversal in advance. The key to reducing invalid traversal is to limit the range of traversal and develop reliable termination rules.
Curr is the macro block to be encoded. A, B, C, and D are adjacent macro blocks in four directions, a_cost, B _cost, c_cost, and d_cost are the encoding costs of A, B, C, and D respectively. The threshold T is calculated using formula (1:
T = (5 × A _ cost + 5 × B _ cost + 4 × C _ cost + 2 × A _ cost)> 4 (1)
Curr encodes the four adjacent macro blocks and their own macro blocks respectively, and obtains the optimal encoding by comparing their generation values. Figure 2 shows the optimized coding flowchart for macro blocks A and B (the code for macro blocks C and D is similar ). Through testing and comparison and optimization algorithm processing, videos can effectively reduce the compression ratio and increase the algorithm computing speed in the case of fidelity.

3.2 Software Design
The Android platform mainly includes the communication module and data processing module.
The communication module usesSocketNetwork communication technology for UDB communication. Preparations before communication are to create a socket, bind the socket and port number, and set the listening port. After the listener starts, the main program listens cyclically and receives request signals. At the same time, a new client connects to the socket and the corresponding communication process.
The data processing module extracts and transmits video stream data. After the camera is enabled, the data of each frame of the video stream is captured during video preview. Extract the interceptedData TransmissionThe image is drawn at the application layer and transmitted to the DSP chip through peripherals for video encoding. After encoding, the data is transmitted to the background monitoring room through the network. The core code of Android Application Layer [8] is as follows:
P0 = socket (af_inet, sock_dgram, ipproto_udp );
// Create a socket
BIND (P0, (struct sockaddr *)&Amp; (Addr_org), sizeof (struct sock-
Addr_in); // bind the IP address and port
Sendto (P0, senddatabuff, ullen, 0, (struct sockaddr *)&
(Addr_dst), sizeof (sockaddr_in ));
// Send video data in senddatabuff to a specified IP Address
Public imagesurfaceview (context, attributeset attrs)
{Paint = new paint (); paint. setcolor (color. White );
Paint. setantialias (true );
...... Setfocusable (true);} // initialize the surfaceview class
Public void surfacecreated (surfaceholder holder ){......
Screenh = This. getheight (); screenw = This. getwidth
(); Handler. Post (imagerunnable );}
// Create a surfaceview for displaying captured images
Camera opencamera () {}// open the camera
Android. Hardware. Camera. previewcallback
// Call the data interface of each frame of Image
The main purpose of software design in DSP chip is to improve the computing speed and efficiency. Macro Block encoding uses separate encoding at different locations. During programming, the judgment is transferred out of the loop as much as possible, avoiding repeated judgment of a large number of macro blocks within and between frames. The quick mode selection algorithm is used to encode macro blocks, further improving the coding efficiency. Video commands dedicated to blackfin533 chipsSAAReturns the sum of absolute difference values.Sad(), Greatly improving the computing speed. The specific code for using SAA is as follows:
For (I = 0; I ≪ 16*16; I ++)
Sad + = ABS (* psrc ++-* Pref ++ );
Lsetup (sad_start, sad_end) lc0 = p1;
Sad_start:
R3 = [I1 ++];
SAA (r1: 0, R3: 2) | R1 = [I0 ++] | r2 = [I1 ++];
SAA (r1: 0, R3: 2) (R) | R0 = [I0 ++] | R3 = [I1 ++];
SAA (r1: 0, R3: 2) | R1 = [I0 ++] | r2 = [I1 ++];
Sad_end: SAA (r1: 0, R3: 2) (R) | R0 = [I0 ++] | r2 =
[I1 ++]
4. Implementation result
Figure 3 showsHTCG14 mobile phones and background computers use the result of the 3G network experiment. Videos taken and previewed by the mobile phone are displayed on the computer. You can monitor the field of view of a mobile phone in the background, or use commands to zoom in or out the field of view. The entire process is not limited by distance. After multiple tests, the display of the PDA end and the background in the same frame only exists for 3 S ~ Latency of 5 s.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.