第一种:
#include "opencv2/imgproc.hpp"
#include "opencv2/imgcodecs.hpp"
#include "opencv2/highgui.hpp"
#include <iostream>
using namespace cv;
using namespace std;
int sliderPos = 70;
Mat image;
void processImage(int, void*);
int main( int argc, char** argv )
{
image = imread("C:\\Users\\Administrator\\Desktop\\20140528\\129.bmp", 0);
if( image.empty() )
{
cout << "Couldn't open image " << "\n";
return 0;
}
namedWindow("result", 1);
// Create toolbars. HighGUI use.
createTrackbar( "threshold", "result", &sliderPos, 255, processImage );
processImage(0, 0);
// Wait for a key stroke; the same function arranges events processing
waitKey();
return 0;
}
// Define trackbar callback functon. This function find contours,
// draw it and approximate it by ellipses.