From 13bd0f15030bc9c5ca59ff40d3760149c1fc38df Mon Sep 17 00:00:00 2001 From: Matt Hill Date: Sun, 24 Apr 2016 21:55:51 -0400 Subject: [PATCH] Combined webcam logic, minor code reorg --- src/main.cpp | 32 ++++++++------------------------ 1 file changed, 8 insertions(+), 24 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index f50c3f1..eddd020 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -40,6 +40,7 @@ const std::string MAIN_WINDOW_NAME = "ALPR main window"; const bool SAVE_LAST_VIDEO_STILL = false; const std::string LAST_VIDEO_STILL_LOCATION = "/tmp/laststill.jpg"; +const std::string WEBCAM_PREFIX = "/dev/video"; MotionDetector motiondetector; bool do_motiondetection = true; @@ -161,38 +162,21 @@ int main( int argc, const char** argv ) } } - else if (startsWith(filename, "/dev/video")) + else if (filename == "webcam" || startsWith(filename, WEBCAM_PREFIX)) { int webcamnumber = 0; - if(filename.length() > 10) + + // If they supplied "/dev/video[number]" parse the "number" here + if(startsWith(filename, WEBCAM_PREFIX) && filename.length() > WEBCAM_PREFIX.length()) { - std::string webcam_str_num; - for(int a = 11; a <= filename.length(); a=a+1) - { - webcam_str_num.append(filename,a,1); - } - int webcamnumber = atoi(webcam_str_num.c_str()); - } - else - { - std::cout << "Incorrect Webcam Address" << std::endl; - return 1; + webcamnumber = atoi(filename.substr(WEBCAM_PREFIX.length()).c_str()); } + int framenum = 0; cv::VideoCapture cap(webcamnumber); if (!cap.isOpened()) { - std::cout << "Error opening webcam" << std::endl; - return 1; - } - } - else if (filename == "webcam") - { - int framenum = 0; - cv::VideoCapture cap(0); - if (!cap.isOpened()) - { - std::cout << "Error opening webcam" << std::endl; + std::cerr << "Error opening webcam" << std::endl; return 1; }