메뉴 건너뛰기

목록
2022.12.05 23:15

이제 정상작동됨

profile
조회 수 18 댓글 0 예스잼 1 노잼 0

No Attached Image

import cv2

import time

import serial

import serial.tools.list_ports

 

my_serial = serial.Serial("COM7", baudrate=9600, timeout = 1.0)

time.sleep(2.0)

def send_buzzer(freq):

    sendData = f"BUZZER={freq}\n"

    my_serial.write( sendData.encode() )

 

def main():

    cam = cv2.VideoCapture(0)

    cam.set(3,640)

    cam.set(4,480)

 

    face_cascade = cv2.CascadeClassifier(cv2.data.haarcascades + 'haarcascade_frontalface_default.xml')

    eye_cascade = cv2.CascadeClassifier(cv2.data.haarcascades + 'haarcascade_eye.xml')

 

    sleep_count = 0

    while( cam.isOpened() ):

        _, image = cam.read()

        gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)

 

        faces = face_cascade.detectMultiScale(gray, scaleFactor=1.1,minNeighbors= 5,minSize=(50,50),

                                              flags=cv2.CASCADE_SCALE_IMAGE)

 

        if len(faces):

            for(x, y, w, h) in faces:

                cv2.rectangle(image,(x,y),(x+w,y+h),(255,0,0),2)

 

                face_gray = gray[y:y+h, x:x+w]

                face_color = image[y:y+h, x:x+w]

 

                eyes = eye_cascade.detectMultiScale(face_gray, scaleFactor=1.2,

                                                    minNeighbors=10)

 

                if len(eyes) == 0 :

                    if sleep_count < 1000:

                        sleep_count = sleep_count + 1

                    if sleep_count >= 1000:

                        print("BUZZ")

                        send_buzzer(1000)

                else:

                    if sleep_count >= 20:

                        sleep_count = sleep_count - 20

                    send_buzzer(0)

 

                for (ex, ey, ew, eh) in eyes:

                    cv2.rectangle(face_color, (ex,ey), (ex+ew,ey+eh), (0,255,0),2)

        print(sleep_count)

        cv2.imshow('result' , image)

 

        if cv2.waitKey(10) == ord('p'):

            break

 

    cv2.destroyAllWindows()

 

if __name__ == '__main__':

 

    ports = list(serial.tools.list_ports.comports())

    for p in ports:

        if 'Arduino Uno' in p.description:

            print(f"{p}포트에 연결하였습니다.")

            my_serial = serial.Serial(p.device, baudrate=9600, timeout=1.0)

            time.sleep(2.0)

 

    main()

 

    my_serial.close()

 

추가할만한 코드 : 자리를 비웠을때 카운트가 올라가게 해서 일정 시간(5분)이 경과하면 부저가 올리게 하기 

 

            


List of Articles
번호 제목 글쓴이 날짜 조회 수 추천
공지 수용소닷컴 이용약관 file asuka 2020.05.16 1340 1
957 애플, ios에서 언리얼엔진 씨를 말리겠다 1 file 땅크4호 2020.08.25 90 0
956 삭제된 게시글입니다. 스마일 2020.06.25 90 0
955 삭제된 게시글입니다. 스마일 2020.06.14 90 0
954 마크로 재밋게 코딩 1 노동자 2022.02.05 89 0
953 개같이 코드 입갤 ㅋㅋ file 毛簿没区 2022.01.11 89 0
952 언어 중에 파이썬이 가장 쓰기 편한듯 1 file MDR 2021.11.28 89 0
951 노예질 on 마루쉐 2021.01.12 89 0
950 삭제된 게시글입니다. 스마일 2020.08.25 89 0
949 삭제된 게시글입니다. 노모현 2020.05.31 89 0
948 fhd 144 살까 qhd 60 살까 고민중인데 뭐살까 8 즈고크 2020.07.12 88 0
947 유튜브 광고 스킵 스크립트 1 케니귀여워 2020.06.27 88 0
946 오늘 공부를 안했음... 또치면과락 2024.04.15 87 0
945 그냥 올려봄 2 그리드 2021.12.16 87 0
944 삭제된 게시글입니다. 우지챠 2021.02.03 87 0
943 이런곳도 있었노 2 하루각하 2021.01.06 87 0
942 여기 뭐냐ㄷㄷ ましろ 2020.12.17 87 0
941 자바를 잡아라! 2 다람쥐 2020.06.04 87 0
940 ChatGPT 진짜 지리네... 말만 하면 코드를 다 짜줌 7 file midori 2023.01.30 86 0
939 it는 본업보다는 취미로 하기 딱임 6 다람쥐 2020.06.26 86 0
938 윈도우버전 redis 설치했는데 2 阿米娅 2020.06.12 86 0
목록
Board Pagination Prev 1 ... 4 5 6 7 8 9 10 11 12 13 ... 56 Next
/ 56