Merge pull request #27546 from asmorkalov:as/interactive_calib_backend

Added command line option to select VideoCapture backend
This commit is contained in:
Alexander Smorkalov 2025-07-16 12:02:49 +03:00 committed by GitHub
commit 4813d1cd32
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 47 additions and 7 deletions

View File

@ -92,6 +92,7 @@ namespace calib
std::string videoFileName;
bool flipVertical;
int camID;
int camBackend;
int fps;
cv::Size cameraResolution;
int maxFramesNum;

View File

@ -34,7 +34,7 @@ PipelineExitStatus CalibPipeline::start(std::vector<cv::Ptr<FrameProcessor> > pr
auto open_camera = [this] () {
if(mCaptureParams.source == Camera)
{
mCapture.open(mCaptureParams.camID);
mCapture.open(mCaptureParams.camID, mCaptureParams.camBackend);
cv::Size maxRes = getCameraResolution();
cv::Size neededRes = mCaptureParams.cameraResolution;
@ -55,7 +55,7 @@ PipelineExitStatus CalibPipeline::start(std::vector<cv::Ptr<FrameProcessor> > pr
mCapture.set(cv::CAP_PROP_AUTOFOCUS, 0);
}
else if (mCaptureParams.source == File)
mCapture.open(mCaptureParams.videoFileName);
mCapture.open(mCaptureParams.videoFileName, mCaptureParams.camBackend);
};
if(!mCapture.isOpened()) {

View File

@ -6,7 +6,7 @@
#include <opencv2/calib3d.hpp>
#include <opencv2/cvconfig.h>
#include <opencv2/highgui.hpp>
#include <opencv2/videoio/registry.hpp>
#include <string>
#include <vector>
@ -23,9 +23,25 @@
using namespace calib;
const std::string keys =
static std::string getVideoIoBackendsString()
{
std::string result;
auto backs = cv::videoio_registry::getBackends();
for (const auto& b: backs)
{
if (!result.empty())
result += ", ";
result += cv::videoio_registry::getBackendName(b);
}
return result;
}
const char* keys =
"{v | | Input from video file }"
"{ci | 0 | Default camera id }"
"{ci | 0 | Camera id }"
"{vb | | Video I/O back-end. One of: %s }"
"{flip | false | Vertical flip of input frames }"
"{t | circles | Template for calibration (circles, chessboard, dualCircles, charuco, symcircles) }"
"{sz | 16.3 | Distance between two nearest centers of circles or squares on calibration board}"
@ -95,11 +111,13 @@ static void undistortButton(int state, void* data)
int main(int argc, char** argv)
{
cv::CommandLineParser parser(argc, argv, keys);
cv::CommandLineParser parser(argc, argv, cv::format(keys, getVideoIoBackendsString().c_str()));
if(parser.has("help")) {
parser.printMessage();
return 0;
}
std::cout << consoleHelp << std::endl;
parametersController paramsController;

View File

@ -4,7 +4,7 @@
#include "parametersController.hpp"
#include <opencv2/objdetect/aruco_dictionary.hpp>
#include <opencv2/videoio/registry.hpp>
#include <iostream>
template <typename T>
@ -106,6 +106,27 @@ bool calib::parametersController::loadFromParser(cv::CommandLineParser &parser)
mCapParams.camID = parser.get<int>("ci");
}
mCapParams.camBackend = cv::CAP_ANY;
if (parser.has("vb"))
{
std::string backendName = parser.get<std::string>("vb");
auto backs = cv::videoio_registry::getBackends();
bool backendSet = false;
for (const auto& b: backs)
{
if (backendName == cv::videoio_registry::getBackendName(b))
{
mCapParams.camBackend = b;
backendSet = true;
}
}
if (!backendSet)
{
std::cout << "Unknown or unsupported backend " << backendName << std::endl;
return false;
}
}
std::string templateType = parser.get<std::string>("t");
if(templateType.find("symcircles", 0) == 0) {