top of page
  • BrainlessRBT

Employee Temperature System: How I failed to build a product, What I learned? Part II

Updated: Jul 15, 2020

Python, Kivy, OpenCV, Android, Buildozer, RaspberryPi, Arduino, Chromebook etc.

In this part, I will explain the problems and solutions I experienced with Kivy, Python and OpenCV on Android. As I mentioned before, because of the supply problems that I had with temperature sensor, I gave up proceeding with my project at that time. And I had decided to continue to learn and solve face recognition with Kivy + Python to work on Android.


Using Kivy and Python


Before attempting to this project, I always used Raspberry Pi or a Linux PC for my Python projects and I was using tkinter for GUI design. However, with this project, in order to be able to use in Android and because of its modern widgets, I decided to learn and use Kivy. I am using PyCharm and configured a virtual environment.


Setting Up Buildozer


Buildozer is a tool for creating Python packages for Android, iOS, Windows etc.. So you can package your Kivy application to run in Android. Very important to remember to name your main application as main.py And when you initiate buildozer a .spec file will appear, where you set permissions such as camera, change name, icon and many other specifications. There are many little details, I will mention. But, before, you should install Buildozer successfully. Unfortunately, I had a lot problems installing it to venv in PyCharm, on my Mac and Ubuntu. And thanks to sentdex's video I could manage to make it work. I would recommend to follow everything that he shows exactly.


 

OpenCV + Kivy + Python = FaceDetection


My first aim was to detect faces with opencv on python and frame them with a border. I was pretty new to that, and I found this guide and code in this Brazilian Blog

Visit:


This is a good example of Kivy working with Python and OpenCV.


VideoCapture(0) indexes the cameras and uses the first camera, (1 is second), and captures the image.

self.capture = cv2.VideoCapture(0)

ret, frame = self.capture.read()

ret: A Boolean, True or False if there is return from read

frame: Next Frame


For more insight and if you don't want to search and search, earn some time, watch and read sentdex's tutorial please: https://pythonprogramming.net/loading-video-python-opencv-tutorial/


Adding Haar Cascade Frontal Face Detection of OpenCV




Anyway, the example above works fine on PC, raspberry pi or etc. But the opencv capture is not working when you build it to Kivy + Android.


Problem occurs with :

self.capture = cv2.VideoCapture(0)
ret, frame = self.capture.read()

ret is false, meaning no frame is captured when used on Android, even though Camera permissions are all set. One thing I could do is to use:


camera = self.ids['camera']
timestr = time.strftime("%Y%m%d_%H%M%S")
camera.export_to_png("IMG_{}.png".format(timestr))

This function exports the image from camera widget and saves. However, I didn't think it was an efficient way for the thing I would like to achieve. I searched for self.capture a lot, even tried professional help, but could not find any solution. Please write in the comments if you know something about this.


So I am still on hold with opencv(f.detection)+ Kivy on Android due to this.

 

Part III will be showing my final program that can run on Windows, Mac, Linux which is automatically detecting faces and measuring the temperature upon face detection. Using screen widgets of Kivy.




261 views0 comments
bottom of page