From 842e3549ef6f4d1ea3e0acaee2f7d4bfacd55866 Mon Sep 17 00:00:00 2001 From: "jack@armsom.org" Date: Mon, 23 Sep 2024 20:50:39 +0800 Subject: [PATCH] Fix: Handle 2-digit video device index correctly --- src/main.cc | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/main.cc b/src/main.cc index 8f5bd99..469eca8 100644 --- a/src/main.cc +++ b/src/main.cc @@ -31,10 +31,13 @@ int main(int argc, char **argv) cv::namedWindow("Camera FPS"); cv::VideoCapture capture; - if (strlen(vedio_name) == 1) - capture.open((int)(vedio_name[0] - '0')); - else - capture.open(vedio_name); + if (strlen(vedio_name) == 1 || strlen(vedio_name) == 2) { + int deviceIndex = atoi(vedio_name); + capture.open(deviceIndex); + } else { + capture.open(vedio_name); + } + struct timeval time; gettimeofday(&time, nullptr);