วันพฤหัสบดีที่ 23 มีนาคม พ.ศ. 2560

C++ opencv Canny Edge

#include "opencv2/imgproc/imgproc.hpp"
#include "opencv2/highgui/highgui.hpp"
#include <stdlib.h>
#include <stdio.h>

using namespace cv;

/// Global variables

Mat frame, src_gray;
Mat dst, detected_edges;

int ratio = 3;
int kernel_size = 3;
char* window_name = "Edge Map";

void CannyThreshold(int, void*)
{

imshow(window_name, dst);
}

/** @function main */
int main(int argc, char** argv)
{
VideoCapture cap(0);
while (1)
{
cap >> frame;
namedWindow("Original", CV_WINDOW_AUTOSIZE);
imshow("Original", frame);
dst = frame.clone();


/// Convert the image to grayscale
cvtColor(frame, src_gray, CV_BGR2GRAY);
/// Reduce noise with a kernel 3x3
blur(src_gray, detected_edges, Size(3, 3));

/// Canny detector
Canny(detected_edges, detected_edges, 15, 10, kernel_size);

/// Using Canny's output as a mask, we display our result
dst = Scalar::all(0);

frame.copyTo(dst, detected_edges);

namedWindow("Canny Edge Map", CV_WINDOW_AUTOSIZE);
imshow("Canny Edge Map", dst);

if (waitKey(30) == 27)
break;
}
return 0;
}

ไม่มีความคิดเห็น:

แสดงความคิดเห็น