|
@@ -20,7 +20,7 @@ void thresh_callback(int, void* );
|
|
int main( int argc, char** argv )
|
|
int main( int argc, char** argv )
|
|
{
|
|
{
|
|
/// Load source image and convert it to gray
|
|
/// Load source image and convert it to gray
|
|
- src = imread( "C:\\Users\\Sky\\Downloads\\photo.jpg", IMREAD_COLOR );
|
|
|
|
|
|
+ src = imread( "C:\\Users\\Sky\\Downloads\\1.jpg", IMREAD_COLOR );
|
|
|
|
|
|
/// Convert image to gray and blur it
|
|
/// Convert image to gray and blur it
|
|
cvtColor( src, src_gray, COLOR_BGR2GRAY );
|
|
cvtColor( src, src_gray, COLOR_BGR2GRAY );
|
|
@@ -54,7 +54,7 @@ void thresh_callback(int, void* )
|
|
Mat drawing = Mat::zeros( canny_output.size(), CV_8UC3 );
|
|
Mat drawing = Mat::zeros( canny_output.size(), CV_8UC3 );
|
|
for( int i = 0; i < contours.size(); i++ )
|
|
for( int i = 0; i < contours.size(); i++ )
|
|
{
|
|
{
|
|
- Scalar color = Scalar( rng.uniform(0, 255), rng.uniform(0,255), rng.uniform(0,255) );
|
|
|
|
|
|
+ Scalar color = Scalar( rng.uniform(255, 255), rng.uniform(255,255), rng.uniform(255,255) );
|
|
drawContours( drawing, contours, i, color, 2, 8, hierarchy, 0, Point() );
|
|
drawContours( drawing, contours, i, color, 2, 8, hierarchy, 0, Point() );
|
|
}
|
|
}
|
|
|
|
|
|
@@ -62,219 +62,3 @@ void thresh_callback(int, void* )
|
|
namedWindow( "Contours", WINDOW_AUTOSIZE );
|
|
namedWindow( "Contours", WINDOW_AUTOSIZE );
|
|
imshow( "Contours", drawing );
|
|
imshow( "Contours", drawing );
|
|
}
|
|
}
|
|
-
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-//#include "opencv2/imgproc.hpp"
|
|
|
|
-//#include "opencv2/imgcodecs.hpp"
|
|
|
|
-//#include "opencv2/highgui.hpp"
|
|
|
|
-//#include <iostream>
|
|
|
|
-//using namespace cv;
|
|
|
|
-//using std::cout;
|
|
|
|
-//int threshold_value = 0;
|
|
|
|
-//int threshold_type = 3;
|
|
|
|
-//int const max_value = 255;
|
|
|
|
-//int const max_type = 4;
|
|
|
|
-//int const max_binary_value = 255;
|
|
|
|
-//Mat src, src_gray, dst;
|
|
|
|
-//const char* window_name = "Threshold Demo";
|
|
|
|
-//const char* trackbar_type = "Type: \n 0: Binary \n 1: Binary Inverted \n 2: Truncate \n 3: To Zero \n 4: To Zero Inverted";
|
|
|
|
-//const char* trackbar_value = "Value";
|
|
|
|
-//static void Threshold_Demo( int, void* )
|
|
|
|
-//{
|
|
|
|
-// /* 0: Binary
|
|
|
|
-// 1: Binary Inverted
|
|
|
|
-// 2: Threshold Truncated
|
|
|
|
-// 3: Threshold to Zero
|
|
|
|
-// 4: Threshold to Zero Inverted
|
|
|
|
-// */
|
|
|
|
-// threshold( src_gray, dst, threshold_value, max_binary_value, threshold_type );
|
|
|
|
-// imshow( window_name, dst );
|
|
|
|
-//}
|
|
|
|
-//int main( int argc, char** argv )
|
|
|
|
-//{
|
|
|
|
-// String imageName("C:\\Users\\Sky\\Downloads\\photo.jpg"); // by default
|
|
|
|
-// if (argc > 1)
|
|
|
|
-// {
|
|
|
|
-// imageName = argv[1];
|
|
|
|
-// }
|
|
|
|
-// src = imread( samples::findFile( imageName ), IMREAD_COLOR ); // Load an image
|
|
|
|
-// if (src.empty())
|
|
|
|
-// {
|
|
|
|
-// cout << "Cannot read the image: " << imageName << std::endl;
|
|
|
|
-// return -1;
|
|
|
|
-// }
|
|
|
|
-// cvtColor( src, src_gray, COLOR_BGR2GRAY ); // Convert the image to Gray
|
|
|
|
-// namedWindow( window_name, WINDOW_AUTOSIZE ); // Create a window to display results
|
|
|
|
-// createTrackbar( trackbar_type,
|
|
|
|
-// window_name, &threshold_type,
|
|
|
|
-// max_type, Threshold_Demo ); // Create a Trackbar to choose type of Threshold
|
|
|
|
-// createTrackbar( trackbar_value,
|
|
|
|
-// window_name, &threshold_value,
|
|
|
|
-// max_value, Threshold_Demo ); // Create a Trackbar to choose Threshold value
|
|
|
|
-// Threshold_Demo( 0, 0 ); // Call the function to initialize
|
|
|
|
-// waitKey();
|
|
|
|
-// return 0;
|
|
|
|
-//}
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-//#include <iostream>
|
|
|
|
-//#include <sstream>
|
|
|
|
-//#include <opencv2/imgcodecs.hpp>
|
|
|
|
-//#include <opencv2/imgproc.hpp>
|
|
|
|
-//#include <opencv2/videoio.hpp>
|
|
|
|
-//#include <opencv2/highgui.hpp>
|
|
|
|
-//#include <opencv2/video.hpp>
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-//using namespace cv;
|
|
|
|
-//using namespace std;
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-//const char* params
|
|
|
|
-// = "{ help h | | Print usage }"
|
|
|
|
-// "{ input | C:\\Users\\Sky\\Downloads\\Umka video\\Umka video\\1_light.mp4 | Path to a video or a sequence of image }"
|
|
|
|
-// "{ algo | MOG2 | Background subtraction method (KNN, MOG2) }";
|
|
|
|
-//int main(int argc, char* argv[])
|
|
|
|
-//{
|
|
|
|
-// CommandLineParser parser(argc, argv, params);
|
|
|
|
-// parser.about( "This program shows how to use background subtraction methods provided by "
|
|
|
|
-// " OpenCV. You can process both videos and images.\n" );
|
|
|
|
-// if (parser.has("help"))
|
|
|
|
-// {
|
|
|
|
-// //print help information
|
|
|
|
-// parser.printMessage();
|
|
|
|
-// }
|
|
|
|
-// //create Background Subtractor objects
|
|
|
|
-// Ptr<BackgroundSubtractor> pBackSub;
|
|
|
|
-// if (parser.get<String>("algo") == "MOG2")
|
|
|
|
-// pBackSub = createBackgroundSubtractorMOG2();
|
|
|
|
-// else
|
|
|
|
-// pBackSub = createBackgroundSubtractorKNN();
|
|
|
|
-// VideoCapture capture( samples::findFile( parser.get<String>("input") ) );
|
|
|
|
-// if (!capture.isOpened()){
|
|
|
|
-// //error in opening the video input
|
|
|
|
-// cerr << "Unable to open: " << parser.get<String>("input") << endl;
|
|
|
|
-// return 0;
|
|
|
|
-// }
|
|
|
|
-// Mat frame, fgMask;
|
|
|
|
-// while (true) {
|
|
|
|
-// capture >> frame;
|
|
|
|
-// if (frame.empty())
|
|
|
|
-// break;
|
|
|
|
-// //update the background model
|
|
|
|
-// pBackSub->apply(frame, fgMask);
|
|
|
|
-// //get the frame number and write it on the current frame
|
|
|
|
-// rectangle(frame, cv::Point(10, 2), cv::Point(100,20),
|
|
|
|
-// cv::Scalar(255,255,255), -1);
|
|
|
|
-// stringstream ss;
|
|
|
|
-// ss << capture.get(CAP_PROP_POS_FRAMES);
|
|
|
|
-// string frameNumberString = ss.str();
|
|
|
|
-// putText(frame, frameNumberString.c_str(), cv::Point(15, 15),
|
|
|
|
-// FONT_HERSHEY_SIMPLEX, 0.5 , cv::Scalar(0,0,0));
|
|
|
|
-// //show the current frame and the fg masks
|
|
|
|
-// imshow("Frame", frame);
|
|
|
|
-// imshow("FG Mask", fgMask);
|
|
|
|
-// //get the input from the keyboard
|
|
|
|
-// int keyboard = waitKey(30);
|
|
|
|
-// if (keyboard == 'q' || keyboard == 27)
|
|
|
|
-// break;
|
|
|
|
-// }
|
|
|
|
-// return 0;
|
|
|
|
-//}
|
|
|
|
-
|
|
|