[PYTHON] A server that returns the number of people in front of the camera with bottle.py and OpenCV

Last time I tried calling a Java program from bottle.py, but when accessed with a browser by the same method, I wrote a server that acquires a webcam image, recognizes a face image with OpenCV and returns the number of people in front of the camera saw.

Last time I wrote it in Python3, but this time it's Python2.7 and it's awkward to write import cv, cv2. .. ..

from bottle import route, run, template
import cv,cv2
import time

@route('/cv')
def index():
    cnt = 0
    cap = cv2.VideoCapture(0)
    time.sleep(0.1)
    ret,im = cap.read()
    cv2.imwrite("camera.jpg ",im)
    cap.release()
    cascade = cv.Load("haarcascade_frontalface_default.xml")
    cvim = cv.LoadImage("camera.jpg ")
    faces = cv.HaarDetectObjects(cvim, cascade, cv.CreateMemStorage())
    for (x,y,w,h),n in faces:
        cnt = cnt + 1
        cv.Rectangle(cvim, (x,y), (x+w,y+h), 255)
    cv.SaveImage('dst.jpg',cvim)
    return template('{{cnt}}', cnt=cnt)
run(host='127.0.0.1', port=8080)

Recommended Posts

A server that returns the number of people in front of the camera with bottle.py and OpenCV
Create a BOT that displays the number of infected people in the new corona
A simple mock server that simply embeds the HTTP request header in the body of the response and returns it.
A script that pings the registered server and sends an email with Gmail a certain number of times when it fails
Generate a list packed with the number of days in the current month.
The story of making a sound camera with Touch Designer and ReSpeaker
Create a bot that posts the number of people positive for the new coronavirus in Tokyo to Slack
Find the number of days in a month
The advantages and disadvantages of Django that people with one year of experience think
How to count the number of elements in Django and output to a template
[Python] A program that calculates the number of updates of the highest and lowest records
[Python] Precautions when finding the maximum and minimum values in a numpy array with a small number of elements
[Python] A program that counts the number of valleys
# Function that returns the character code of a string
Predict the number of people infected with COVID-19 with Prophet
Develop a web API that returns data stored in DB with Django and SQLite
Build API server for checking the operation of front implementation with python3 and Flask
How to identify the element with the smallest number of characters in a Python list?
[Python] A program that finds the shortest number of steps in a game that crosses clouds
A memo that detects and returns an image acquired from a webcam with Django's OpenCV
Find a guideline for the number of processes / threads to set in the application server
Create a bot that only returns the result of morphological analysis with MeCab on Discord
Create a web surveillance camera with Raspberry Pi and OpenCV
Get the number of specific elements in a python list
[Python] Programming to find the number of a in a character string that repeats a specified number of times.
[Homology] Count the number of holes in data with Python
I created a Discord bot on Docker that reports the number of corona infected people in Tokyo at a specified time.
Let's visualize the number of people infected with coronavirus with matplotlib
[Python] A program to find the number of apples and oranges that can be harvested
A story that verified whether the number of coronas is really increasing rapidly among young people
I tried to predict the number of domestically infected people of the new corona with a mathematical model
[Python] The role of the asterisk in front of the variable. Divide the input value and assign it to a variable
Yield in a class that inherits unittest.TestCase didn't work with nose (depending on the version of nose?)
[Python] A program that finds the maximum number of toys that can be purchased with your money
The story of creating a bot that displays active members in a specific channel of slack with python
Process the contents of the file in order with a shell script
Count the number of Thai and Arabic characters well in Python
How to make a surveillance camera (Security Camera) with Opencv and Python
A function that measures the processing time of a method in python
Draw a watercolor illusion with edge detection in Python3 and openCV3
A script that returns 0, 1 attached to the first Python prime number
The story of making a module that skips mail with python
Get the number of readers of a treatise on Mendeley in Python
A programming language that young people will need in the future
I made a LINE bot that tells me the type and strength of Pokemon in the Galar region with Heroku + Flask + PostgreSQL (Heroku Postgres)
Set up a dummy SMTP server in Python and check the operation of sending from Action Mailer
Considering the situation in Japan by statistician Nate Silver, "The number of people infected with coronavirus is meaningless"
Recognize the contour and direction of a shaped object with OpenCV3 and Python3 (Principal component analysis: PCA, eigenvectors)
Get a list of camera parameters that can be set with cv2.VideoCapture and make it a dictionary type
A story about creating a program that will increase the number of Instagram followers from 0 to 700 in a week
A story that visualizes the present of Qiita with Qiita API + Elasticsearch + Kibana
The story of a Parking Sensor in 10 minutes with GrovePi + Starter Kit
[Python] A program that calculates the number of chocolate segments that meet the conditions
Replace the directory name and the file name in the directory together with a Linux command.
Calculate the shortest route of a graph with Dijkstra's algorithm and Python
Graph of the history of the number of layers of deep learning and the change in accuracy
Get the number of searches with a regular expression. SeleniumBasic VBA Python
[Python] A program that calculates the number of socks to be paired
The story of having a hard time introducing OpenCV with M1 MAC
Check the in-memory bytes of a floating point number float in Python
Receive a list of the results of parallel processing in Python with starmap