[PYTHON] Visualize the appreciation status of art works with OpenCV

Overview

スクリーンショット 2020-10-01 9.18.26.png It seems that it was installed and operated at the startup support facility FGN (https://growth-next.com) in Fukuoka City. スクリーンショット 2020-10-01 9.24.23.png IMG_4946.jpeg IMG_4945.jpeg

What to prepare

Preparation

programming

detect_face_camera.py


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')

eye_cascade = cv2.CascadeClassifier('haarcascade_eye.xml')

cap = cv2.VideoCapture(0)

flg = 0

stime =  0

am = ambient.Ambient(xxxx, 'xxxxxxxxxxxxxxxx')  #Ambient channel ID/Light key(Number of visits / stay time)

am2 = ambient.Ambient(xxxx, 'xxxxxxxxxxxxxxxx')  #Ambient channel ID/Light key(CPU temperature)

acnt = 0

while(True):

    t3 = time.time()

    cnt = 0

    ret, frame = cap.read()

    #Get the height and width of the loaded image

    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)

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

        t1 = time.time()

        cv2.rectangle(frame,(x,y),(x+w,y+h),(152,145,234),2)

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

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

        eyes = eye_cascade.detectMultiScale(roi_gray)

        cnt += 1

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

            cv2.rectangle(roi_color,(ex,ey),(ex+ew,ey+eh),(108,97,232),2)

        t2 = time.time()

        stime += (t2 - t1) * 1000 / 60

        acnt = acnt + cnt

    cv2.putText(frame, 'count: ' + str(acnt / 100), (10, 420), cv2.FONT_HERSHEY_DUPLEX, 1.0, (0,255,0), thickness=2)

    cv2.putText(frame, 'stay[sec]: ' + str('{:.1f}'.format(stime)), (10, 460), cv2.FONT_HERSHEY_DUPLEX, 1.0, (0,255,0), thickness=2)

    cv2.putText(frame, 'senseart v.0.0.1b', (410, 20), cv2.FONT_HERSHEY_PLAIN, 1.5, (0,255,0), thickness=2)

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

    cv2.imshow('senceart (v.0.0.1 beta)', resized_img)

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

        break

    t4 = time.time()

    f = open("/sys/class/thermal/thermal_zone0/temp","r")  #CPU temperature

    for t in f:

        tmp = t[:2]+"."+t[2:5]

    f.close()

    fps = cap.get(cv2.CAP_PROP_FPS)

    now = datetime.datetime.now() 

    minute = '{0:%M}'.format(now)

    second = '{0:%S}'.format(now)

    print('count', acnt / 100)

    print('stay', stime)

    print("minute", minute)

    print("second", second)

    print("temp", tmp)

    print("\n")

    if int(minute) % 5 == 0 and int(second) == 0:

        r = am.send({'d1': acnt / 100, 'd2': stime})  #Send visits and length of stay to Ambient

        r = am2.send({'d1': tmp})  #Send CPU temperature to Ambient

        r.close()
        acnt = 0

        cnt = 0

        print("******************sended*****************\n")

        continue

    if int(minute) % 10 == 0 and int(second) == 0:

        r = am.send({'d1': acnt / 100, 'd2': stime})  #Send visits and length of stay to Ambient

        r = am2.send({'d1': tmp})  #Send CPU temperature to Ambient

        r.close()

        acnt = 0

        cnt = 0

        print("******************sended*****************\n")

        continue

cap.release()

senceart.sh


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

important point

Try using

Recommended Posts

Visualize the appreciation status of art works with OpenCV
Visualize the response status of the census 2020
Visualize the behavior of the sorting algorithm with matplotlib
Visualize the range of interpolation and extrapolation with python
Visualize the characteristic vocabulary of a document with D3.js
Get the operation status of JR West with Python
Visualize the orbit of Hayabusa2
I tried "gamma correction" of the image with Python + OpenCV
Check the memory status of the server with the Linux free command
Check the operating status of the server with the Linux top command
The story of displaying images with OpenCV or PIL (only)
Visualize the flow rate of tweets with Diamond + Graphite + Grafana
Estimate the attitude of AR markers with Python + OpenCV + drone
Color extraction with Python + OpenCV solved the mystery of the green background
Finding the simplest mistakes with OpenCV
How to monitor the execution status of sqlldr with the pv command
Visualize the frequency of word occurrences in sentences with Word Cloud. [Python]
I want to check the position of my face with OpenCV!
Try blurring the image with opencv2
Basic study of OpenCV with Python
How to crop the lower right part of the image with Python OpenCV
The story of having a hard time introducing OpenCV with M1 MAC
Read the graph image with OpenCV and get the coordinates of the final point of the graph
Display the status of COVID 19 infection in Japan with Splunk (GitHub version)
I tried to visualize the text of the novel "Weathering with You" with WordCloud
The result of making the first thing that works with Python (image recognition)
Get and estimate the shape of the head using Dlib and OpenCV with python
Try to separate the background and moving object of the video with OpenCV
Cv2.imshow now works properly with Homebrew's OpenCV3
Align the size of the colorbar with matplotlib
Visualize the boundary values of the multi-layer perceptron
Check the existence of the file with python
Try using the camera with Python's OpenCV
Visualize the effects of deep learning / regularization
The third night of the loop with for
Visualize the export data of Piyo log
Count the number of characters with echo
I want to visualize the transfer status of the 2020 J League, what should I do?
I tried to easily visualize the tweets of JAWS DAYS 2017 with Python + ELK
Periodically notify the processing status of Raspberry Pi with python → Google Spreadsheet → LINE
[PyCharm 5.0 new function] Visualize and debug the thread execution status of async / await
I tried "smoothing" the image with Python + OpenCV
The story of doing deep learning with TPU
Check the operation of OpenCV3 installed by Anaconda
Note: Prepare the environment of CmdStanPy with docker
Prepare the execution environment of Python3 with Docker
Performance comparison of face detector with Python + OpenCV
2016 The University of Tokyo Mathematics Solved with Python
I tried "differentiating" the image with Python + OpenCV
[Note] Export the html of the site with python.
See the behavior of drunkenness with reinforcement learning
Visualize the inner layer of a neural network
Increase the font size of the graph with matplotlib
Visualize coronavirus infection status with Plotly [For beginners]
Calculate the total number of combinations with python
Eliminate the inconveniences of QDock Widget with PySide
Challenge the Tower of Hanoi with recursion + stack
Rewrite the name of the namespaced tag with lxml
I tried "binarizing" the image with Python + OpenCV
The easiest way to use OpenCV with python
Fill the browser with the width of Jupyter Notebook