Merge pull request #22135 from rogday:force_reopen

pull/22298/head
Alexander Smorkalov 2 years ago
commit 47a59d72c9
  1. 1
      apps/interactive-calibration/calibCommon.hpp
  2. 31
      apps/interactive-calibration/calibPipeline.cpp
  3. 1
      apps/interactive-calibration/main.cpp
  4. 1
      apps/interactive-calibration/parametersController.cpp

@ -95,6 +95,7 @@ namespace calib
int minFramesNum;
bool saveFrames;
float zoom;
bool forceReopen;
captureParameters()
{

@ -6,6 +6,7 @@
#include <opencv2/highgui.hpp>
#include <opencv2/imgproc.hpp>
#include <opencv2/core/utils/logger.hpp>
#include <stdexcept>
@ -30,7 +31,8 @@ CalibPipeline::CalibPipeline(captureParameters params) :
PipelineExitStatus CalibPipeline::start(std::vector<cv::Ptr<FrameProcessor> > processors)
{
if(mCaptureParams.source == Camera && !mCapture.isOpened())
auto open_camera = [this] () {
if(mCaptureParams.source == Camera)
{
mCapture.open(mCaptureParams.camID);
cv::Size maxRes = getCameraResolution();
@ -52,15 +54,38 @@ PipelineExitStatus CalibPipeline::start(std::vector<cv::Ptr<FrameProcessor> > pr
}
mCapture.set(cv::CAP_PROP_AUTOFOCUS, 0);
}
else if (mCaptureParams.source == File && !mCapture.isOpened())
else if (mCaptureParams.source == File)
mCapture.open(mCaptureParams.videoFileName);
};
if(!mCapture.isOpened()) {
open_camera();
}
mImageSize = cv::Size((int)mCapture.get(cv::CAP_PROP_FRAME_WIDTH), (int)mCapture.get(cv::CAP_PROP_FRAME_HEIGHT));
if(!mCapture.isOpened())
throw std::runtime_error("Unable to open video source");
cv::Mat frame, processedFrame, resizedFrame;
while(mCapture.grab()) {
while (true) {
if (!mCapture.grab())
{
if (!mCaptureParams.forceReopen)
{
CV_LOG_ERROR(NULL, "VideoCapture error: could not grab the frame.");
break;
}
CV_LOG_INFO(NULL, "VideoCapture error: trying to reopen...");
do
{
open_camera();
} while (!mCapture.isOpened() || !mCapture.grab());
CV_LOG_INFO(NULL, "VideoCapture error: reopened successfully.");
auto newSize = cv::Size((int)mCapture.get(cv::CAP_PROP_FRAME_WIDTH), (int)mCapture.get(cv::CAP_PROP_FRAME_HEIGHT));
CV_CheckEQ(mImageSize, newSize, "Camera image size changed after reopening.");
}
mCapture.retrieve(frame);
if(mCaptureParams.flipVertical)
cv::flip(frame, frame, -1);

@ -42,6 +42,7 @@ const std::string keys =
"{pf | defaultConfig.xml| Advanced application parameters}"
"{save_frames | false | Save frames that contribute to final calibration}"
"{zoom | 1 | Zoom factor applied to the image}"
"{force_reopen | false | Forcefully reopen camera in case of errors}"
"{help | | Print help}";
bool calib::showOverlayMessage(const std::string& message)

@ -91,6 +91,7 @@ bool calib::parametersController::loadFromParser(cv::CommandLineParser &parser)
mCapParams.templDst = parser.get<float>("dst");
mCapParams.saveFrames = parser.get<bool>("save_frames");
mCapParams.zoom = parser.get<float>("zoom");
mCapParams.forceReopen = parser.get<bool>("force_reopen");
if(!checkAssertion(mCapParams.squareSize > 0, "Distance between corners or circles must be positive"))
return false;

Loading…
Cancel
Save