Langsung ke konten utama

CV :: How to detect the color of a person's shirt


The task of "Face Recognition", where you want a computer to figure out who a person is from a photo of them, is a very difficult function to do well. But in some cases such as robotics, it may not be so important to figure out exactly who it is, you might just want to get an idea of where the people are, or to notice when the camera sees the same person again after the camera has moved around in the room. These are cases when Shirt Detection can be used as a simple method to keep track of who is in the room. For example, a robot could just keep track that there is a person wearing a red shirt to its left, a person wearing a blue shirt in front, and a person wearing a yellow shirt on its right side, so that it can track where these people are when they move around or when the robot moves around.

Shirt Detection can be performed quite easily compared to Face Recognition, by using OpenCV's very reliable Face Detection. Once the program knows where a person's face is, it can look in a small region below the face (where a person's shirt would be), and determine the approximate color of their shirt in that shirt region. This can be performed even without a complex method of determining the exact contour region of a person's shirt, since all you need to know is the color of a region below their face, as opposed to the color of their entire shirt or body.

Here you can find a program I have created (named "ShirtDetection") that detects the shirt color of multiple people in a photo. As a demo, here is the input photo:



The program will convert each pixel into an approximate color type (eg: Green or Orange or Purple or Black, etc), based on its HSV color components. In the image below, you can see that some pixels are converted to red, some to orange, some to green, etc.



It will then perform Face Detection to find where the faces are within the original image. For each face that it finds, it will look at the approximate color types in a small rectangle region below the detected face. It will then see if there is a certain color type that is most dominant in that small region, such as if 60% of the pixels in the shirt rectangle are detected as purple pixels, then it will classify the person's shirt as Purple, with a 60% confidence rating. You can see the final image below, where the detected shirt colors are overlayed on top of the person's shirt.


In most photos, it is reliable enough for simple uses such as Human-Robot-Interaction, where a false detection is not such a problem. Note that even though it appears as if image segmentation was performed, there was no segmentation or contour detection being done. It is simply the result of converting each pixel into an approximate color type.

Note that if the person is so close to the camera that the shirt region goes below the bottom of the image, you should either ignore that face or try a smaller region (with less confidence) in the hope of atleast seeing the top of the shirt. Remember that this program is trying to do shirt color detection, on the assumption that most of their shirt is in the photo, so don't expect good results if only a tiny part of their shirt is visible, and since the shirt color is converted to just a few possible colors, don't expect good results with more than 3 or 4 people!

ShirtDetection v1.1 does try a smaller region (with less confidence) if most of the shirt is cut from the image. For example, if only the collar of the shirt is visible in the image, then instead of looking for the region in the chest area, it will look in the lower-neck area.
 

ShirtDetection:

The source-code to my program is available here (opensource freeware), to use as you wish for personal or commercial use but NOT for criminal-detection or military projects.

The shirt detection process only takes a few milliseconds to execute, but also does face detection, which normally takes about 100 milliseconds (depending on the image size). Also, it generates a "Color Image" window so you can see the detected colors of all pixels, which is useful for debugging but is very slow to generate. You can disable that feature by commenting out "SHOW_DEBUG_IMAGE" in the source-code, to run faster.

Click here to download ShirtDetection v1.1: shirtDetection.zip

(0.2MB Zip file, including C/C++ source code, VS2008 project files, the compiled Win32 program and Haar frontal face detector).

If you dont have the OpenCV 2.0 SDK then you can just get the Win32 DLLs for running this program here: openCV200_Win32DLLs.7z (1.3MB 7-Zip file).

And if you dont have the freeware 7-Zip program (better than WinZip and WinRar in my opinion), you can download it HERE.

Komentar

Postingan populer dari blog ini

CV :: Detect and Track Objects in Live Webcam Video Based on Color and Size Using C#

vote 2 vote 3 vote 4 vote 5 Download source - 229.14 KB Introduction You can select a color in real time and it tracks that color object and gives you the position. I use the Aforge library for that. I also used .NET Framework 4.0. It is a C# desktop application, it can take up to 25 frames per second. You can change color size any time you want, the color of drawing point will also change. Background  I saw a very interesting  project  in CodeProject named Making of  Lego pit camera . With the help of this project, I thought a real time tracker could be made where the color and object's size could also be changed in real time. and can draw the movement of that object in a bitmap with that color. I used some part of their code, although I used a separate color filter for more accuracy. Using the Code  The steps are very simple: Take videoframe from webcam Use filtering by given color (here Euclidian filtering is us...

CV :: Simple Color Tracking Menggunakan Webcam Dengan Library AForge.NET

Simple Color Tracking Menggunakan Webcam Dengan Library AForge.NET Berikut installer demo software simple color tracking. http://www.mediafire.com/file/304priwevhameq0/simple%20color%20tracking.rar Schematic dan firmware http://www.mediafire.com/file/mqdrsjj3qoc7777/Color_Tracking-wangready.wordpress.com.rar Beberapa waktu lalu saat sempat terpikir untuk membuat aplikasi image processing, saya menemukan sebuah library yang saya kira cukup simple untuk diimplementasikan yaitu  AForge.NET  untuk bahasa C#. Alhamdulillah saat itu ada beberapa perangkat yang tersedia di laboratorium sehigga bisa terealisasi. Berikut uraian saya. Simple Color Tracking Abstraksi Robotics vision adalah salah satu bidang kajian dalam dunia robotika. Salah satu langkah awal untuk memulainya adalah robot mampu mengenali warna. Dalam kesempatan kali ini, robot didisain mampu mengenali warna lalu mengikuti gerak dari warna yang terdeteksi tersebut. Sebagai sensornya digunakan ...

ARDUINO :: Komunikasi Arduino Uno dengan Komputer

Komunikasi serial Arduino  adalah Komunikasi antara Arduino Uno dan Komputer dapat dilakukan melalui port serial (via USB). Dalam hal ini, Arduino Uno tidak hanya bisa membaca data dari komputer yang ada di port serial, melainkan juga dapat mengirim data ke komputer. Sehingga komunikasi yang dilakukan bersifat dua arah. Pada Arduino IDE menyesuaikan fasilitas untuk melakukan komunikasi dua arah tersebut melalui serial monitor. Dengan menggunakan fasilitas ini, dapat dikirimkan data ke Arduino Uno dan sebaliknya dapat membaca kiriman dari arduino uno. Tentu saja, hal ini memungkinkan dapat mengontrol Arduino Uno melalui komputer dan memantau sesuatu yang sedang terjadi di Arduino Uno. Sebagai contoh, saat mengirimkan isyarat untuk menghidupkan lampu atau memantau suhu yang terdeteksi oleh sensor suhu di Serial Monitor. ilustrasi sederhana komunikasi antara laptop dengan arduino Jenis Perintah Komukasi serial Arduino Serial.begin() : berguna untuk menentukan kecepatan p...