s1081540 作業 5
主題:膚色偵測 Skin Color Detection
作業說明
利用你所學的顏色(Color)的知識與技術,撰寫一個程式來偵測一張輸入照片中的皮膚區域並將其標示出。(請用附件中的三張照片做測試)
Write a program that detect skin color from an image.
開發環境
- Windows 10
- OpenCV 4.2.0
- Visual Studio 2019
- C++
- Windows 10
- OpenCV 4.2.0
- Visual Studio 2019
- C++
程式實作
- 使用 imread() 讀入附件中的三張圖像,再使用 empty() 判斷圖片是否存在,若圖像讀取失敗會輸出錯誤訊息並結束程式。
- cvtColor() :對原圖進行顏色空間轉換(BGR→BGRA、BGR→HSV、BGR→YCrCb)。
- at() :讀取轉換成BGRA、HSV、YCrCb類型的圖像像素值。
- 根據參考文獻定義的膚色範圍找出符合條件的膚色像素點,並將這些符合條件的像素點設為白色/原來的顏色,而不符合條件的像素點設為黑色。以下為參考文獻定義的兩種膚色範圍:
- 0.0 <= H <= 50.0 and 0.23 <= S <= 0.68 and R > 95 and G > 40 and B > 20 and R > G and R > B and | R - G | > 15 and A > 15
- R > 95 and G > 40 and B > 20 and R > G and R > B and | R - G | > 15 and A > 15 and Cr > 135 and Cb > 85 and Y > 80 and Cr <= (1.5862*Cb)+20 and Cr>=(0.3448*Cb)+76.2069 and Cr >= (-4.5652*Cb)+234.5652 and Cr <= (-1.15*Cb)+301.75 and Cr <= (-2.2857*Cb)+432.85
- imshow() :顯示原圖及經過膚色檢測後的圖像。
- waitKey(0) :透過使用者輸入0來中止程式。
執行結果
- 參考文獻定義的第一種膚色範圍:0.0 <= H <= 50.0 and 0.23 <= S <= 0.68 and R > 95 and G > 40 and B > 20 and R > G and R > B and | R - G | > 15 and A > 15
▲ img1經過膚色偵測的結果 ▲ img2經過膚色偵測的結果 ▲ img3經過膚色偵測的結果 - 參考文獻定義的第二種膚色範圍:R > 95 and G > 40 and B > 20 and R > G and R > B and | R - G | > 15 and A > 15 and Cr > 135 and Cb > 85 and Y > 80 and Cr <= (1.5862*Cb)+20 and Cr>=(0.3448*Cb)+76.2069 and Cr >= (-4.5652*Cb)+234.5652 and Cr <= (-1.15*Cb)+301.75 and Cr <= (-2.2857*Cb)+432.85
▲ img1經過膚色偵測的結果 ▲ img2經過膚色偵測的結果 ▲ img3經過膚色偵測的結果 ▲ 程式執行過程
參考資料
- Human Skin Detection Using RGB, HSV and YCbCr Color Models:https://arxiv.org/ftp/arxiv/papers/1708/1708.02694.pdf
- Color Space Conversions - OpenCV Documentation:https://docs.opencv.org/3.4/d8/d01/group__imgproc__color__conversions.html
- opencv学习笔记之Mat::at - CSDN博客:https://blog.csdn.net/u012915829/article/details/38269207
留言
張貼留言