Face Recognition Using OpenCV | Loading Recognizer
আমার আগের পোস্টে আমরা একটি ডেটাসেট ব্যবহার করে কোনও সনাক্তকারীকে প্রশিক্ষণ দিতে শিখেছি, এই পোস্টে আমরা কীভাবে সেই স্বীকৃতিটি মুখগুলি সনাক্ত করতে ব্যবহার করতে পারি তা দেখার জন্য আমরা সনাক্তকারী লোড করছি।
আপনি যদি আমার আগের পোস্টগুলি অনুসরণ করে থাকেন তবে এর মধ্যে \"ট্রেনার\" এবং \"ট্রেনার.আইএমএল\" ফাইলের ভিতরে আপনার সাথে ইতিমধ্যে প্রশিক্ষিত শনাক্তকারী রয়েছে। আমরা পূর্বে প্রশিক্ষিত কিছু মুখ সনাক্ত করতে আমরা সেই প্রশিক্ষণ ডেটা ব্যবহার করতে যাচ্ছি।
Lets Start By Importing The Libraries
import cv2
import numpy as np
হ্যাঁ এটি হ'ল, আমাদের এই প্রকল্পগুলির জন্য প্রয়োজনীয়।
Now Loading Recognizer
এরপরে আমরা ওপেনসিভি লাইব্রেরি ব্যবহার করে একটি সনাক্তকারী বস্তু তৈরি করব এবং প্রশিক্ষণ ডেটা লোড করব (তার আগে কেবলমাত্র আপনার স্ক্রিন্টটি একই জায়গায় যেখানে আপনার \"প্রশিক্ষক\" ফোল্ডারটি অবস্থিত আছে সেখানে সেভ করুন)
recognizer = cv2.createLBPHFaceRecognizer()
recognizer.load('trainner/trainner.yml')
এখন আমরা মুখ সনাক্তকরণের জন্য haar cascade for face detection হর ক্যাসকেড ব্যবহার করে একটি ক্যাসকেড শ্রেণিবদ্ধকারী তৈরি করব, ধরে নিচ্ছি আপনার একই জায়গায় ক্যাসকেড ফাইল রয়েছে,
cascadePath = "haarcascade_frontalface_default.xml"
faceCascade = cv2.CascadeClassifier(cascadePath);
এখন আমরা ভিডিও ক্যাপচার অবজেক্ট তৈরি করব
cam = cv2.VideoCapture(0)
এর পরে আমাদের একটি \"ফন্ট\" দরকার কারণ আমরা ছবিতে সেই ব্যক্তির নাম লিখতে চলেছি সুতরাং পাঠ্যের জন্য আমাদের ফন্টের প্রয়োজন
font = cv2.cv.InitFont(cv2.cv.CV_FONT_HERSHEY_SIMPLEX, 1, 1, 0, 1, 1)
Okay so the first parameter is the font name, 2nd and 3rd is the horizontal and the vertical scale,4rth is shear (like italic), 5th is thickness of line, 6th is line type ঠিক আছে তাই প্রথম প্যারামিটার হ'ল ফন্টের নাম, ২ য় এবং তৃতীয়টি অনুভূমিক এবং উল্লম্ব স্কেল, চতুর্থতম শিয়ার (ইটালিকের মতো), 5 তম লাইনের বেধ, 6 ষ্ঠ লাইনের ধরণ
So we have all setup
Lets Start the main Loop
Lets start the main loop and do the following basic steps
- Starts capturing frames from the camera object
- Convert it to Gray Scale
- Detect and extract faces from the images
- Use the recognizer to recognize the Id of the user
- Put predicted Id/Name and Rectangle on detected face
So its pretty similar to the face detection code the only difference is the following lines
Id, conf = recognizer.predict(gray[y:y+h,x:x+w])
cv2.cv.PutText(cv2.cv.fromarray(im),str(Id), (x,y+h),font, 255)
in the next line we are writing the User ID in the screen below the face, which is (x, y+h) coordinateউপরের দুটি লাইনে সনাক্তকারী যথাক্রমে ব্যবহারকারী আইডি এবং পূর্বাভাসের আত্মবিশ্বাসের পূর্বাভাস দিচ্ছে পরের লাইনে আমরা মুখের নীচে স্ক্রিনে ব্যবহারকারী আইডি লিখছি, যা (x, y + h) স্থানাঙ্ক
[ictt-tweet-inline hashtags=”#opencv,#python,#facerecognition” via=”via thecodacus”]Just Little Finishing Touch (For Unknown Faces)[/ictt-tweet-inline]
Now with this we are pretty much done we can add some more finishing touch like its showing user Id instead of the name,
and it cant handle unknown faces,
এখন এটির সাহায্যে আমরা বেশ কাজ করেছি আমরা নামের পরিবর্তে এর ব্যবহারকারীর আইডির মতো আরও কিছু সমাপ্তি স্পর্শ যুক্ত করতে পারি,এবং এটি অজানা মুখগুলি পরিচালনা করতে পারে না,
So to add this additional features we can do the following,
Now Some Cleanup
Now that everything is done, we need to close the camera and the windows. and we are done!!!!
And this is the results

[ictt-tweet-inline hashtags=”#opencv, #python, #facerecognition” via=”via thecodacus”]The Complete Face Recognition Code In One Piece[/ictt-tweet-inline]
Now as Promised
Complete Video Tutorial
Feel Free to Subscribe my blog and her youtube channel
https://youtu.be/oqMTdjcrAGk
Updates:
Github links:
For this code: you can visit: https://github.com/thcodacus/Face-Recognition
nazmi69 has done a good job converting the code for python 3.x and opencv 3.0
available at https://github.com/nazmi69/Face-Recognition
available at https://github.com/nazmi69/Face-Recognition
0 comments:
Post a Comment