Face detection in OpenCV – part 1

d5dc853022.png

OpenCV  is a library of programming functions mainly aimed at real-time computer vision. I think personally that this library is a powerful item on account of the range of usability. We can use in programming drones, verification application, robotics, comparison images… In this post I will code a simple face detection app in OpenCV. My IDE is PyCharm.

First of all, you have to install OpenCV on your machine. In case of Windows system you can type:
pip install opencv-python

After installation I recommend restart your computer. In the next step you create a basic project in selected IDE.

The first command in new project is:
import cv2

It is obvious that in face detection project you have to have an access to webcam. In this situation helps us the command:
video_capture = cv2.VideoCapture(0);
The important thing is the digit – if you use webcam built in your device (laptop, desktop) you should type 0 . In case of external webcam, just type -1 or 1.

In the next line you have to create an infinite loop to be able to read an image (live video). Simultaneously you should add a line according to displaying the live video (window).
While True:
       _, image = video_capture.read()
       cv2.imshow(“Rozpoznawanie twarzy”)

After launching the program, you should have a possibility to quick from the program. So in the next line type:
if cv2.waitKey(1)  & 0xFF == ord(‘q’):
    break

It means that when you hit ‘q’, the program will stop execute.

Capture.PNG
Now, you have to download at least two files – these are responsible for different parts of face.
Download haarcascade_eye.xml and haarcascade_frontalface_default.xml

Extract files and move to project folder.

When you have basic code, downloaded files, you can start code a boundary when the program detect a face.
Add:
def draw_boundary(img):

     gray_img = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
     features = classifier.detectMultiScale(gray_img, scaleFactor,minNeighbors)
     coords = []
     for (x,y,w,h) in features:
     cv2.rectangle(img,(x,y), (x+w, y+h),color,2)
     cv2.putText(img, text, (x, y-4), cv2.FONT_HERSHEY_SIMPLEX, 0.8, color,1,        cv2.LINE_AA)
    coords = [x,y,w,h]

    return coords

This function finds parts of face in grayscale image. Then it draws appropriate rectangle to point on face  Capture.PNG

Agile – what is it ?

Introduction
During skimming over job offers you can notice one of requirements: ‘Agile’. It is interesting issue and in this post I’m gonna give you a little explanation what is going on…

Firstly, I would like to come back to 2001. 17 practitioners who work on a daily basis in small, self-organizing teams, in cooperation with the client, an atmosphere of mutual respect, focus on early and regular provision of working software to the client and care for technical excellence. They operate based on the so-called lightweight methods. They  were meeting to talk about the specifics of the light methods they use, exchange experiences and opinions, go skiing and have a good time. Within 3 days they did much more than they expected. First of all, they found a common denominator for all these methods and decided that the common name “light methods” is not appropriate. They recognized that the term “agile” better reflects their specificity. This is the beginning of the term ‘Agile methods’. They also form the Agile Programming Manifesto, commonly referred to as the Manifesto for Agile Software Development, which is to emphasize the four values ​​on which all agile, agile methods of work are based.

 

Working  in Agile
How it looks like in reality ? I tried to show quintessence below. Thus:
#1 Client satisfaction
Recipient is happy because he get earlier, working, a good quality software.
—     —     —    —    —   —     —     —    —    —   —     —     —    —    —   —     —     —    —    —   —
#2 Motivating work environment
People want to work, develop software cause they have needed things. They have support and feel confident.
—     —     —    —    —   —     —     —    —    —   —     —     —    —    —   —     —     —    —    —   —
#3 Direct communication
Conversations in the style ‘face to face’. Business persons and programmers are still in the touch.  They have a chance to dispel all doubts.
—     —     —    —    —   —     —     —    —    —   —     —     —    —    —   —     —     —    —    —   —
#4 Working software = progress
The key is simplicity, or the art of minimizing the amount of work necessary.
—     —     —    —    —   —     —     —    —    —   —     —     —    —    —   —     —     —    —    —   —
#5 Requirements are not constants
Changes could be even in final stage of produce software.
—     —     —    —    —   —     —     —    —    —   —     —     —    —    —   —     —     —    —    —   —
#6 Efficiency is constantly enhancing
A team regularly analyze what they should to change to be more productive.
—     —     —    —    —   —     —     —    —    —   —     —     —    —    —   —     —     —    —    —   — 

Reasons-why-we-Trust-Agile-for-our-Mobile-App-Development-Process

How to improve your English ?

 

Introduction
I like learning English very much. I mentioned that on the website About me and I improve my language everyday. Obviously, I didn’t know other ways earlier, so I started looking for new paths in Internet one day. I have found different ways to learn something new about language. I can claim that these ideas are more comfortable and you have not to put in a huge effort.

