facedetection
xenodeve · ส่วนตัว
โปรแกรมตรวจจับใบหน้าด้วย OpenCV และ Python รองรับทั้งไฟล์ภาพ, URL และกล้องแบบ Real-time
สรุปโปรเจกต์
ภาพรวม
แอปพลิเคชันตรวจจบบใบหน้าที่พัฒนาด้วย Python และ OpenCV รองรับการประมวลผลจากไฟล์ภาพในเครื่อง, ลิงก์ URL และกล้องเว็บแคมแบบเรียลไทม์
สรุป 30 วินาที
• รองรับแหล่งข้อมูลหลากหลายทั้งไฟล์ท้องถิ่น, URL และกล้องแบบเรียลไทม์ • ประมวลผลรวดเร็วด้วย Haar Cascade พร้อมตรวจจับหลายใบหน้าและแสดงผลกรอบสีเหลืองทันที
เหมาะกับใคร
เหมาะสำหรับนักพัฒนาและนักศึกษาด้าน Computer Vision ที่ต้องการโปรโตไทป์ระบบตรวจจับใบหน้าหรือเรียนรู้การประมวลผลภาพเบื้องต้น
- หมวดหมู่
- Computer Vision
- ปี
- 2026
- ผู้ดูแลผลงาน
- xenodeve
รายละเอียดเพิ่มเติมรายละเอียดเชิงลึก
โปรแกรมตรวจจับใบหน้านี้พัฒนาด้วย Python และ OpenCV รองรับการทำงานจากหลายแหล่งข้อมูลทั้งไฟล์ภาพในเครื่อง ภาพผ่าน URL และกล้องเว็บแคมแบบ Real-time โดยใช้โมเดล Haar Cascade Classifier ในการระบุตำแหน่งใบหน้า พร้อมแสดงผลกรอบสีเหลืองและรองรับการตรวจจับหลายใบหน้าในภาพเดียว
ระบบออกแบบมาให้ใช้งานง่ายผ่าน Command Line Interface โดยผู้ใช้สามารถเลือกโหมดการทำงานได้ทันทีหลังรันโปรแกรม ประกอบด้วยการประมวลผลภาพนิ่งและสตรีมวิดีโอที่รวดเร็ว ผ่านไลบรารีมาตรฐานอย่าง NumPy และ urllib สำหรับจัดการข้อมูลภาพและดาวน์โหลดจากอินเทอร์เน็ต
โครงสร้างโปรเจกต์มีความเรียบง่าย เหมาะสำหรับการเรียนรู้ Computer Vision ขั้นพื้นฐาน หรือการนำไปต่อยอดเป็นระบบวิเคราะห์ภาพในอนาคต ด้วยประสิทธิภาพการประมวลผลที่รวดเร็วและค่าพารามิเตอร์ที่ปรับแต่งได้ตามความต้องการ
เอกสารต้นฉบับรายละเอียด (README)
👤 Face Detection - Python Application
โปรแกรมตรวจจับใบหน้าด้วย OpenCV และ Python ที่รองรับการตรวจจับใบหน้าจากหลายแหล่งที่มา ทั้งไฟล์ภาพ, URL, และกล้องแบบ Real-time
📝 Latest Version: v1.0.0 - Face Detection with Multiple Input Sources
🌟 คุณสมบัติเด่น
🎯 Multiple Input Sources
- 📁 Local Image - ตรวจจับใบหน้าจากไฟล์ภาพในเครื่อง
- 🌐 URL Image - ดาวน์โหลดและตรวจจับใบหน้าจากภาพออนไลน์
- 📹 Real-time Camera - ตรวจจับใบหน้าแบบ real-time จากกล้อง webcam
🔧 Technical Features
- 🤖 Haar Cascade Classifier - ใช้โมเดล pre-trained สำหรับตรวจจับใบหน้า
- ⚡ Fast Processing - ประมวลผลรวดเร็วด้วย OpenCV
- 🎨 Visual Feedback - แสดงกรอบสีเหลืองรอบใบหน้าที่ตรวจพบ
- 🔄 Multi-face Detection - ตรวจจับหลายใบหน้าในภาพเดียว
- 📱 Multi-camera Support - รองรับการเลือกกล้องหลายตัว
💻 เทคโนโลยีที่ใช้
🐍 Python Libraries
- OpenCV (cv2) - Computer Vision library สำหรับการประมวลผลภาพ
- NumPy - การจัดการ array และข้อมูลภาพ
- urllib - ดาวน์โหลดภาพจาก URL
📁 โครงสร้างโปรเจ็กต์
facedetection/
├── detect.py # Main application file
├── facedetectionmodel.xml # Haar Cascade model file
├── requirements.txt # Python dependencies
└── README.md # Documentation
🛠️ การติดตั้งและใช้งาน
📋 ความต้องการระบบ
- Python 3.7+
- pip สำหรับติดตั้ง packages
- Webcam (ถ้าต้องการใช้งานโหมดกล้อง)
- facedetectionmodel.xml - Haar Cascade model file
⚡ Quick Start
1. Clone โปรเจ็กต์
git clone https://github.com/xenodeve/facedetection.git
cd facedetection
2. ติดตั้ง Dependencies
pip install -r requirements.txt
หรือติดตั้งแบบ manual:
pip install opencv-python==4.10.0.84
pip install numpy==1.26.4
3. ดาวน์โหลด Haar Cascade Model (ถ้ายังไม่มี)
# ดาวน์โหลดไฟล์ haarcascade_frontalface_default.xml จาก OpenCV
# และเปลี่ยนชื่อเป็น facedetectionmodel.xml
หรือดาวน์โหลดจาก: OpenCV GitHub - Haar Cascades
4. รันโปรแกรม
python detect.py
🎮 วิธีการใช้งาน
เมื่อรันโปรแกรม จะมีตัวเลือก 3 แบบ:
Option 0: Local Image 📁
Where do you get the input?
0 = local
1 = url
2 = cam
Answer(Number) = 0
- ตรวจจับใบหน้าจากไฟล์
tag.ongในโฟลเดอร์เดียวกัน - แสดงผลภาพพร้อมกรอบใบหน้า
- กด ปุ่มใดก็ได้ เพื่อปิดหน้าต่าง
Option 1: URL Image 🌐
Where do you get the input?
0 = local
1 = url
2 = cam
Answer(Number) = 1
url = https://example.com/image.jpg
- ใส่ URL ของภาพที่ต้องการตรวจจับใบหน้า
- โปรแกรมจะดาวน์โหลดและตรวจจับใบหน้าอัตโนมัติ
- กด ปุ่มใดก็ได้ เพื่อปิดหน้าต่าง
Option 2: Real-time Camera 📹
Where do you get the input?
0 = local
1 = url
2 = cam
Answer(Number) = 2
Which camera?
(if you have only 1 cam. enter 0, Default = 0)
Answer = 0
- เลือกหมายเลขกล้องที่ต้องการใช้ (ปกติใช้ 0)
- ตรวจจับใบหน้าแบบ real-time
- กด 'q' เพื่อออกจากโปรแกรม
🔧 คุณสมบัติเทคนิค
🏗️ Detection Methods
- detection() - สำหรับภาพนิ่ง (local และ URL)
- detection2() - สำหรับ video stream (camera)
🎨 Visual Features
- สีกรอบ: เหลือง (BGR: 255, 255, 0)
- ความหนากรอบ: 2 pixels
- การแปลงสี: Gray scale สำหรับการตรวจจับ
⚙️ Detection Parameters
# สำหรับภาพนิ่ง
faces = face_model.detectMultiScale(gray_scale)
# สำหรับ video stream
faces = face_model.detectMultiScale(gray_scale, 1.3, 5)
# scaleFactor = 1.3
# minNeighbors = 5
🐛 การแก้ไขปัญหา
ปัญหาที่พบบ่อย
❌ ไม่พบไฟล์ facedetectionmodel.xml
# ดาวน์โหลด Haar Cascade model
wget https://raw.githubusercontent.com/opencv/opencv/master/data/haarcascades/haarcascade_frontalface_default.xml -O facedetectionmodel.xml
❌ กล้องไม่ทำงาน
# ลองเปลี่ยนหมายเลขกล้อง
# 0 = กล้องหลัก
# 1 = กล้องรอง (ถ้ามี)
❌ ตรวจจับใบหน้าไม่ได้
- ตรวจสอบแสงสว่างในภาพ
- ลองปรับ parameters ใน
detectMultiScale() - ใบหน้าควรหันตรงกล้อง
❌ Error: cv2.error
# ติดตั้ง opencv-python ใหม่
pip uninstall opencv-python
pip install opencv-python==4.10.0.84
🚀 การปรับแต่งและพัฒนาต่อ
ปรับแต่งสีกรอบ
# เปลี่ยนสีกรอบใน detect.py
cv.rectangle(img, (x,y), (x+w,y+h), (0,255,0), 2) # สีเขียว
cv.rectangle(img, (x,y), (x+w,y+h), (255,0,0), 2) # สีน้ำเงิน
ปรับความแม่นยำ
# ปรับ parameters สำหรับความแม่นยำที่ดีขึ้น
faces = face_model.detectMultiScale(
gray_scale,
scaleFactor=1.1, # ค่าน้อย = แม่นยำมากขึ้น แต่ช้าลง
minNeighbors=5, # ค่ามาก = ลด false positive
minSize=(30, 30) # ขนาดใบหน้าขั้นต่ำ
)
เพิ่มการบันทึกภาพ
# บันทึกภาพที่ตรวจจับแล้ว
cv.imwrite('detected_faces.jpg', img)
📊 Model Information
Haar Cascade Classifier
- Type: Pre-trained face detection model
- Algorithm: Viola-Jones object detection framework
- Training: Trained on thousands of positive and negative images
- Performance: Fast and efficient for frontal face detection
🏆 Features Showcase
🎯 Versatile Input Options
- รองรับการตรวจจับจากหลายแหล่งที่มา
- ง่ายต่อการใช้งานด้วย CLI interface
- เหมาะสำหรับทั้งการเรียนรู้และการใช้งานจริง
⚡ Fast Processing
- ใช้ OpenCV ที่มีประสิทธิภาพสูง
- ตรวจจับ real-time ได้อย่างลื่นไหล
- รองรับหลายใบหน้าในภาพเดียว
📈 Future Enhancements
🚀 Planned Features
- รองรับการตรวจจับใบหน้าด้านข้าง
- เพิ่มการจดจำใบหน้า (Face Recognition)
- บันทึก video output
- GUI interface
- การตรวจจับอารมณ์ (Emotion Detection)
- การตรวจจับอายุและเพศ
- Export ผลลัพธ์เป็น JSON
👨💻 ผู้พัฒนา
XenoDeve
- GitHub: @xenodeve
- Repository: facedetection
🤝 Contributing
ยินดีรับ Pull Requests และ Issues ทุกรูปแบบ!
- Fork โปรเจ็กต์
- สร้าง Feature Branch (
git checkout -b feature/AmazingFeature) - Commit การเปลี่ยนแปลง (
git commit -m 'Add some AmazingFeature') - Push ไปยัง Branch (
git push origin feature/AmazingFeature) - เปิด Pull Request
📚 Documentation Links
Official Documentation
Useful Resources
📜 License
This project is licensed under the MIT License - see the LICENSE file for details.
🙏 Acknowledgments
- OpenCV Team - สำหรับ computer vision library ที่ยอดเยี่ยม
- Viola-Jones - สำหรับ object detection algorithm
- Python Community - สำหรับเครื่องมือและ libraries ที่ดีเยี่ยม
📞 Support & Contact
หากมีคำถามหรือปัญหาในการใช้งาน:
- 📧 เปิด Issue บน GitHub
- 💬 ติดต่อผ่าน GitHub Profile
🚀 Happy Coding! 👤
ถาม AI เกี่ยวกับ facedetection
ถามแนวทาง เทคโนโลยี หรือความเหมาะสมของโปรเจกต์นี้กับไอเดียของคุณ
กำลังโหลดแชท / Loading chat…