[PYTHON] Detect mask wearing status with OpenCV and Raspberry Pi

Overview

IMG_0076.JPG

IMG_0077.JPG

What to prepare

Preparation

programming

import sys

sys.path.append('/home/pi/.local/lib/python2.7/site-packages')

import numpy as np

import cv2

import time

import datetime

import ambient

args = sys.argv

face_cascade = cv2.CascadeClassifier('haarcascade_frontalface_default.xml')

mouth_cascade = cv2.CascadeClassifier('haarcascade_mcs_mouth.xml')

cap = cv2.VideoCapture(0)

while(True):


    ret, frame = cap.read()

    height = frame.shape[0]

    width = frame.shape[1]

    import sys

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

    faces = face_cascade.detectMultiScale(gray, 1.3, 5)

    cv2.putText(frame, 'Please face in frame.', (350, 20), cv2.FONT_HERSHEY_PLAIN, 1.5, (0,255,0), thickness=2)

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

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

        roi_color = frame[y:y+h, x:x+w]

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

        mouth = mouse_cascade.detectMultiScale(roi_gray)

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

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

            cv2.putText(frame, 'Not masked!!', (10, 460), cv2.FONT_HERSHEY_DUPLEX, 1.0, (0,0,255), thickness=2)

    resized_img = cv2.resize(frame,(width*2, height*2))

    cv2.imshow('maskcheck', resized_img)

    if cv2.waitKey(1) & 0xFF == ord('q'):

        break

cap.release()

cv2.destroyAllWindows()

maskcheck.sh


#! /bin/bash
cd /home/pi/opencv_programs/
sudo python3 detect_face_camera.py

スクリーンショット 2020-11-08 10.30.24.png

スクリーンショット 2020-11-08 10.32.13.png

Task

Recommended Posts

Detect mask wearing status with OpenCV and Raspberry Pi
Ubuntu 20.04 on raspberry pi 4 with OpenCV and use with python
Troubleshoot with installing OpenCV on Raspberry Pi and capturing
Detect switch status on Raspberry Pi 3
Create a web surveillance camera with Raspberry Pi and OpenCV
Pet monitoring with Rekognition and Raspberry pi
MQTT RC car with Arduino and Raspberry Pi
Get temperature and humidity with DHT11 and Raspberry Pi
Detect stoop with OpenCV
DigitalSignage with Raspberry Pi
Record temperature and humidity with systemd on Raspberry Pi
Machine learning with Raspberry Pi 4 and Coral USB Accelerator
Easy IoT to start with Raspberry Pi and MESH
Measure temperature and humidity with Raspberry Pi3 and visualize with Ambient
Getting Started with Yocto Project with Raspberry Pi 4 and WSL2
Display USB camera video with Python OpenCV with Raspberry Pi
Mutter plants with Raspberry Pi
Install OpenCV4 on Raspberry Pi 3
Python beginner opens and closes interlocking camera with Raspberry Pi
Create an LCD (16x2) game with Raspberry Pi and Python
I tried connecting Raspberry Pi and conect + with Web API
Production of temperature control system with Raspberry Pi and ESP32 (1)
Measure and compare temperature with Raspberry Pi and automatically generate graph
Shining life with Python and OpenCV
[Raspberry Pi] Stepping motor control with Raspberry Pi
Use vl53l0x with Raspberry Pi (python)
Servo motor control with Raspberry Pi
Neural network with OpenCV 3 and Python 3
MQTT on Raspberry Pi and Mac
Serial communication with Raspberry Pi + PySerial
Christmas classic (?) Lighting a Christmas tree with Raspberry Pi and Philips Hue
OS setup with Raspberry Pi Imager
Make a thermometer with Raspberry Pi and make it viewable with a browser Part 4
Try L Chika with raspberry pi
OpenCV installation procedure on Raspberry Pi
Make a Kanji display compass with Raspberry Pi and Sense Hat
VPN server construction with Raspberry Pi
Graph display of household power consumption with 3GPI and Raspberry Pi
Try moving 3 servos with Raspberry Pi
Using a webcam with Raspberry Pi
Draw shapes with OpenCV and PIL
How to put OpenCV in Raspberry Pi and easily collect images of face detection results with Python
Detect analog signals with A / D converter using python on Raspberry Pi 3!
Make a wireless LAN Ethernet converter and simple router with Raspberry Pi
Get GrovePi + sensor value with Raspberry Pi and store it in kintone
RabbitMQ message notification app in Python with Growl ~ with Raspberry Pi and Julius ~
Production of temperature control system with Raspberry Pi and ESP32 (2) Production of transmission device
Measure SIM signal strength with Raspberry Pi
I want to detect objects with OpenCV
[Raspberry Pi] Add a thermometer and a hygrometer
Detect "brightness" using python on Raspberry Pi 3!
Hello World with Raspberry Pi + Minecraft Pi Edition
Build a Tensorflow environment with Raspberry Pi [2020]
Capturing images with Pupil, python and OpenCV
Get BITCOIN LTP information with Raspberry PI
Try fishing for smelt with Raspberry Pi
Programming normally with Node-RED programming on Raspberry Pi 3
Improved motion sensor made with Raspberry Pi
Try Object detection with Raspberry Pi 4 + Coral
Power SG-90 servo motor with raspberry pi
Working with sensors on Mathematica on Raspberry Pi