Application of image processing technology in the classroom energy-saving system

In this paper, image processing technology is applied to the field of classroom energy-saving. After the preprocessing of classroom images, we utilize SOPC based on the Nios II embedded soft-core processor, in order to acquire the number and position of students through illumination detection, image segmentation and template matching achieved by the sequential similarity detection algorithm (SSDA). Then the signal to control the switches of electrical appliances intelligently will be output through SOPC of FPGA. With the effective combination of hardware and software, the system achieves the intelligent control of electrical appliances such as lights in the classroom, which covers the shortage of the energy management of the classroom.


Introduction
Promoting efficient energy-saving system is one of the key national energy-saving projects. Recently, many systems based on the microcontroller, photoelectric sensors and timers to achieve large-scale college electrical control have come out. However, most of these systems have a minus side that they are unable to be controlled intelligently according to actual personnel distribution. The classroom energy-saving system in this paper combines the template matching of image processing with SOPC technology, which can avoid the effect.

Image gray processing
The color images captured by the camera can be converted to gray-value images. Grayscale is as in equation (1).
where, R, G, B, respectively, refers to the red, green and blue value of the color pixel, and Y refers to the gray value.
Image graying can not only retain the distribution of students in color images, but also save storage space, thereby reducing the computation and improving the efficiency of the algorithm.

Image filtering
In order to eliminate the noise generated during image acquisition, the median filter is used to filter. The gray value after filtering is as in equation (2).
refers to the gray value entered, and W indicates the area where the template is located. The system uses a 3 by 3 square window which slides pixel by pixel along the line of image data. All pixels in the window are sorted by gray value after sliding, and the median of the data group is replaced by the gray value of the pixel in the center of the original window.
Median filtering can protect the edge of the image better without affecting subsequent analysis. The influence of the photographing angle should be eliminated by geometric correction ultimately.

Coordinate mapping and illumination detection
Establish a rectangular coordinate system at the level of the classroom. The gray value of all points in the plane of a seat is composed of the illuminance matrix of the seat as in equation (3). The illuminance matrix of each seat makes up the illumination matrix of the whole classroom as in equation (4), where ij A represents the illuminance matrix of the seat in row i, column j, and p, q are the number of rows and columns of seats in the classroom, respectively.
The illuminance matrix is used to calculate average illuminance in the classroom. If it is greater than 180, it is considered that the illuminance is sufficient, and the illuminator will not is be required. Otherwise, proceed to the next image processing.

Complete and access to the template library
In order to overcome the mismatching of single template matching in traditional algorithm, multitemplate matching method is used in this paper. Set in the center of the classroom ceiling, the camera captures images of the classroom in various situations. Cut out the area of the student's head as a sample. Standardize the scale of the head sample to get the original template. Repeat the above process, and eventually the original template library about students' heads with different genders, hairstyles, and angles will be completed.
To storage and access to the template library, hash tables are chosen, for they turn out to be on average more efficient than search trees or any other table look-up structure in many situations. Given a key, the average RGB value of an image, the algorithm computes an index that suggests where the entry can be found. A template in memory is supposed to be found according to the record number stored in the first address of the conflict queue at the hash entry address table and compares the image with the template. If they matched, it will return information about this template. Otherwise, it continues to find the next queue element pointed by the first record of the conflict queue and compare until the tail of the conflict queue is found. The way of storing and searching the template can save a lot of storage space and improve the search efficiency.

The sequential similarity detection algorithm (SSDA)
As the size of a student's head in the image is small, the sequential similarity detection algorithm is used to reduce the amount of computation at each position to be matched. Complete the following steps.
Set the upper left corner of the image S to be tested to the initial position. Shift the template T stacked on the image S. Compute the average value of the template bitmap pixels and the covered area of the image S respectively. Calculate the error ε between a pixel randomly selected in the coverage area and the corresponding points in the template T. Select the next pixel at random and add up the error value. When it adds r times and the sum of the errors exceeds the threshold, stop accumulating and record the number of times r. Define the SSDA test surface as in equation (5). Only at this point can the total error exceed. According to the above method, all the matching points can be found out, and the location of the personnel in the image is determined.
According to the actual area of the classroom and the location of the corridors, the image is divided into several sub-regions that do not intersect. Do template matching for each region using the above algorithm.

Switch control system
The system applies NiosⅡ to FGPA which is illustrated as in Figure 1 and its hardware platform design is completed with EP1C6Q as the core. The memory system includes FLASH and SDRAM; the peripheral interface includes the serial interface and JTAG interface based on MAX3232. The distribution and the total number of students are displayed on LCD screen. Chances are that a lot of memory will be occupied when every pixel is processed by NiosⅡ to meet the high requirement of timeliness. In order to release NiosⅡ from heavy data transmission, DMA Controller is put into use to complete the transmission of image data. At the same time, VGA Controller adopts data flow transmission so as to realize efficient data transmission. Quartus Ⅱ , SOPC Builder and other development software help realize the system software design. After the template matching, the number of students in each region is output on the FPGA display screen, and the system controls the light switch in the area according to whether someone is there. Program flow chart is as shown in Figure 2.

Conclusion
The system can detect the number and position of students in the classroom immediately and precisely. Lights are turned on automatically for the corresponding regions according to the position of students where the illumination is insufficient, while lights are turned off when no one is there, through which the shortcoming of classroom power management is offset and energy saving is achieved autonomously.
The system has the template library and the template looking-up method based on the hash table in the aspect of personnel positioning, matching the image of the district with the corresponding template using SSDA, after which it outputs the number and the position of students. It builds the hardware platform on the basis of the FPGA outputting personnel information and control signals for each region.
One of the innovation points is the improvement of traditional template matching algorithm, benefited from which the system can meet the dual demand for accuracy and timeliness better, so that it will be promoted in national universities.