কম্পিউটার

কিভাবে C++ ব্যবহার করে OpenCV-তে মুখের অবস্থান ট্র্যাক করবেন?


আমরা যখন মুখের অবস্থান ট্র্যাক করতে চাই, তখন উপবৃত্তের সাথে মুখটি ঘেরা ভাল কারণ একটি উপবৃত্তের একটি কেন্দ্র থাকে। এই কেন্দ্রটি সনাক্ত করা মুখের কেন্দ্রবিন্দুও। ফলস্বরূপ, সনাক্ত করা মুখের অবস্থান ট্র্যাক করা আরও নির্ভুল হয়ে ওঠে৷

নিম্নলিখিত প্রোগ্রামটি সনাক্ত করা মুখের কেন্দ্র ট্র্যাক করে এবং কনসোল উইন্ডোতে অবস্থান দেখায় -

উদাহরণ

#include<iostream>
#include<opencv2/highgui/highgui.hpp>
#include<opencv2/imgproc/imgproc.hpp>
//This header includes definition of 'rectangle()' function//
#include<opencv2/objdetect/objdetect.hpp>
//This header includes the definition of Cascade Classifier//
#include<string>
using namespace std;
using namespace cv;
int main(int argc, char** argv){
   Mat image_with_humanface;//Declaring a matrix to load image with human faces//
   image_with_humanface = imread("person.jpg");//loading an image that contains human face in it//
   namedWindow("Face Detection");//Declaring an window to show the result//
   string trained_classifier_location = "C:/opencv/sources/data/haarcascades/haarcascade_frontalface_alt.xml";//Defining the location our XML Trained Classifier in a string//
   CascadeClassifier faceDetector;//Declaring an object named 'face detector' of CascadeClassifier class//
   faceDetector.load(trained_classifier_location);//loading the XML trained classifier in the object//
   vector<Rect>faces;//Declaring a rectangular vector named faces//
   faceDetector.detectMultiScale(image_with_humanface, faces, 1.1, 4, CASCADE_SCALE_IMAGE,Size(20,20));//Detecting the faces in 'image_with_humanfaces' matrix//
   for (int i = 0; i < faces.size(); i++){ //Initiating for loop to detect the largest face//
      Point center(faces[i].x + faces[i].width * 0.5, faces[i].y + faces[i].height * 0.5);//getting the center of the face//
      ellipse(image_with_humanface, center, Size(faces[i].width * 0.5, faces[i].height * 0.5), 0, 0, 360, Scalar(255, 0, 255), 4, 8, 0);//draw an ellipse on the face//
      int horizontal = (faces[i].x + faces[i].width * 0.5);//Getting the horizontal value of coordinate//
      int vertical = (faces[i].y + faces[i].width * 0.5);//Getting the vertical value of coordinate//
   }
   cout << "Position of the face is at(x,y)=" << " ("<<CAP_PROP_XI_DECIMATION_HORIZONTAL<<","<<CAP_PROP_XI_DECIMATION_VERTICAL<<")"<< endl;//
   imshow("Face Detection", image_with_humanface);//Showing the largest face face//
   waitKey(0);//To wait for keystroke to terminate the program
   return 0;
}

আউটপুট

কিভাবে C++ ব্যবহার করে OpenCV-তে মুখের অবস্থান ট্র্যাক করবেন?


  1. সি++ ব্যবহার করে ওপেনসিভিতে একটি নির্দিষ্ট পিক্সেলের মান কীভাবে পাবেন?

  2. কিভাবে C++ ব্যবহার করে OpenCV-এ একটি উপবৃত্ত আঁকবেন?

  3. কিভাবে C++ ব্যবহার করে OpenCV-এ একটি লাইন আঁকবেন?

  4. C++ ব্যবহার করে ওপেনসিভিতে একটি ছবির চ্যানেলের সংখ্যা কীভাবে গণনা করা যায়?