Skip to content

compro-itkmitl/FEWWWW

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

61 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

🔐 What is FEWWW

Fewww คือ ระบบแจ้งเตือน โดยใช้ระบบ Face-Recognition เข้ามาช่วยเหลือในการตรวจจับหน้าบุคคล และการนำ Chat Service มาเป็นตัวแจ้งเตือน (Bot) โดยจุดประสงค์คือการแจ้งเตือน เมื่อเครื่องมือ detect ใบหน้าของบุคคลให้เจ้าของบ้านรับรู้และตอบสนองได้ท่วงทันเหตุการณ์

🛠 Component

สิ่งที่เราใช้มาประกอบการทำ Project Fewww ก็มีดังนี้

ส่วนทางด้าน ภาษา

  • C++ (OpenCV)👁
  • Javascript (node-telegram-bot-api) 📲
  • Python (Training Model) 👥

🔗 Requested Component installation is needed

🗜️How did it work?

Fewww จะทำงานอยู่บน Raspberry-Pi โดย System ของเรานั้นจะแบ่งเป็น 2 ส่วนหลังนั้นก็คือ ส่วนของการ Recognition และ Notification ซึ่งส่วนของการ Recognition นั้นจะคอย ตรวจจับใบหน้าและจะเป็นส่วนที่คอย Trigger ให้ส่วน Notification ทำงานนั้นคือ การ Notify ผู้ใช้

👁 OpenCV2

ในส่วนของการจดจำใบหน้าเป็นเรื่องง่ายสำหรับคน แต่เป็นเรื่องยากสำหรับคอมพิวเตอร์ โดยทางคอมพิวเตอร์ได้มีอัลกอริทึกมีมากมายแต่ทุกสิ่งนั้นได้มีพื้นฐานมาจาก เรขาคณิต โดยนำ จุดที่เป็นจุดแสดงถึงองค์ประกอบภายในใบหน้าและภายนอกมาสร้างเป็นสมการเวคเตอร์ ซึ่งใน ณ จุดนี้ เราใช้ library C++ ที่ชื่อว่า OpenCV (version 2) เข้ามาช่วย

และแน่นอนการที่จะให้ตัว FEWWW นั้นสามารถ Identify Face ได้ แน่นอนเราก็ต้องทำการ Training ให้ Program สามารถเรียนรู้จากรูปใบไหน้าได้ (Training Model)

ตัวอย่างรูปการ Trainning

ตัวอย่าง Code การ Training Face Recognition

'''create recognizer'''
rec = cv2.face.LBPHFaceRecognizer_create()

'''This is path go to dataset'''
path = 'user'

'''define function get img'''
def getimg(path):
	'''get image path and append to list imgpath'''
	
	imgpath = [os.path.join(path, f) for f in os.listdir(path)]

	'''create list of faces and Id'''
	faces, Id = [], []

	'''loop for in img path'''
	for p in imgpath:
		'''add img to face_img and connvert to grayscale'''
		if(p == "user/.DS_Store"):
			continue
		face_img = Image.open(p)
		
		face_np = np.array(face_img, 'uint8')
		Ids = int(os.path.split(p)[-1].split('.')[0][-1])
		faces.append(face_np)
		
		print(Ids)
		
		Id.append(Ids)
		
		cv2.imshow("train", face_np)
		cv2.waitKey(10)
	
	return Id, faces

Id, faces = getimg(path)

rec.train(faces, np.array(Id))
rec.save('trainingdata.yml')
cv2.destroyAllWindows()

ตัวอย่าง รูปของการ Recognition

ตัวอย่าง code ของส่วน อ่าน File .yml (File ที่เกิดจากการ Trainning)

Ptr<LBPHFaceRecognizer> model = LBPHFaceRecognizer::create();
	//read model
	model -> read("trainingdata.yml");
	
	//cascade face
	CascadeClassifier face_cascade;
	string classifier = "haarcascade_frontalface_alt.xml";
	face_cascade.load(classifier);

	string window = "cap_faceDetection";

ตัวอย่าง Code ของ Face Recognition

Ptr<LBPHFaceRecognizer> model = LBPHFaceRecognizer::create();
for(int i=0;i<faces.size();i++){
    //point begin and end of faces
    Rect face_num = faces[i];
    Point f_begin(faces[i].x, faces[i].y);
    Point f_end(faces[i].x + faces[i].width , faces[i].y + faces[i].height);

    Rect crop = Rect(faces[i].x, faces[i].y, faces[i].width, faces[i].height);
    Mat cropimage = gray_scale(crop);
    imshow("f", cropimage);

    rectangle(frame, face_num,CV_RGB(0, 255, 0), 2);

    int predict_label = -1;
    double confidence = 0.0;
    model -> predict(cropimage,predict_label, confidence);
    
    if(confidence == 0.0){
        int check = 0;
    }
    cout << confidence << endl;
    if(predict_label == 1){
        if(confidence < 50){
            name_user = "khing";
        }
        else{
            name_user = "unknown";
            
        }
        check += 1;
    }

🔔 Telegram bot api

ในส่วนของการ Notify User นั้นอย่างที่เราได้กล่าวไว้ในข้างต้นว่าเราใช้ตัว Telegram Bot เป็นตัวส่งให้ User รับรู้ โดยภาษาที่ใช้สั่งตัว Telegram Bot ที่เราใช้คือ JavaScript (node.js) และใช้ node.js telegram bot api ซึ่งตัว Node.js นี้จะเป็นตัวที่รอการ Trigger จาก C++ เมื่อมีการ detect เกิดขึ้น เพื่อส่งให้กับผู้ใช้

ตัวอย่าง Code ของ Trigger FEWWW Bot

if (check >= 15){
    cout << name_user << endl;
    imwrite("test_picture.jpg", frame);
    system ("node notify.js");
    check = 0;
}

ตัวอย่าง Code ของการส่งรูปไปยัง User

const TelegramBot = require('node-telegram-bot-api');
const token = '<botToken>';
const bot = new TelegramBot(token, {polling: true});

    bot.sendPhoto(msg.chat.id,"test_picture.jpg",{caption:})
    .then(() => {
        console.log('--sending completed--');
        console.log('--sended to '+msg.chat.username+'--');
    })
    .catch(() => {
        console.log('-- sending err --');
    });

📲 Interface

ในส่วนของการใช้งานนั้น การทำงาน Feww จะทำการ Notify ไปผ่านท่าง Feww Alert bot เพื่อเตือนให้เรารู้ว่า ให้เรารับรู้ โดยเมื่อเราเริ่มการทำงานของ Raspberry Pi เราก็สามารถปล่อยให้ Programme นั้น Run ไปได้เลย

รูปตัวอย่างของ การแจ้งเตือน

👥Team Member

พชรพล พรหมมา รฐนนท์ จันทนะสุคนธ์ รวิชญ์ โลหะขจรพันธ์
60070058 60070079 60070081
@MixPacharapon @ khingbmc @RawitSHIE

👨‍🏫 Instructor

ผศ. ดร. กิติ์สุชาต พสุภา ผศ. ดร. ปานวิทย์ ธุวะนุติ

🔗Reference

OpenCV

node.js telegram bot api

Telegram Bot Api - Telegram APIs Document

Learning Algorithms


รายงานนี้เป็นส่วนหนึ่งของวิชา Computer Programming (รหัส 06016315)

คณะเทคโนโลยีสารสนเทศ สถาบันเทคโนโลยีพระจอมเกล้าเจ้าคุณทหารลาดกระบัง


About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors