Fewww คือ ระบบแจ้งเตือน โดยใช้ระบบ Face-Recognition เข้ามาช่วยเหลือในการตรวจจับหน้าบุคคล และการนำ Chat Service มาเป็นตัวแจ้งเตือน (Bot) โดยจุดประสงค์คือการแจ้งเตือน เมื่อเครื่องมือ detect ใบหน้าของบุคคลให้เจ้าของบ้านรับรู้และตอบสนองได้ท่วงทันเหตุการณ์
สิ่งที่เราใช้มาประกอบการทำ Project Fewww ก็มีดังนี้
- Rasberry Pi 3 Model B
- Computer Webcam (ทางเราใช้ Logitech HD WEBCAM C310)
ส่วนทางด้าน ภาษา
- C++ (OpenCV)👁
- Javascript (node-telegram-bot-api) 📲
- Python (Training Model) 👥
- OpenCV2 (version 3.4.1)
- OpenCV Extra Module
- Node.js (npm)
- Node Telegram bot Api (with in code Folder)
Fewww จะทำงานอยู่บน Raspberry-Pi
โดย System ของเรานั้นจะแบ่งเป็น 2 ส่วนหลังนั้นก็คือ ส่วนของการ Recognition
และ Notification
ซึ่งส่วนของการ Recognition
นั้นจะคอย ตรวจจับใบหน้าและจะเป็นส่วนที่คอย Trigger ให้ส่วน Notification
ทำงานนั้นคือ การ Notify ผู้ใช้
และแน่นอนการที่จะให้ตัว FEWWW นั้นสามารถ Identify Face ได้ แน่นอนเราก็ต้องทำการ Training ให้ Program สามารถเรียนรู้จากรูปใบไหน้าได้ (Training Model)
'''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()
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";
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;
}
ในส่วนของการ Notify User นั้นอย่างที่เราได้กล่าวไว้ในข้างต้นว่าเราใช้ตัว Telegram Bot เป็นตัวส่งให้ User รับรู้ โดยภาษาที่ใช้สั่งตัว Telegram Bot ที่เราใช้คือ JavaScript (node.js) และใช้ node.js telegram bot api ซึ่งตัว Node.js นี้จะเป็นตัวที่รอการ Trigger จาก C++ เมื่อมีการ detect เกิดขึ้น เพื่อส่งให้กับผู้ใช้
if (check >= 15){
cout << name_user << endl;
imwrite("test_picture.jpg", frame);
system ("node notify.js");
check = 0;
}
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 --');
});
ในส่วนของการใช้งานนั้น การทำงาน Feww จะทำการ Notify ไปผ่านท่าง Feww Alert bot
เพื่อเตือนให้เรารู้ว่า ให้เรารับรู้ โดยเมื่อเราเริ่มการทำงานของ Raspberry Pi เราก็สามารถปล่อยให้ Programme นั้น Run ไปได้เลย
พชรพล พรหมมา | รฐนนท์ จันทนะสุคนธ์ | รวิชญ์ โลหะขจรพันธ์ |
60070058 | 60070079 | 60070081 |
@MixPacharapon | @ khingbmc | @RawitSHIE |
ผศ. ดร. กิติ์สุชาต พสุภา | ผศ. ดร. ปานวิทย์ ธุวะนุติ |
Telegram Bot Api - Telegram APIs Document
รายงานนี้เป็นส่วนหนึ่งของวิชา Computer Programming (รหัส 06016315)
คณะเทคโนโลยีสารสนเทศ สถาบันเทคโนโลยีพระจอมเกล้าเจ้าคุณทหารลาดกระบัง