described

This commit is contained in:
Gary Bradski 2010-11-24 05:51:04 +00:00
parent 541f4fc99f
commit 85f301ab9f

View File

@ -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 );