Found 7347 Articles for C++

Find maximum of minimum for every window size in a given array in C++

Naveen Singh
Updated on 12-Mar-2021 05:49:21

686 Views

In this problem, we are given an array arr[] of size n. Our task is to Find the maximum of the minimum for every window size in a given array.Problem Description − We need to find the maximum of the minimum of a window size that varies from 1 to n. For this we will consider subarrays of the given window size, find the minimum element of each subarray and then find the maximum of all the minimums.Let’s take an example to understand the problem, Inputarr[] = {4, 1, 2, 4, 5, 1, 2, 4}Output5 4 2 1 1 1 ... Read More

How to detect and track the motion of eyeball in OpenCV using C++?

Naveen Singh
Updated on 10-Mar-2021 09:16:37

431 Views

Here, we will learn how to detect and track the motion of eyeball in OpenCV.The following program demonstrates to detect the eyeball and track the location.Example#include #include #include #include #include #include using namespace cv; using namespace std; Vec3f eyeBallDetection(Mat& eye, vector& circles) {    vectorsums(circles.size(), 0);    for (int y = 0; y < eye.rows; y++) {       uchar* data = eye.ptr(y);       for (int x = 0; x < eye.cols; x++) {          int pixel_value = static_cast(*data);          for (int i = 0; i < circles.size(); i++) {   ... Read More

How to track the eye in OpenCV using C++?

Naveen Singh
Updated on 10-Mar-2021 09:13:36

936 Views

Here, we will learn how to track the eye in OpenCV. After detective the eyes, the tracking is an effortless and straightforward task. We used the circle to enclose the detected eyes. Tracking the center of the circle means tracking the center of eyes. To track the center of the circle, we need two integer variables. This has been done on the first two lines (9th and 10th line) inside the main() function. The name of the integer variables is 'x_axis' and 'y_axis'.In line 42 and 43, the horizontal and vertical coordinate values of the center have been copied to ... Read More

How to detect the eye in OpenCV using C++?

Naveen Singh
Updated on 10-Mar-2021 09:12:36

914 Views

Here, we will learn how to detect the eye in OpenCV. We will use haarcascade_eye.xml classifier located in 'C:/opencv/sources/data/haarcascades' to detect the eyes. To detect the eyes, we need to add these headers.The first header is , and it is the header of C++ programming language. Reading writing images and user interface functionalities are defined in 'highgui' header. We need to add 'imgproc' header to enhance image quality, and we also use 'objdetect' header to detect face and eyes.The following program to demonstrate how to detect and track eye in OpenCV.Example#include #include #include #include using namespace cv; using namespace std; ... Read More

How to track the face in real-time in OpenCV using C++?

Naveen Singh
Updated on 10-Mar-2021 09:08:19

269 Views

We will learn how to track the face in real-time in OpenCV. This program is same to the previous program and difference is that we used ellipse instead of rectangle to identify the face and we also used additional 'cout' statement to show the co-ordinate of the face in the console window.The following program to detect human face in real-time −Example#include #include #include //This header includes definition of 'rectangle()' function// #include //This header includes the definition of Cascade Classifier// #include using namespace std; using namespace cv; int main(int argc, char** argv) {    Mat video_stream;//Declaring a matrix hold frames from ... Read More

How to detect human faces in real-time in OpenCV using C++?

Naveen Singh
Updated on 10-Mar-2021 09:06:25

2K+ Views

Detecting face in real-time is similar to detecting a face in still pictures.  The only difference is in real-time face detection, and we have to take a video stream of computer. In this program, we used 'VideoCapture()' function. This function captures video from other camera and stores the frames temporarily in matrix assigned to it. Here this function captures video from the default camera and temporarily stores the frames in 'real_time' matrix.The following program detects human faces in real-time −Example#include #include #include //This header includes definition of 'rectangle()' function// #include //This header includes the definition of Cascade Classifier// #include using ... Read More

How to track the position of the face in OpenCV using C++?

Naveen Singh
Updated on 10-Mar-2021 09:05:32

265 Views

When we want to track the position of the face, it is better to enclose the face with ellipse because an ellipse has a center. This center is also the center point of the detected face. As result, tracking the position of detected face becomes more accurate.The following program tracks the center of detected face and show the position in console window −Example#include #include #include //This header includes definition of 'rectangle()' function// #include //This header includes the definition of Cascade Classifier// #include using namespace std; using namespace cv; int main(int argc, char** argv){    Mat image_with_humanface;//Declaring a matrix to load ... Read More

How to detect the largest face in OpenCV using C++?

Naveen Singh
Updated on 10-Mar-2021 09:03:37

226 Views

We will learn how to detect the largest face only. This topic is same as the previous topic. The only difference is we used an additional 'Rect' structure and a 'for loop' to detect the largest face.The actual format of this function −Mat faceROI = image_with_humanface(maxRect)The maxRect have the area and location information of the largest face located on the image. The line above is cropping the same area stored in maxRect on the same location where the largest face is located on the image and storing in 'faceROI' matrix.The following program detects the largest face from still pictures −Example#include ... Read More

How to crop the detected faces in OpenCV using C++?

Naveen Singh
Updated on 10-Mar-2021 08:59:54

613 Views

We will know how to crop the detected faces in OpenCV. To crop detected faces, we need multiple matrices. The most appropriate way is to use an image array. In this program using the following two lines, we have declared two image matrices −Mat cropped_faces[4];Mat faceROI[4];The first matrix is to store the cropped images, and the second matrix is to define the region of interest. In the detection process, first, the program locates the faces and store them in vectors. In our program, the name of the vector is 'faces' Vectors can contain multiple elements.Using the following two lines, we ... Read More

How to count the number of faces in OpenCV using C++?

Naveen Singh
Updated on 10-Mar-2021 08:58:49

265 Views

Counting the number of faces located in an image is easy. The program we wrote in the previous section already have the information of number of faces in 'faces.size()'. This code-'faces.size()' gives an integer value.For example, if we write 'int x = faces.size()', the 'x' will contain the number of faces.The following program calculates the number of faces from a given image and shows it in console window.Example#include #include #include //This header includes the definition of Cascade Classifier// #include using namespace std; using namespace cv; int main(int argc, char** argv){    Mat image_with_humanface;//Declaring a matrix to load image with human ... Read More

Advertisements