Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #http://192.168.194.148/capture?
- import urllib.request
- import numpy as np
- import cv2 as cv
- import serial
- import time
- frame = None
- key = None
- print('START')
- fire_cascade = cv.CascadeClassifier('fire_detection.xml')
- #fire_detection.xml file & this code should be in the same folder while running the code
- ser1 = serial.Serial('COM8',9600)#change COM port number on which your arduino is connected
- #cap = cv.VideoCapture(0)
- while 1:
- imgResponse = urllib.request.urlopen ('http://192.168.194.148/capture?')
- imgNp = np.array(bytearray(imgResponse.read()),dtype=np.uint8)
- frame= cv.imdecode (imgNp,-1)
- #ser1.write('0')
- #ret, img = cap.read()
- #cv.imshow('imgorignal',img)
- gray = cv.cvtColor(frame,cv.COLOR_BGR2GRAY)
- fire = fire_cascade.detectMultiScale(frame, 1.2, 5)
- for (x,y,w,h) in fire:
- cv.rectangle(frame,(x,y),(x+w,y+h),(0,0,255),2)
- roi_gray = gray[y:y+h, x:x+w]
- roi_color = frame[y:y+h, x:x+w]
- print ('Fire is detected..!')
- ser1.write(bytes('p', 'utf-8'))
- time.sleep(0.2)
- cv.imshow('Window',frame)
- #cv.imshow('img',img)
- ser1.write(bytes('s', 'utf-8'))
- k = cv.waitKey(30) & 0xff
- if k == 27:
- break
- #cap.release()
- cv.destroyAllWindows()
- print('TNE END')
Add Comment
Please, Sign In to add comment