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
반응형
'Development & Tools > Tools & Environments' 카테고리의 다른 글
| [OpenCV] pyrMeanShiftFiltering 적용하여 영상분할 (0) | 2017.01.17 |
|---|---|
| [OpenCV] MOG2 함수를 이용한 배경추출 (0) | 2017.01.17 |
| OpenCV contrib 설치 및 Cmake (4) | 2016.11.14 |
| OpenCV 설치 시 에러 LNK1112 (0) | 2016.11.12 |
| OpenCV 직선 그리기, 사각형 그리기, 직선 클리핑 (0) | 2016.08.13 |