Automated Computer Vision
HomeHome > Blog > Automated Computer Vision

Automated Computer Vision

Jul 16, 2023

Member-only story

Md. Zubair

Follow

DataDrivenInvestor

--

Listen

Share

Computer vision adds a new dimension to modern technologies. Consciously or subconsciously, we are using computer vision. I am a university lecturer conducting a computer vision course. Usually, I manually take the attendance; it consumes time and energy. Two days ago, an idea came to my mind to automate a system to save energy and time. And I have successfully completed the project.

If you read the article till the end, you will be able to create your own. No complex or higher-level coding or mathematics knowledge is needed. Let's move on.

I have tried to keep the project simple and easy so that beginner-level learners feel comfortable creating their first project. Let's import the required libraries.

We extracted the training image directories with the above code and saved them in the myList variable.

With the above code, we have extracted the training image directories and saved them in the myList variable.

Now, consider the following code cell.

Above code helps us to create two different lists named — images and classnames. We have saved the intensity values of the images in the images list and the name of each person in the classnames list.

For demonstration purposes, I have shown the name of the images below.

The images were saved with Anik.jpg, Ferdous.jpg, etc.

[N.B. According to the code of this project, we have to label the image with the identification name or I.D.]

Face encoding is a way to represent the faces of an image with some computer-measured numbers. Similar face encoding generates similar types of encoded values. So it becomes easy to recognize the faces.

We have used the following code cell to encode the images with the face recognition library.

The function findEncodings returns all the encoded values for the training images.

Generally, OpenCV stores the image in BGR format rather than RGB format. So, we need to convert it to RGB to work with the images. And face_recognition.face_encodings() function extracts the face from an image and encodes it.

We want to make our project realistic. That's why we also generate an Excel sheet containing the information and attendance time in a tabular format for each day. I have created the following function to do the job.

We have used the openpyxl library to create and insert data in the Excel sheets. Firstly, we have taken an Excel file where we store the information. For each day, we have created a new sheet with that day's date in the Excel file. Finally, we have inserted the name, date, and time of the recognized persons in the Excel sheet.

Sample output —

We have detected the faces from live camera input so that we can use the real-time CCTV camera footage to take attendance. We also saved the image in a different folder of the detected face for further checking.

All of these tasks are in a single code cell —

We have created individual folders for each day to save the detected images with os.mkdir() . Next, we captured the video with the function cv2.VideoCapture(0) . Here, 0 for the default camera, and you can also use 1, 2 and so on for other camera inputs. We have taken continuous video frames with a while loop. After that, we reduced the image size to 1/4 to minimize the computational cost and encode the image with the reduced image. We have also calculated the distance from the input image to the trained image and finally labeled the input image with the shortest distanced trained image label.

We also draw a red rectangle of the detected face showing the name of the detected person. At the same time, we collected the name of the detected face as a list and inserted it into the Excel sheet with the takeAttendance() function.

Output of the detected face —

Saved image in the specific date folder —

Generated Excel sheet —

For each date, we have created an Excel sheet of a specific Excel file.

Mainly, I have created the project for beginners. So, I have kept it simple. The project has some limitations.

The full project is available here.

Join medium with the following link to support my writings.

https://mzh706.medium.com/membership

Other articles from my computer vision series —

towardsdatascience.com

towardsdatascience.com

towardsdatascience.com

towardsdatascience.com

towardsdatascience.com

Subscribe to DDIntel Here.

Visit our website here: https://www.datadriveninvestor.com

Join our network here: https://datadriveninvestor.com/collaborate

CCTV The full project is available here. computer vision