## 4 High-Resolution Images in Camera-Based WMSNs
### Camera Sensor Node Selection Algorithm with Good Coverage and Minimum Energy Dissipation
#### 4.2.2 Fair Camera Node Selection Algorithm  
After first query from Sink, and having all necessary information (transformation matrixes and Coverage Data Structure) which have been sent to the related cluster head, cluster head selects subset of camera sensor nodes based on the Fair Camera Node Selection algorithm to respond to subsequent queries. Presented algorithm selects this subset in a way that each node is selected almost equal times in multiple queries. It avoids the early failure of some sensor nodes and consequently a good coverage of field is provided for a longer time. The steps of Fair Camera Node Selection are explained in the following:  
* _Initialization_: As mentioned before each camera sensor covers multiple grids, so after selecting a sensor to cover a specific grid cell, some other cells will be automatically covered by the same sensor and selecting another sensor to cover them is unnecessary. Accordingly, an array of flags called \"_Uncovered Grids_\" is needed to identify which grid cells are covered. Each element of this array corresponds to a grid cell and if an element in this array is marked (includes 1), it means that the corresponding grid cell is uncovered. If the element is unmarked (includes 0), it is covered by a camera in previous algorithm iterations. As is shown in Figure 6A, all elements of \"_Uncovered Grids_\" are marked (set to 1) at the beginning of the algorithm. In addition, \"_Start Grid_\" is a variable that identifies which grid cell must be covered first in this query and by each query it cycles between grid cells (see Figure 6A). This rotation between grid cells that changes the first grid cell to be covered causes a pseudo-random selection. Selected cameras are added to a set called \"_Active Set_\" which is empty at the beginning (see Figure 6A). * _Checking the Answer_: If there is no marked grid cell in \"_Uncovered Grids_\" as an uncovered one, the algorithm task is completed and desired answer is in the \"_Active Set_\". Otherwise, the grid cells which are uncovered must be covered in the next steps (see Figure 6B). * _Finding an Uncovered Grid Cell_: Here, as there is still uncovered grid cell(s), we are sure that another camera must be selected. \"_Selected Grid_\" is a variable that identifies the grid which must be covered now and was set to \"_Start Grid_\" at the start of algorithm (see Figure 6A). If the \"_Selected Grid_\" is already covered (see Figure 6C), it must be set as the next uncovered grid (see Figure 6D) and this process goes on until an uncovered grid cell is found. * _Camera Sensor Selection and Related Updates_: After the uncovered grid cell is found in previous step, in this step one of the cameras that cover it must be chosen. In the Coverage Data Structure, each grid cell has a list of sensor cameras covering it. First sensor node (header) in the sensor list of \"_Selected Grid_\" is selected as \"_Selected Sensor_\" and is added to the \"_Active set_\". After this, as each camera sensor covers more than one grid cell, corresponding elements of all grid cells covered by \"_Selected Sensor_\" are unmarked (set to 0) in the \"_Uncovered Grids_\". In addition, \"_Selected Sensor_\" is moved to the end of all sensor lists in the Coverage Data Structure in order to let the other sensors be selected in the next queries. To perform these tasks, a search through all lists is required (see Figure 6E). Then algorithm returns to _Checking the Answer_ step. Figure 6: Flowchart of fire camera node selection algorithm. At first it appears that using a random selection for uncovered grid cells instead of selecting them one after another (using \"_Start Grid_\" variable) is more fair but running tests have shown that they have no difference in results and all sensors are selected almost equal times. The result of this test is shown in subsection 5.2.