フィルターのクリア

In the fire detection project, the code barely works, but when it detects the color, it considers it as fire as well,If you can help me add a condition for fire motion, I don'

1 回表示 (過去 30 日間)
clear all
close all
clc
object = VideoReader('123.avi');
framerate = get(object, 'FrameRate');
figure;
% Nom du dossier de sortie
output_folder = 'output_images';
if ~isfolder(output_folder)
mkdir(output_folder);
end
subplot(1,2,1); % Affichage de la vidéo originale à gauche
progress_bar = waitbar(0, 'Processing frames...');
max_frames = object.NumFrames; % Nombre maximal de frames à traiter
for k = 1:max_frames
single_frame = read(object, k);
img = rgb2ycbcr(single_frame);
sz = size(img);
Y = img(:,:,1);
Cb = img(:,:,2);
Cr = img(:,:,3);
fire_detected = false; % Variable pour vérifier si un feu a été détecté
for x = 1:sz(1)
for y = 1:sz(2)
if and(Cb(x,y) > 50, Cr(x,y) > 150)
fire_detected = true; % Un feu a été détecté
break;
end
end
if fire_detected
break;
end
end
subplot(1,2,1);
imshow(single_frame);
title('Vidéo originale');
if fire_detected
single_frame_modified_color = single_frame;
% Trouver les coordonnées des régions de feu détectées
single_frame_modified_bw = zeros(sz);
for x = 1:sz(1)
for y = 1:sz(2)
if and(Cb(x,y) > 50, Cr(x,y) > 150)
% canal rouge
single_frame_modified_bw(x,y,1) = 255;
% Copier les pixels du feu de la vidéo d'origine sur l'image modifiée
single_frame_modified_color(x,y,:) = single_frame(x,y,:);
end
end
end
% Trouver les coordonnées des régions de feu détectées
[labelCord, ~] = bwlabel(single_frame_modified_bw(:,:,1));
% Calculer les coordonnées du rectangle englobant toutes les régions de feu
[r, c] = find(labelCord > 0);
xmin = min(c);
xmax = max(c);
ymin = min(r);
ymax = max(r);
single_frame_modified_color = insertShape(single_frame_modified_color, 'Rectangle', [xmin, ymin, xmax-xmin, ymax-ymin], 'Color', 'red');
% Ajouter le texte "fire" en dehors du rectangle rouge
textPosition = [xmin, ymin-20];
single_frame_modified_color = insertText(single_frame_modified_color, textPosition, 'Fire', 'FontSize', 10, 'TextColor', 'white', 'BoxColor', 'red');
subplot(1,2,2);
imshow(single_frame_modified_color);
title('Détection de feu (Couleur)');
else
subplot(1,2,2);
imshow(single_frame);
title('Vidéo originale sans feu');
% Sauvegarder une image spécifique dans le répertoire de sortie
no_fire_image = zeros(sz);
output_filename = sprintf('aucuninc.jpg', k);
output_path = fullfile(output_folder, output_filename);
imwrite(no_fire_image, output_path);
end
pause(1/framerate);
waitbar(k / max_frames, progress_bar);
end
close(progress_bar);

回答 (1 件)

Ranjeet
Ranjeet 2023 年 6 月 28 日
Hi Mohammed,
The approach provide in the code applies thresholding to each pixel in an image and decides if there is fire or not in the image. This is a bit preliminary approach.
To have a robust fire detection system, have a look at the following resources:
  1. Fire detection for CCTV surveillance using YOLOV2
  2. Fire detection approaches – you may explore this resource to get an understanding what all techniques are doing best in the application.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!