TheMathemagicians/a_scanner_darkly/main.cpp

40 lines
1.1 KiB
C++
Raw Normal View History

2024-05-14 14:48:47 +00:00
#include <opencv2/opencv.hpp>
const std::string WINDOW_NAME = "A Scanner Darkly";
2024-05-15 10:16:50 +00:00
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;
2024-05-14 14:48:47 +00:00
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);
2024-05-15 10:16:50 +00:00
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);
2024-05-14 14:48:47 +00:00
cv::Mat frame, grayscaleFrame, cannyFrame;
2024-05-14 14:48:47 +00:00
while (true) {
cap >> frame;
cv::cvtColor(frame, grayscaleFrame, cv::COLOR_BGR2GRAY);
cv::Canny(grayscaleFrame, cannyFrame, g_Canny_lower_threshold, g_Canny_upper_threshold);
2024-05-15 10:16:50 +00:00
cv::imshow(WINDOW_NAME, cannyFrame);
2024-05-14 14:48:47 +00:00
char c = (char)cv::waitKey(33);
if (c == 27) {
break;
}
}
cv::destroyWindow(WINDOW_NAME);
}