#include const std::string WINDOW_NAME = "A Scanner Darkly"; const std::string LOWER_THRESHOLD_TRACKBAR_NAME = "Canny: Lower Threshold"; const std::string UPPER_THRESHOLD_TRACKBAR_NAME = "Canny: Upper Threshold"; int g_Canny_lower_threshold = 110; int g_Canny_upper_threshold = 300; int main(int argc, char** argv ) { cv::VideoCapture cap; cap.open(0); if (!cap.isOpened()) { std::cerr << "Couldn't open capture" << std::endl; return -1; } cv::namedWindow(WINDOW_NAME); cv::createTrackbar(LOWER_THRESHOLD_TRACKBAR_NAME, WINDOW_NAME, &g_Canny_lower_threshold, 1000, NULL); cv::createTrackbar(UPPER_THRESHOLD_TRACKBAR_NAME, WINDOW_NAME, &g_Canny_upper_threshold, 1000, NULL); cv::Mat frame, cannyFrame; while (true) { cap >> frame; cv::Canny(frame, cannyFrame, g_Canny_lower_threshold, g_Canny_upper_threshold); cv::imshow(WINDOW_NAME, cannyFrame); char c = (char)cv::waitKey(33); if (c == 27) { break; } } cv::destroyWindow(WINDOW_NAME); }