My favourite ways

a) language on a phone
I have changed my language (set on English) on my mobile phone. Why ? Because when you have a constant contact with foreign language, you can learn new words by practice. What does it mean ? If you have on your display the word “Power Saving” and you have no idea what it could means, you have a great possibility to discover meaning through tap.

b) listening songs/podcasts/videos on YouTube
Everyday, when I go to school I turn on something in English on my mobile phone. Through this, I can improve my listening skills. In total I exercise my listening 3 hours per day. (during going to school and coming back).

c) Quizlet
I have downloaded the app: ‘Quizlet’ last holiday. ‘Quizlet’ is the tool which helps you learn new words which you want. You have to add words/phrasal verbs/sentences which you want to study and then constantly exercise them. I have to admit that I don’t regret having this app on my phone. When I’m little bored or I go to school by train – I like launching this app instead playing a game.

d) Instagram
Accidentally I have ‘Instagram’ app on my device. I enjoyed because I can learn new words (with meaning !) there, too. Beyond this there are lots of daily live conversation with people around the world, so If you have a free time, you can take a part in live conversation.

e) Skype/Tandem
I also improve my speaking skills through Skype. There are lots of English learners in Internet who looking for speaking partner. It is an amazing chance to improve your fluency and simultaneously know more about foreign culture.

f) quickly reading
Good idea to be fluent in English (and other languages) is quickly reading at home or another place where is silence. I try to choose (in a free time) interested book and read quickly by 15 min.

What do you think about that ? If you have any idea how to improve English – share your way below in a comment.

Few words about: how useful is using vector in small projects

When I started learning programming, nobody told me that exists very, very useful tool like vector. Somebody could say: ‘Ok Wojtek, but what is it ?’ With pleasure I can explain this term. Vector is an array, but you don’t declare a size. However, array will be increase without any problems when you will add next (for example) integers. If you will be curious of size – you can use: array.size(); I still use vector, almost in every project because I enjoyed seriously. You can use this type of array when you will not know how big will be an array. Let’s go to sample project.

Firstly, when you create a new project, you must add the #include <vector>. I am sure that you know how to declare basic array, but I put below an example and then I will compare an array and a vector.

Capture
As you can see: there is a difference in a record. In normal array you have to define a size, but in a vector – no. Let’s check how to add anything to this type of array.

‘numbers.push_back(random)’ is necessary if you want to fill in vector. Every single integer (in this case) will be located on the end of numbers (push_back). As I wrote (at the beginning of the post) if you want to check size, you should use command ‘numbers.size()’. Let’s add that.

Conclusion: vector is an array which is elastic and it helps during solving ‘matura’ tasks. If you want to know more about this topic, I recommend you these sources:
First source
Second source
Third source

What I did during the month break ? What’s happened ?

Introduction
There are over 7.5 bilion people on the world. Every single year people set new goals to achieve. They say: “Tomorrow, I am running to the park (100%) and I am gonna stick with it”. Motivation is on high level, but even if they persevere the first day, their motivation falls and after few days, they don’t do anything to achieve set goal. Why ? In my opinion they improvise, don’t have a plan to succed. It is really hard to do something without a plan because they don’t know what is important specific day and motivation becomes a frustration. When zeal is 0%, they return to daily.
If You want to achieve anything without frustration – go to this video . Did I use this ? Of course ! 🙂 Everything here (on this blog) come from my experience (check my course).

Month break
My last post was published 16 February 2018. What I did through the month ? Did I return to daily ? 🙂 No ! I focused on solving secondary school certificate (matura) and I think that I did… a progress :). I am able to do more assignments but not every. Remember – I am beginner programmer ;). However I feel better and I noticed that programming is (obviously another world) little hard because computer is not smart – yeah and we have to program in the universal way which will ok in every situation. If we add lines of code than computer will follow them and do commands (then we call ‘smart’). I know that I didn’t discover America but sometimes we should think deeper about some topic and notice differences and references.

Recently, I have started listening podcasts, YouTube videos to improve listening skills. Of course I knew something interesting about conversion number system. I have learnt vector and I am still use that in projects – very useful tool :).

In conclusion, I still learn new things and I like it because I discover new sources of learning which I want to see and it is amazing.

3 ways to be smarter without a huge effort

Introduction
Internet – the word which know almost everybody on this World. Lots of people used to use the Internet as a source of environment (e.g. games, movies) because everyday they have to hard work and then this group of people want to feel comfortable. Another group prefer to spend a free time outside through go to a park, to a forest and feel free there – many space away from a job, troubles…
If you tell anyone about increasing a knowledge after a job, this person could think that you are stupid and probably you don’t know what means a ‘hard work’ at job. I agree with this person, but… someone told her/him that it must takes a huge effort ? 😉 In this post I am going to show you few ways to be smarter what is important for developers and not only.

