Add sliders to adjust Canny thresholds

This commit is contained in:
The Magician 2024-05-15 11:16:50 +01:00
parent beed5fd92d
commit 5f5eae7443
1 changed files with 11 additions and 2 deletions

View File

@ -1,6 +1,11 @@
#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;
@ -12,12 +17,16 @@ int main(int argc, char** argv ) {
}
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;
cv::Mat frame, cannyFrame;
while (true) {
cap >> frame;
cv::imshow(WINDOW_NAME, 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) {