This OpenCV tutorial is a very simple code example of GPU Cuda optical flow in OpenCV written in c++. The configuration of the project, code, and explanation are included for farneback Optical Flow method. Farneback algorithm is a dense method that is used to process all the pixels in the given image. The dense methods are slower but more accurate as all the pixels of the image are processed. In the following example, I am displaying just a few pixes based on a grid. I am not displaying all the pixes. In the opposite to dense method the sparse method like Lucas Kanade using just a selected subset of pixels. They are faster. Both methods have specific applications. Lucas-Kanade is widely used in tracking. The farneback can be used for the analysis of more complex movement in image scene and furder segmentation based on these changes. As dense methods are slightly slower, the GPU and Cuda implementation can lead to great performance improvements to calculate optical flow for all pixels o
Sliding Window, search objects single scale
Opencv C++ tutorial about the object detection with sliding window. Sliding window is easy to implement in single scale and also not to much harder to implement in multi scale for example detection inside the bigger mat. I would like to visualize all the step during the code and described by natural c++ way. As a // comments. Enjoy the coding..
Second tutorial mat roi Roi
Opencv instalation for the tutorial
You can simple prepare the project inside the Visual Studio 2015 by Nuget Packages. This approach is easy for beginers and better than standard installation with all the environmental variables problems. Just follow the installation steps inside here
I am using Visual Studio 2015, How to use Opencv 3.0.0 with Visual Studio can be found here install opencv visual studio 2015.
Sliding window for detection opencv code
#include <Windows.h>
#include "opencv2\highgui.hpp"
#include "opencv2\imgproc.hpp"
#include "opencv2/video/background_segm.hpp"
#include "opencv2/video/tracking.hpp"
using namespace cv;
using namespace std;
int main(int argc, const char** argv)
{
//
// Load the image from file
//
Mat LoadedImage;
// Just loaded image Lenna.png from project dir to LoadedImage Mat
LoadedImage = imread("Lenna.png", IMREAD_COLOR);
//I would like to visualize Mat step by step to see the result immediately.
// Show what is in the Mat after load
namedWindow("Step 1 image loaded", WINDOW_AUTOSIZE);
imshow("Step 1 image loaded", LoadedImage);
waitKey(1000);
// Same the result from LoadedImage to Step1.JPG
imwrite("Step1.JPG", LoadedImage);
// Parameters of your slideing window
int windows_n_rows = 60;
int windows_n_cols = 60;
// Step of each window
int StepSlide = 30;
// Just copy of Loaded image
// Note that Mat img = LoadedImage; This syntax only put reference on LoadedImage
// Whot does it mean ? if you change img, LoadeImage is changed 2.
// IF you want to make a copy, and do not change the source image- Use clone();
Mat DrawResultGrid= LoadedImage.clone();
// Cycle row step
for (int row = 0; row <= LoadedImage.rows - windows_n_rows; row += StepSlide)
{
// Cycle col step
for (int col = 0; col <= LoadedImage.cols - windows_n_cols; col += StepSlide)
{
// There could be feature evaluator over Windows
// resulting window
Rect windows(col, row, windows_n_rows, windows_n_cols);
Mat DrawResultHere = LoadedImage.clone();
// Draw only rectangle
rectangle(DrawResultHere, windows, Scalar(255), 1, 8, 0);
// Draw grid
rectangle(DrawResultGrid, windows, Scalar(255), 1, 8, 0);
// Show rectangle
namedWindow("Step 2 draw Rectangle", WINDOW_AUTOSIZE);
imshow("Step 2 draw Rectangle", DrawResultHere);
waitKey(100);
imwrite("Step2.JPG", DrawResultHere);
// Show grid
namedWindow("Step 3 Show Grid", WINDOW_AUTOSIZE);
imshow("Step 3 Show Grid", DrawResultGrid);
waitKey(100);
imwrite("Step3.JPG", DrawResultGrid);
// Select windows roi
Mat Roi = LoadedImage(windows);
//Show ROI
namedWindow("Step 4 Draw selected Roi", WINDOW_AUTOSIZE);
imshow("Step 4 Draw selected Roi", Roi);
waitKey(100);
imwrite("Step4.JPG", Roi);
}
}
}
windows_n_rows why 60 ?
ReplyDeletenice tutorial!
ReplyDeletehmmmmmm
ReplyDeleteThanks for posting the useful information to my vision. This is excellent information,.
ReplyDeleteupvc sliding doors manufacturers hyderabad
upvc doors suppliers in hyderabad
Thanks for sharing this in here. You are running a great blog, keep up this good work.
ReplyDeleteMachine Learning institute in Chennai | best machine learning with python course in chennai | best training institute for machine learning
I enjoyed reading your article :) PLease continue publishing helpful topics like this. Regards, from https://www.pellamontreal.com
ReplyDeleteI think this article will fully complement your article.
Hey, very nice site. I came across this on Google, and I am stoked that I did. I will definitely be coming back here more often. Wish I could add to the conversation and bring a bit more to the table, but am just taking in as much info as I can at the moment. Thanks .
ReplyDeleteDedicatedHosting4u.com
I am overwhelmed by your post with such a nice topic. Usually, I visit your blogs and get updated with the information you include but today’s blog would be the most appreciable...
ReplyDeleteThanks
Cpa offers
ReplyDeleteThis is a fantastic idea! I like it a lot because it's super easy for the audience to see the value of opting in. wonderful and amazing post very use full your post thanks for sharing your article
Android Application development
Web application
ReplyDeleteYour post is very good. I got to learn a lot from your post. Thank you for sharing your article for us. it is amazing post
what is seo
types of seo