Ways to increase knowledge
Assuredly you have to use a mean of transport to be at job, because not everyone is a freelancer, haven’t you ? 🙂 A car, a train, a bike…. it doesn’t matter but then you have a possibility to be smarter during going to a job, to school…. What did I write ? Am I sure ? I am sure ! 🙂 Have you ever heard about audiobooks and podcasts ? Probably yes, but did you use once ?
In my opinion, one of the best way to be smarter is… listening podcasts and audiobooks. Why ? Undoubtedly, you want to be smarter and you haven’t a free time for this and you don’t like reading books, but you have a phone and headphones, yeah ? 🙂 So, here is my tip: download a podcast or an audiobook for your mobile phone, turn on and just listen during going to job, school, university, meeting etc. What is the difference beetwen listening and reading a book ? By listening you will be able to have more books in category ‘read in 100%’ than even starting reading a book. If you want to read a book, you have to have silence, free time, focus… but if you turn on podcast, for example in a car you will be listening and it is a chance to finish listening an audiobook or a podcast in a week. (for example during driving to job and coming back). Try this and you will see a difference 😉 Many people use this and their highly recommend this way.

 

Devstyle podcasts

Gary Vaynerchuk podcasts

Tim Ferris podcasts

My second tip for you is… watching 🙂 Assuredly you like watching videos on YouTube, but have you ever thought about watching something more interesting ? I encourage you to go on YouTube and there subscribe smart people from field what you are interested in. I like programming very much so I subscribe:

Andrzej Krzywda, Arkency CEO

Maciej Aniserowicz, devstyle.pl


John Sonmez, simpleprogrammer.com

Hitesh Choudhary


Stefan Mischook

Beyond these people, I like watching (in a free time) persons who give a tips about life, marketing, leading a business. I highly recommend: 

Irreplaceable Mirosław Burnejko, Chmurowisko CEO


Ludwik C. Siadlak

Gary Vaynerchuk, VaynerMedia CEO

Many people have installed Snapchat on their phones. Is it helpful ? Few persons could say ‘No’, but I tell you that Snapchat is useful. Yeah ! There you can also know something new and it requires only few seconds/per a snap because people like Gary Vaynerchuk, Maciej Aniserowicz give there also a knowledge.

What do you think about my ways ? Maybe you have your own an unique way ? Share below in the comment field 😉

 

A class – how to encourage to be also a friend?

Introduction
What do you think about programming ? Did I encourage you to increase your knowledge on this field ? 🙂 If your answer is: YES –  I am very happy, if: NO – unfortunately, maybe programming is not for you or you should find another more interesting source to know more about programming and … someday make an application which will solve a common problem 🙂
In this post I want to show you and explain to you how to create a friend class. If you are interested in the topic – follow me 😉

Programming
On starting, let’s come back to code from a previous post.

I am going to modify this code. Add a new class and then I will try to make a class friendly. It is high time to ‘connect’ both classes. How can you do it ? Do you remember how looks like a process of connecting functions ? If you are not sure, check here. It will be little similar like in functions. Firstly, you have to add the line:
Now, in the function ‘void price_news()’ you will have to give a parameter.
Obviously, naming of a reference depends only you so instead ‘Fruits & fo‘ you could use ‘Fruits & frts‘. You have a choice 🙂 .
You can write anything in the method. I have added this:
Currently, you have a chance to create an object and refer to…
Firstly, create an object in ‘int main’.
Undoubtedly, you noticed that Visual Studio shows you have to write something yet in ‘new_apple.price_news()‘. What you should write there (give as an argument) ? Think for a moment…

You have to give as an argument just the object apple. Check your code by clicking CTRL+F5. In my Visual Studio, there aren’t any mistakes.

If you are not sure, start one more time. However, any questions please leave in a commnet field or go to contact and write there a message.

Function beyond a class ?

Introduction
In this post I am going to explain to you meaning and working a static function in practice. Let’s start and I will try to convince you that it isn’t hard to understand and use.

Practice
Let’s start coding…. . If you have little problems, return to my previouses posts and read again.
Everything should works properly. Now, I have a question for you: Can I use the function ‘void price_gross()’ in another place ? Beyond the class ‘Library’ ? I want to evaluate a gross price for other thing. I wouldn’t create a new class and write the same function again. Have I a chance to use this function anywhere yet ?

Yes, of course. In this situation very helpful is a static function. See how to do this:

function-scope.png

That’s all what you need to add, simultaneously I want to tell you something: in a static function you can’t refer to variables in given class.