Found 7347 Articles for C++

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

Naveen Singh
Updated on 10-Mar-2021 08:55:37

579 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 track the color in OpenCV using C++?

Naveen Singh
Updated on 10-Mar-2021 08:52:23

590 Views

Color tracking is similar to color detection. For tracking purpose, we added extra few lines to calculate the area of the detected object and then track the current position of that area and finally used line() function of OpenCV to show the object's path of motion.The following program demonstrates how to track the color in OpenCV using 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_Low= 0;//lower range of hue//    int Hue_high = 22;//upper range of ... Read More

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

Naveen Singh
Updated on 10-Mar-2021 08:50:24

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 work with Mouse Events using OpenCV in C++?

Naveen Singh
Updated on 10-Mar-2021 08:48:25

1K+ Views

Mouse Events is one of the most useful features of OpenCV. In OpenCV, we can track the mouse pointer's position and track the clicks (right, left and middle-click). OpenCV has a wide application in robotics and computer vision. In robotics and computer vision tracking mouse pointer and clicks are frequently used.Here we will understand how to track the mouse pointer's location on an image and track the clicks.The following program demonstrates how to track the location of the mouse pointer and clicks.Example#include #include #include using namespace std; using namespace cv; void locator(int event, int x, int y, int flags, void* ... Read More

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

Naveen Singh
Updated on 10-Mar-2021 08:47:25

407 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++?

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

193 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

How to rotate an image in OpenCV using C++?

Naveen Singh
Updated on 10-Mar-2021 08:42:40

2K+ Views

Rotating image using built-in functions of OpenCV is an effortless task. To rotate image, we have to use 'highgui.hpp' and 'imgproc.hpp' header files and we will introduce more functions in this program which deal with image rotation.The following program how to rotate an image in OpenCV using C++.Example#include #include #include using namespace std; using namespace cv; int main(int argc, char** argv) {    Mat before_rotation = imread("bright.jpg");//loading image to a matrix    namedWindow("BeforeRotation");//Declaring window to show the original image//    imshow("BeforeRotation", before_rotation);//showing the image before rotation//    namedWindow("AfterRotation");//declaring window to show rotated image//    int Rotation = 180;//initialization rotation angle// ... Read More

How to add Track-bar in OpenCV using C++?

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

710 Views

Track-bars are controllable bars which are used to control various parameters in OpenCV. Using track-bars, we can make it easier and change the parameters graphically. Track-bar removes this limitation and enables to create of dynamic effects using OpenCV.The following program demonstrates how to add track-bars in OpenCV using C++.Example#include #include using namespace cv; using namespace std; int main() {    Mat original;//Declaring a matrix//    original = imread("sky.jpg");//loading the image in the matrix//    namedWindow("Slider");//Declaring window to show the image//    int light = 50;//starting value of the trackbar//    createTrackbar("Brightness", "Slider", &light, 100);//creating a trackbar//    int contrast = ... Read More

How to get the FPS value in OpenCV using C++?

Naveen Singh
Updated on 10-Mar-2021 08:39:56

951 Views

To get the FPS value, we used the 'get()' command of and 'CAP_PROP_FPS' as the argument of the 'get()'. This argument returns the FPS in integer form.At the starting of the program, we have taken an integer variable named 'FPS'. Then we used FPS = cap.get(CAP_PROP_FPS); to store the FPS value in the variable.The following program gets the FPS of a video and shows it in the console window.Example#include//OpenCV header to use VideoCapture class// #include using namespace std; using namespace cv; int main() {    int FPS;//Declaring an integer variable to store the number of total frames//    VideoCapture cap("video1.mp4");//Declaring ... Read More

How to calculate Elapsed time in OpenCV using C++?

Naveen Singh
Updated on 10-Mar-2021 08:37:50

341 Views

Here, we will understand how to calculate the elapsed time using OpenCV.The following program calculates the elapsed time in OpenCV using C++.Example#include//OpenCV header to use VideoCapture class// #include using namespace std; using namespace cv; int main() {    Mat myImage;//Declaring a matrix to load the frames//    namedWindow("Video Player");//Declaring the video to show the video//    VideoCapture cap("video.mp4");//Declaring an object to load video from device//    if (!cap.isOpened()){ //This section prompt an error message if no video stream is found//       cout myImage;       int elapsed_time;//Declaring an integer variable to store the elapsed time//   ... Read More

Advertisements