728x90
반응형



소스코드 (OpenCV 3.0 버전)


if(frame_valid) 부분의 try 문에 처리하고자 하는 영상처리 소스를 입력하면 된다.



 
#include "opencv/cv.h"
#include "opencv/highgui.h"
#include "opencv2/opencv.hpp"
#include <iostream>

using namespace cv;
using namespace std;

int main(int argc, char *argv[]){
	VideoCapture capture(0);

	if (!capture.isOpened()){
		cerr << "Could not open camera" << endl;
		return 0;
	}

	namedWindow("testcam", 1);

	while (true){
		bool frame_valid = true;
	
		Mat frame;

		try{
			capture >> frame;
		}
		catch (Exception& e){
			cerr << "Exception occurred. Ignoring frame..." << e.err
				<< endl;
			frame_valid = false;
		}

		if (frame_valid){
			try{
				Mat edges;
				cvtColor(frame, edges, COLOR_BGR2GRAY);
				GaussianBlur(edges, edges, Size(7, 7), 1.5, 1.5);
				Canny(edges, edges, 0, 30, 3);
				imshow("testcam", edges);
			}
			catch (Exception& e){
				cerr << "Exception occurred. Ignoring frame..." << e.err
					<< endl;
			}
		}
		if (waitKey(30) >= 0) break;
		
	}
	
	// VideoCapture automatically deallocate camera object
	return 0;
}



결과화면



728x90
반응형