Created
February 28, 2022 06:23
-
-
Save ardadi/e6f9c41edd8937906375872b28dac958 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import cv2 | |
import RPi.GPIO as GPIO | |
import time | |
RelayA = [21, 20, 26] #CH1, CH2, CH3 | |
RelayB = [16, 19, 13] | |
GPIO.setmode(GPIO.BCM) | |
GPIO.setwarnings(False) | |
#GPIO.setup(RelayB, GPIO.OUT, initial=GPIO.LOW) | |
GPIO.setup(RelayA, GPIO.OUT, initial=GPIO.LOW) | |
time.sleep(0.5) | |
def gstreamer_pipeline( | |
capture_width=1280, | |
capture_height=720, | |
display_width=640, | |
display_height=480, | |
framerate=24, | |
flip_method=2, #flip_method=0 180 derece | |
): | |
return ( | |
"nvarguscamerasrc ! " | |
"video/x-raw(memory:NVMM), " | |
"width=(int)%d, height=(int)%d, framerate=(fraction)%d/1 ! " | |
"nvvidconv flip-method=%d ! " | |
"video/x-raw, width=(int)%d, height=(int)%d, format=(string)BGRx ! " | |
"videoconvert ! " | |
"video/x-raw, format=(string)BGR ! appsink drop=True" | |
% ( | |
capture_width, | |
capture_height, | |
framerate, | |
flip_method, | |
display_width, | |
display_height, | |
) | |
) | |
fire_cascade = cv2.CascadeClassifier('fire_detection.xml') | |
cap = cv2.VideoCapture(gstreamer_pipeline(), cv2.CAP_GSTREAMER) | |
while(True): | |
ret, frame = cap.read() | |
gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY) | |
fire = fire_cascade.detectMultiScale(frame, 1.03, 4) #1.05 ,4 --> çok sıkışırsa scale factor 1.15, minNeighbors artınca much faster, less accurate | |
#cv.CascadeClassifier.detectMultiScale( image[, scaleFactor[, minNeighbors[, flags[, minSize[, maxSize]]]]] | |
for (x,y,w,h) in fire: | |
cv2.rectangle(frame,(x-20,y-20),(x+w+20,y+h+20),(255,0,0),2) | |
roi_gray = gray[y:y+h, x:x+w] | |
roi_color = frame[y:y+h, x:x+w] | |
print("fire!") | |
""" | |
#fire çıktısını aldığında çalışacak | |
try: | |
while True: | |
print("turn off") | |
GPIO.output(RelayA, GPIO.LOW) | |
time.sleep(1) | |
print("turn on") | |
GPIO.output(RelayA, GPIO.HIGH) | |
time.sleep(10) #alarm suresi sn | |
except: | |
GPIO.output(RelayA, GPIO.LOW) #role NO kontak kullaniminda LOW, aksi halde HIGH | |
GPIO.cleanup() | |
""" | |
cv2.imshow('frame', frame) | |
if cv2.waitKey(1) & 0xFF == ord('q'): | |
break | |
cap.release() | |
cv2.destroyAllWindows() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment