TheMathemagicians/a_scanner_darkly/main.cpp

40 lines
1.1 KiB
C++

#include <opencv2/opencv.hpp>
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, grayscaleFrame, cannyFrame;
while (true) {
cap >> frame;
cv::cvtColor(frame, grayscaleFrame, cv::COLOR_BGR2GRAY);
cv::Canny(grayscaleFrame, 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);
}