mirror of
https://github.com/opencv/opencv.git
synced 2025-01-18 06:03:15 +08:00
described
This commit is contained in:
parent
541f4fc99f
commit
85f301ab9f
@ -1,11 +1,24 @@
|
||||
#include "cv.h"
|
||||
#include "highgui.h"
|
||||
#include <iostream>
|
||||
|
||||
using namespace cv;
|
||||
|
||||
Mat img;
|
||||
int threshval = 100;
|
||||
|
||||
void help()
|
||||
{
|
||||
cout <<
|
||||
"Program to demonstrate connected components and use of the trackbar\n"
|
||||
<< "\n"
|
||||
<< "Usage: ./connected_components <image>\n"
|
||||
<< "\n"
|
||||
<< "The image is converted to grayscale and displayed, another image has a trackbar\n"
|
||||
<< "that controls thresholding and thereby the extracted contours which are drawn in color\n"
|
||||
<< endl;
|
||||
}
|
||||
|
||||
|
||||
void on_trackbar(int, void*)
|
||||
{
|
||||
Mat bw = threshval < 128 ? (img < threshval) : (img > threshval);
|
||||
@ -34,9 +47,13 @@ void on_trackbar(int, void*)
|
||||
|
||||
int main( int argc, char** argv )
|
||||
{
|
||||
// the first command line parameter must be file name of binary
|
||||
// (black-n-white) image
|
||||
if( !(img=imread(argc == 2 ? argv[1] : "stuff.jpg", 0)).data)
|
||||
// the first command line parameter
|
||||
if(argc != 2)
|
||||
{
|
||||
help();
|
||||
return -1;
|
||||
}
|
||||
if( !(img=imread(argc == 2 ? argv[1] : "stuff.jpg", 0)).data) //The ending 0 in imread converts the image to grayscale.
|
||||
return -1;
|
||||
|
||||
namedWindow( "Image", 1 );
|
||||
|
Loading…
Reference in New Issue
Block a user