# HelpResponder--System for the Security of First Responder Interventions
## 4 Implementation of the Safe and Flame-Aware Intervention Architecture
### Fire Detection System
These objects will be used as seeds. The seeds are a related group of foreground pixels to make the Watershed. Then, the candidate regions are obtained to correspond to fire zones. ```
1. seed_objects_image = np.zeros(diff_image.shape, np.uint8)
2. contours = cv2.findContours(bin_actual_image_cv2.RETR_EXTERNAL_cv2 CHAN_APPROX_SIMPLE)
3. # Each connected region of the original image is overlapped to the image difference
4. for cnt in contours:
5. # The image with the connected region is created. 6. region_image = np.zeros(diff_image.shape, np.uint8)
7. cv2.drawContours(region_image, [cnt], \(-1\), \(255\), \(-1\))
8. # Image with foreground pixels being those that both in the image and in the region image are foreground
9. movement_region_image = cv2.bitwise_and(diff_image, diff_image, mask = region_image)
10. # if there is foreground pixels \(\rightarrow\) Si hay pixels de primer plano \(\rightarrow\) Add region to image
11. if not np.all(movement_region_image = 0):
```  
**Algorithm 1**********Pseudocode for for checking the regions of the current image to which moving pixels belong. The third stage focuses on obtaining the regions that are the real fire or flame; it is necessary to obtain their characteristics (FireAnalizer) and to discriminate small regions that are not of interest (the average intensity). The objective is to rule out regions that have passed the color filter but are not strong enough to be fire. The boundaries disorder is  
Figure 4: The pixel movement of the image. Figure 5: Block diagram of the pseudocode for checking the regions of the current image to which moving pixels belong. a parameter to analyze objects discarding objects with a regular shape of [37], centroids, and contours. A four-stage method (FireClassifier) is developed to consider the following discrimination tasks in the image processing:  
Discrimination by the region's shape: for this kind of classification, the area and boundary disorder parameters are used. The regions must exceed established threshold to be considered a fire or flame. Discrimination by intensity: as described above, to obtain the fire regions, we applied a color filter. The next ranges are used to determine the Boundary disorder, Area, and Intensity mean:  
\[0.7< Boundary\;disorder<0.95\quad 300<Area\quad 130<Intensity\;mean \tag{5}\]  
The fire detection depends on the conditions, but we have used some parameters (thresholds) to validate two different scenarios without changing these parameters in the paper. It relates to the list of parameters that should be adjusted in different environments. In this study, there are confined (indoor) spaces and an open space of approximately 70-130 square meters, simulating a small tunnel or a small gallery: a 120 m\({}^{2}\) gallery with an open space, for example used for parking. We previously analyzed different thresholds oriented to those scenarios. In this case, we use the following parameters: boundary disorder, intensity average, and area size. Moreover, we based the experiment on the hypothesis that in those kinds of scenarios, the context would not change significantly, so the algorithms' results would be similar. Regions meeting these conditions shall be considered as flames and shall be marked in the current input buffer image. In the last stage (FireVisualizer), the algorithm stores the characteristics of the regions classified as fire with their contours. These regions and contours are transferred to their representation. The metric used is important. Some works [38] in classification performance metrics were based on the binary confusion matrix. Below, the methodology to evaluate the results is explained. Firstly, we evaluate the accuracy of the process, detection metrics, and processing times. These were used as an evaluation metric. In a pattern recognition task, we needed to define the true positives and the false positives. We measured the accuracy of the flame detection at the region level and used the IoU (intersection over union) for our evaluation metrics.