C++ Articles

Page 520 of 597

Find maximum sum array of length less than or equal to m in C++

sudhir sharma
sudhir sharma
Updated on 12-Mar-2021 222 Views

In the problem, we are given n arrays of different length. Our task is to Find the maximum sum array of length less than or equal to m.We need to find sub-arrays from the arrays to maximise the sum and make the length of all subarrays combined equal to m.Let’s take an example to understand the problem, Inputn = 3, m = 4 arrOfArr[][] = {    {5, 2, -1, 4, -3}    {3, -2, 1, 6}    {-2, 0, 5} }Output20ExplanationSubArrays are {5, 4}, {6}, {5}, length = 2 + 1 + 1 = 4 Sum = 5 + ...

Read More

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

Ginni
Ginni
Updated on 10-Mar-2021 635 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 face in real-time in OpenCV using C++?

Ginni
Ginni
Updated on 10-Mar-2021 435 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 the largest face in OpenCV using C++?

Ginni
Ginni
Updated on 10-Mar-2021 371 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++?

Ginni
Ginni
Updated on 10-Mar-2021 856 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++?

Ginni
Ginni
Updated on 10-Mar-2021 390 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

How to detect the face in still picture in OpenCV using C++?

Ginni
Ginni
Updated on 10-Mar-2021 804 Views

We detect the faces from the image. To detect the face, we used 'detectMultiScale()' function.The actual format of this function is −SyntaxdetectMultiScale(source matrix, vector, searchScaleFactor, minNeighbours, flags, minfeatureSize)By changing the function arguments, we can control the 'detect.MultiSpace()' function. This function takes the following arguments.Source MatrixIt is the matrix where the face will be detected. In this case, it will the matrix which is keeping the video frames.VectorThe 'detect.MultiScale()' function will be a vector of rectangular type. A rectangle is a vector in OpenCV, and we have to define it as a vector.searchScaleFactorSearch scale factor determines how many different sizes of ...

Read More

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

Ginni
Ginni
Updated on 10-Mar-2021 2K+ Views

We will understand how to detect specific color and track object based on color. Performance of color detection and color detection based tracking system is environment dependent.If you change light of the room or if you change background color, there will be significant effect on color detection.The following program demonstrates how to detect the color using OpenCV in C++.Example#include #include #include using namespace std; using namespace cv; int main(int argc, char** argv) {    VideoCapture video_load(0);//capturing video from default camera//    namedWindow("Adjust");//declaring window to show the image//    int Hue_Lower_Value = 0;//initial hue value(lower)//    int Hue_Lower_Upper_Value = 22;//initial hue ...

Read More

How to rotate a video in OpenCV using C++?

Ginni
Ginni
Updated on 10-Mar-2021 661 Views

Rotating a video is similar to rotate an image. The only difference is instead of load a still picture into an image matrix, we have loaded a video or take video stream from the camera.Here, we are not loading the video but taking a video using the camera. If you want to use a video file, just put the address of the video file properly.The following program demonstrates how to rotate a video in OpenCV using C++.Example#include #include #include using namespace std; using namespace cv; int main(int argc, char* argv[]) {    VideoCapture loadvideo(0);//capture video from default camera//    namedWindow("OriginalVideo");//declaring ...

Read More

How to change the size of an image and add a border in OpenCV using C++?

Ginni
Ginni
Updated on 10-Mar-2021 361 Views

In this topic, we will see another application of trackbar. Here, we will use track-bar to change the size of an image and add a border to the image and change the border's size using the track-bar.Using the following program, we can change the size of an image, add a border, change the border's size and rotate the image. It is similar to the previous example.The following program demonstrates how to add multiple sliders in the same track-bar.Example#include #include #include using namespace std; using namespace cv;    int Rotate = 180;//initializing angle//    int Scale = 50;//initializing scale//    int ...

Read More
Showing 5191–5200 of 5,962 articles
« Prev 1 518 519 520 521 522 597 Next »
Advertisements