OpenCV cvCreateTrackbar cvCmpS 实战

#include 
#include 

int thresh = 0;

int main(int argc,char argv[]){
	CvCapture* capture = cvCreateCameraCapture(0);
	IplImage* img = new IplImage;
	cvNamedWindow("video",CV_WINDOW_AUTOSIZE);
	cvNamedWindow("Track",CV_WINDOW_AUTOSIZE);
	cvCreateTrackbar("cmp","Track",&thresh,255,0);
	while(img!=0){
		img = cvQueryFrame(capture);
		IplImage* dst = cvCreateImage(cvGetSize(img),img->depth,1);
		cvCvtColor(img,dst,CV_BGR2GRAY);
		int _thresh = thresh;
		cvCmpS(dst,_thresh,dst,CV_CMP_GT);
		cvShowImage("video",dst);
		char c = cvWaitKey(30);
		if(c =='s'){
			cvWaitKey();
			std::cout << "保存?(Y/N)" << std::endl;
			std::cin >> c;
			if(c =='Y'){
				std::cout << "请输入名称:"<> d;
				cvSaveImage(strcat(d,".jpg"),dst);
			}
			else{
			}
		}
		if(c==27)
			break;
		cvReleaseImage(&dst);
	}
	cvReleaseCapture(&capture);
	cvDestroyWindow("video");
	return 0;
}

这段代码可以通过摄像头获取实时黑白二值图像,并具备截屏拍照功能。

复习了如何创建滚动条,以及一些简单函数的用法。

你可能感兴趣的:(OpenCV笔记,opencv,cvCmpS)