During the special period of the epidemic, companies and schools have started telecommuting and learning. During the office period, in addition to completing daily work arrangements, they also need to take care of their own food and daily life. Under the situation of high intensity of work pace and lack of exercise, how can they find health risks as soon as possible and work happily? Today’s share from Goose producer Bottlejiang.
A view of the, back
Are you still worried about the current epidemic? Are you still struggling to get three meals a day? Does sitting awkwardly give you back pain? Does a small computer screen give you dry eyes? Home office, unknowingly exposed to a lot of health risks:
1. Posture problems
Home office environment is relatively simple, notebook screen height is low, a day unconsciously hunched over.
2. Eating problems
I can’t go out, I can’t order take-out, cooking for myself doesn’t taste good, it’s tiring and boring.
3. Drinking water
Always forget to drink water exercise when you are so engaged at work.
4. Emotional problems
The epidemic is severe, stay in the rented house for fear of disease, depressed mood.
My life is not by me, healthy life match god! As an engineer, I have made numerous requirements in daily life. This time, why not make a requirement for myself? With their own professional ability, with their own hands, with the code, to develop, to create, to solve the above problems.
Two, the right medicine
1. Address the posture problem
To avoid slouching, I need to remind me when I’m not sitting properly. Then the following three problems need to be solved:
- Monitor my sitting position in real time
- Judge if I’m sitting properly
- Remind me when I don’t sit right
(1) Monitoring
How to monitor? The solution is to use a computer camera! The notebook basically comes with, the desktop can support the way through access peripherals.
If the Web wants to call the webcam, it can easily do so by calling an API: The navigator. MediaDevices. GetUserMedia, the navigator getUserMedia has renamed mediaDevices. GetUserMedia.
Also, for privacy reasons, the API is only supported under HTTPS. The navigator. MediaDevices. GetUserMedia returns a promise object, supports audio and video, size set the frame rate, etc
(2) Judge
How can you tell if I’m sitting properly if you can take a picture of me sitting in real time? The solution: tensorflow.js! As early as half a year ago, tensorflow. js initially attracted me because it could recognize the facial features of a portrait, input a picture, and output the position of human organs in the picture, including nose, eyes, ears, shoulders, elbows, wrists, hips, knees and ankles.
Tensorflow.js is a JavaScript library for training and deploying machine learning models in browsers and Node.js. The short answer is to take machine learning to the web. There are many applications for it, and some interesting things have been done.
Problem is, you’re working in front of your computer, but the best the laptop camera can capture is your head and shoulders? Here you can imagine that when the sitting posture is not straight, in fact the head is not straight. (I’m afraid it’s not common to see a straight head and a crooked body.) So, judging the five senses is actually enough.
In terms of implementation, after initialization (posenet.load), an image is input through estimateSinglePose method, and score and coordinates of various parts of human body are output.
{
"score": 0.36588028040440645."keypoints":[
{
"score": 0.998099148273468."part": "nose"."position": {
"x": 318.6268163302529."y": 371.8572926799611}}, {"score": 0.996922492980957."part": "leftEye"."position": {
"x": 260.77240393968873."y": 307.9062803988327}},... ] }Copy the code
The initialization of posenet.load takes many parameters: Architecture, outputStride, inputResolution, Multiplier, quantBytes, modelUrl. These parameters are the Settings of the model, which are related to the output resolution, recognition accuracy and accuracy, and directly affect the recognition efficiency and performance. In the current requirements scenario, you don’t have to worry about these, just default.
EstimateSinglePose has a parameter flipHorizontal: whether the flip should be horizontal/mirrored. The computer camera returns an image that is horizontally opposite to the direction of reality (relative to its own perspective). It can be processed by CCS horizontal rotation of 180 degrees (rotateY(180deg)).
Similarly, the output of the model can get coordinate data in the corresponding direction by setting flipHorizontal to true. After obtaining the coordinates of five senses, the corresponding points can be drawn on the image through canvas to verify whether the recognition is correct.
As shown in the image above, when sitting upright, the face is in the middle of the image, the eyes and ears are level, and the nose is between the eyes and ears. These conditions are often not met when sitting badly. The sitting position can be detected by judging the relative and absolute position of the five senses. For example, the closer you are to the screen, the bigger your face is and the wider the distance between your eyes. When large enough to be considered close to the screen to a certain extent, this degree is the threshold.
Anything above this threshold means I’m looking at a computer screen at close range. I’m at an unhealthy job at the moment. There are generally the following scenarios of sitting awkwardly, and the position of the five senses on the picture is judged as follows:
- Hunched: Now the whole head is in the lower half of the image, judge the distance between the y coordinate of the nose and the lower edge of the image
- Chin with one hand: at this time the head is crooked, judge the difference of the y coordinates of the two eyes
- Strabismus: now the head rotates along the Y-axis to judge the difference between the x coordinates of the left eye and ear and the difference between the x coordinates of the right eye and ear
- Overlooking (head up) : Tilt your head upward to determine whether the y-coordinate of your nose is too close to the y-coordinate of your eyes
- Overlooking (bowing) : At this point the head is bent down to determine whether the y-coordinate of the nose is too close to the y-coordinate of the ear
- Eyes too close to the screen: the head is larger in the image at this time, judge the x coordinate difference between the two eyes (near larger than far smaller)
Then it’s just a matter of calculation, figuring out the various differences and setting thresholds. Here you can directly to the screen to try to reverse the head, feel the sitting improper timing parameters, grasp the strict and loose judgment, and gradually adjust the parameters.
To achieve the purpose of monitoring, the image recognition logic needs to run a loop. You can use either setInterval or requestAnimationFrame.
RequestAnimationFrame can make the monitor screen very smooth, and the viewing effect is great, but 60 frames is still very high performance, every time TensorFlow identification, Canvas drawing and logic judgment, it is really difficult, short time is ok, Run long enough and the MAC pops into egg-boil mode.
Generally speaking, it is enough to leave the page open and listen to the alarm. This monitoring is not so real-time, and it is enough to run setInterval every 500 milliseconds.
(4) Alarms
Can take a picture of my sitting posture in real time, can tell if I am sitting properly, so when I am not correct, how can I remind me? Playing voice, of course!
Download a few seconds of alarm audio from the Internet. Identify and judge when the sitting posture is not straight play the audio, the effect of reminding. Playing audio is very simple. Get audio object and play().
However, there is a problem. There are six different types of bad posture. How do you know which one is the alarm when you hear it?
Is there a way to! Here you can download audio of various prompts, using Google Translate. When the sitting posture is not straight, play the corresponding voice. At the beginning of a sudden put an alarm bell is always scared jump, Google Translate demonic voice is obviously more human!
In addition, filtering of alarm burrs should be considered. For example, if I drink a glass of water or stretch my back, my head may be tilted and this alarm should not be sent. Considering that these actions are completed in a short period of time, assuming that the completion of 3 seconds, then you can add a judgment, lasting more than 3 seconds is the real alarm of bad sitting posture, need to be issued.
In practice, when I go to the toilet or go out to pour water, no one is in front of the computer at this time, according to the original logic, it must be an alarm.
This is where the score field that the model outputs comes in handy. Score is a number ranging from 0 to 1. A higher value indicates a more accurate and reliable output. When people are not in front of the computer, the score is less than 0.1, so the data lower than 0.1 will be directly discarded.
Finally, put the threshold value and some Settings on the page to support editing, and add the number of alarm statistics. At the end of the day, you can see which kind of improper sitting posture is prominent, and you can do some targeted exercises to stretch and relax.
2. Focus on eating
The problem of eating! It’s a disaster for people who have no cooking experience. But there’s nothing you can do about it. It can only be dealt with casually, such as throwing ingredients into the rice cooker for lazy rice, or buying disposable bowls and chopsticks.
Two meals a day, three hours, and it’s not good! That’s pretty boring. The main premise of cooking is not to be defeated, only to enhance the fun. So, according to the staple food, meat, vegetables, snacks four categories, will store down the food classification, and then add a random function, every time to the meal point, click, random collocation.
This solves two problems:
- It’s hard to cook what to eat, and it’s hard to decide what to eat when there’s a lot of ingredients.
- To spice things up, you might randomly create some weird combinations. The unknown brings curiosity and keeps people interested. It is the ladder of human progress. Isn’t that interesting!
There’s a lot of logic here, so two random foods in a row can’t be the same. After all, it’s no fun to eat the same thing for lunch and dinner!
3. Drink water & exercise
After a day often forget to drink water, until thirsty time to think of passive, at this time your body has been water, this is not healthy! At the end of the day, sitting for long periods of time is not healthy!
In view of this problem, you can make a periodic reminder. Recall the time when you tend to forget to drink water in your daily work. Two reminders are given in the morning, middle and evening respectively, and two reminders are added at the same time.
It is also easy to implement. Run setInterval to compare the current time and set the reminder time in real time. The alarm mode is the same as the preceding.
conclusion
Being positive and happy can help boost your immune system.
Adult life is not easy, but always believe that the way is more than difficult! Write here, imagine oneself of 100 years old, majestic and powerful tapping keyboard, mouth read: healthy life, long life.
Resources: application experience: www.doverr.com/alarm/index…