728x90
반응형

소스코드


 
#include <opencv\cv.h>
#include<opencv\highgui.h>

void main(){
	int i, threshold = 128;

	IplImage* image = 0;
	IplImage* output = 0;
	IplImage* gray = 0;

	CvCapture* capture = cvCaptureFromCAM(0);

	cvNamedWindow("original", 0);
	cvNamedWindow("Thresh_binary",0);

	cvCreateTrackbar("T", "seohee-camera", &threshold, 255, NULL);

	while (1){
		cvGrabFrame(capture);
		image = cvRetrieveFrame(capture);
		cvShowImage("original", image);
		if (!output){
			gray = cvCreateImage(cvGetSize(image), IPL_DEPTH_8U, 1);
			output = cvCreateImage(cvGetSize(image), IPL_DEPTH_8U, 1);
		}
		cvCvtColor(image, gray, CV_RGB2GRAY);

		if (cvWaitKey(10) >= 0)
			break;

		cvThreshold(gray, output, threshold, 255, CV_THRESH_BINARY); 
		output->origin = image->origin;
		cvShowImage("Thresh_binary", output);
	}

	cvReleaseImage(&output);
	cvReleaseCapture(&capture);
	cvDestroyWindow("seohee-camera");
}

결과 화면


728x90
반응형