safwan092

Untitled

Oct 30th, 2021 (edited)
1,113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.30 KB | None | 0 0
  1. #http://192.168.194.148/capture?
  2. import urllib.request
  3. import numpy as np
  4. import cv2 as cv
  5. import serial
  6. import time
  7.  
  8. frame = None
  9. key = None
  10.  
  11. print('START')
  12. fire_cascade = cv.CascadeClassifier('fire_detection.xml')
  13. #fire_detection.xml file & this code should be in the same folder while running the code
  14.  
  15. ser1 = serial.Serial('COM8',9600)#change COM port number on which your arduino is connected
  16.  
  17. #cap = cv.VideoCapture(0)
  18. while 1:
  19.     imgResponse = urllib.request.urlopen ('http://192.168.194.148/capture?')
  20.     imgNp = np.array(bytearray(imgResponse.read()),dtype=np.uint8)
  21.     frame= cv.imdecode (imgNp,-1)
  22.     #ser1.write('0')
  23.     #ret, img = cap.read()
  24.     #cv.imshow('imgorignal',img)
  25.     gray = cv.cvtColor(frame,cv.COLOR_BGR2GRAY)
  26.     fire = fire_cascade.detectMultiScale(frame, 1.2, 5)
  27.     for (x,y,w,h) in fire:
  28.         cv.rectangle(frame,(x,y),(x+w,y+h),(0,0,255),2)
  29.         roi_gray = gray[y:y+h, x:x+w]
  30.         roi_color = frame[y:y+h, x:x+w]
  31.         print ('Fire is detected..!')
  32.         ser1.write(bytes('p', 'utf-8'))
  33.         time.sleep(0.2)
  34.        
  35.     cv.imshow('Window',frame)
  36.     #cv.imshow('img',img)
  37.     ser1.write(bytes('s', 'utf-8'))
  38.    
  39.     k = cv.waitKey(30) & 0xff
  40.     if k == 27:
  41.         break
  42.  
  43. #cap.release()
  44. cv.destroyAllWindows()
  45. print('TNE END')
  46.  
Add Comment
Please, Sign In to add comment