You are on page 1of 8

from time import sleep

import time

import serial

from tensorflow.keras.models import Sequential

import numpy as np

from tensorflow.keras.layers import MaxPool2D

import argparse

from tensorflow.keras.layers import Conv2D

import cv2

from tensorflow.keras.layers import Flatten

import requests

from imutils.video import VideoStream

import imutils

from tensorflow.keras.layers import Dense

from tensorflow.keras.layers import Dropout

from tensorflow.keras.datasets import mnist

#loading data

(i_train,j_train) , (i_test,j_test)=mnist.load_data()

#reshaping data

i_train = i_train.reshape((i_train.shape[0], i_train.shape[1], i_train.shape[2], 1))

i_test = i_test.reshape((i_test.shape[0],i_test.shape[1],i_test.shape[2],1))

#checking the shape after reshaping

print(i_train.shape)

print(i_test.shape)

#normalizing the pixel values

i_train=i_train/255

i_test=i_test/255
def modRepeatedStratifiedKFold():

curr_row=0

row_array = []

while curr_row < num_rows:

row = worksheet.row(curr_row+1)

row_array += row

curr_row += 1

#print(row_array)

cv = RepeatedStratifiedKFold(n_splits=10, n_repeats=3)

return cv

# evaluate a given model using cross-validation

def evaluate_model(model, fire, errorratio):

# define the evaluation procedure

cv=modRepeatedStratifiedKFold()

# evaluate the model and collect the results

scores = cross_val_score(model, X, y, scoring='accuracy', cv=cv, n_jobs=-1)

return scores

j=0

uf=0

area1=0.0

area2=0.0

boundaries = [

([0, 0, 100], [70, 70, 255]),

([0, 100, 4], [88, 255, 50])

]
webcam = cv2.VideoCapture(0)

while(True):

check, frame = webcam.read()

cv2.imwrite(filename='fire.png', img=frame)

image = cv2.imread("fire.png")

for (lower, upper) in boundaries:

# create NumPy arrays from the boundaries

lower = np.array(lower, dtype = "uint8")

upper = np.array(upper, dtype = "uint8")

# find the colors within the specified boundaries and apply

# the mask

mask = cv2.inRange(image, lower, upper)

contours,hierarchy = cv2.findContours(mask, cv2.RETR_TREE, cv2.CHAIN_APPROX_NONE)

#print(mask)

output = cv2.bitwise_and(image, image, mask = mask)

for contour in contours:

cv2.drawContours(image, contour, -1, (0, 255, 0), 1)

#print(boundaries[j])

j=1

print(j)

for pic, contour in enumerate(contours):

area = cv2.contourArea(contour)

if area>0 :

print('Area=' + str(area))
#print(area)

#print(j)

if j == 1:

area1=area

if area1 > 800:

print("fire")

break

cv2.imshow("Frame", image)

b, g, r = cv2.split(output)

cv2.imshow('B',b)

cv2.imshow('G',g)

cv2.imshow('R',r)

cv2.imshow("images", np.hstack([image, output]))

cv2.waitKey(0)

cv2.destroyAllWindows()

You might also like